diff --git a/babelvueextractor/lexer.py b/babelvueextractor/lexer.py index a25634c..b34ed7b 100644 --- a/babelvueextractor/lexer.py +++ b/babelvueextractor/lexer.py @@ -37,7 +37,7 @@ V_DIRECTIVE_PREFIX = 'v-' COLON_DIRECTIVE_PREFIX = '\x3a' # 0x3a = ":" -tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|(?:%s|%s).+?=".*?")' % ( +tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|%s.*?%s|(?:%s|%s).+?=(?:".*?"|\'.*?\'))' % ( re.escape(CONST_START), re.escape(CONST_END), re.escape(RAW_HTML_TAG_START), re.escape(RAW_HTML_TAG_END), re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), @@ -131,10 +131,10 @@ def create_token(self, token_string, in_tag): _end = len(VARIABLE_TAG_END) token_type = TOKEN_VAR - elif token_string.endswith('"'): + elif token_string.endswith(('"', "'")): token_type = TOKEN_DIRECTIVE # eg. v-text="attr" => ['v-text=', 'attr', ''] - content = token_string.split('"')[1] + content = token_string.split(token_string[-1])[1] if _start is not None: content = token_string[_start:-_end].strip() diff --git a/babelvueextractor/tests/test_lexer.py b/babelvueextractor/tests/test_lexer.py index 7967d0e..455a622 100644 --- a/babelvueextractor/tests/test_lexer.py +++ b/babelvueextractor/tests/test_lexer.py @@ -1,6 +1,6 @@ import unittest from babelvueextractor.lexer import Lexer, Token, TOKEN_TEXT, TOKEN_VAR, TOKEN_COMMENT, TOKEN_RAW_HTML, TOKEN_CONST, \ - TOKEN_DOUBLE_WAY_BINDING + TOKEN_DOUBLE_WAY_BINDING, TOKEN_DIRECTIVE class TestLexer(unittest.TestCase): @@ -52,6 +52,34 @@ def test_double_way_binding(self): Token(TOKEN_DOUBLE_WAY_BINDING, "foo") ]) + def test_v_attr(self): + content = "