From 40c4b464dcdaeded34fefa4d48ce7f128792485d Mon Sep 17 00:00:00 2001 From: Guilian Date: Sat, 25 Jan 2025 17:05:40 +0100 Subject: [PATCH] refactor: simplify 'skipping' mechanism --- html.lua | 69 ++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 59 deletions(-) diff --git a/html.lua b/html.lua index fcc5696..b9e185b 100644 --- a/html.lua +++ b/html.lua @@ -207,71 +207,22 @@ function M.tokenise( content ) local currently_opened_quotes = nil local text_memory = "" - local skipping_from = nil - local skip_target = nil - local skip_mode = "before" - - local function set_skipping_to( str, mode ) - mode = mode or "before" - if mode ~= "before" and mode ~= "after" then - error("Unexpected skipping mode: " .. mode .. ", in looking for " .. str) - end - - skip_target = str - skip_mode = mode - end - - - local i = 1 while i <= #content do local char = content:sub(i,i) - if skip_target ~= nil then - if skipping_from == nil then - skipping_from = i - end - - if skip_mode == "before" then - local end_i = i + #skip_target - 1 - - if trim(content:sub(i, end_i)) == skip_target then - table.insert( TOKENS, {type="TEXT", value=content:sub(skipping_from, i-1)} ) - - -- release from skip - --i = end_i - 1 - i = i - 1 - skip_target = nil - skipping_from = nil - end - - goto continue - else - local start_i = i - #skip_target + 1 - - if trim(content:sub(start_i, i)) == skip_target then - table.insert( TOKENS, {type="TEXT", value=content:sub(skipping_from, start_i-1)} ) - - -- release from skip - i = start_i - skip_target = nil - skipping_from = nil - end - - goto continue - end - - - - end - - if char == "<" then if content:sub(i, i+3) == "", "after") + local end_i = content:find("-->", i+3, true) + if end_i then + i = end_i + 2 + else + i = #content + end + goto continue end @@ -308,7 +259,7 @@ function M.tokenise( content ) if RAW_TEXT_TAGS[word] then logger.printerr("Warning: "..word.." tags may contain text that would be incorrectly parsed as HTML.") -- made possible because of the whitespace removal at the start - set_skipping_to("" i = content:find(">", i) + -- made possible because of the whitespace removal at the start + i = content:find("