diff --git a/luax.lua b/luax.lua index 3994d3e..edfbedd 100644 --- a/luax.lua +++ b/luax.lua @@ -24,26 +24,27 @@ local function decentParserAST(input) local tagName = tagRange:match("<(%w+)", 0) local tagNameEnd = tagRange:match("(%w+)>", 0) if tagName then deepNode = deepNode + 1 end - if tagNameEnd then deepNode = deepNode - 1 end pos = pos + 1 if tagName and not deepString then isTag = true textNode = false + if textNodeStart then + textNodeStart = not textNodeStart + output = output .. "]]" + end if deepNode > 1 then output = output .. ", " .. tagName .. "({" else output = output .. tagName .. "({" end - local step = 1 - -- enclose attributes if it empty - if tagRange:sub(#tagRange - 1, #tagRange):gsub("[\r\n]", ""):match("^%s*(.-)$") == ">" then step = 0 end - pos = pos + #tagName + step + pos = pos + #tagName elseif tagNameEnd then + deepNode = deepNode - 1 if isTag and not textNode then isTag = not isTag local trail = input:sub(0, pos - 2):gsub("[%s\r\n]", "") - if trail:sub(#trail - 1, #trail - 1) == '/' then + if trail:sub(#trail - 1, #trail - 1) == "/" then output = output .. ")" else output = output .. "})" @@ -104,7 +105,7 @@ local function decentParserAST(input) end if textNode and not textNodeStart then - local subNode = input:match("%s*<(%w+)", pos) + local subNode = input:match("^%s*<(%w+)", pos) or input:match("^%s*{(%w+)", pos) if not isTag and not subNode and not var then textNodeStart = not textNodeStart output = output .. ", [[" diff --git a/test/14_page.luax b/test/14_page.luax new file mode 100644 index 0000000..91eeb4e --- /dev/null +++ b/test/14_page.luax @@ -0,0 +1,61 @@ +local module = {} +local toggleMain = "toggleMain" +local todoList = "todoList" +local todoFooter = "todoFooter" + +function module.Page(todos) + return +
+ +Created by syarul
\ No newline at end of file diff --git a/test/test_ast.lua b/test/test_ast.lua index 2cab3f9..89fac52 100644 --- a/test/test_ast.lua +++ b/test/test_ast.lua @@ -68,4 +68,16 @@ local varin = require('test.13_varin') h(varin) +local page = require('test.14_page') + +print(h(page.Page("todos"))) + +local title = require('test.15_title') + +print(h(title)) + +local p = require('test.16_p') + +print(h(p)) + diff --git a/test/test_spec.lua b/test/test_spec.lua index 935d423..7e476ab 100644 --- a/test/test_spec.lua +++ b/test/test_spec.lua @@ -99,7 +99,7 @@ describe("LuaX", function() it("should return a HTML string with deep node tree", function() local el = require("test.12_test") assert.is.equal( - 'Hello, world!