refactor: pseudo-elements use : instead of # prefix
parent
8937c1d496
commit
fc026a30f5
16
html.lua
16
html.lua
|
@ -298,7 +298,7 @@ function M.parse_tokens_into_document( TOKENS )
|
||||||
local token = TOKENS[i]
|
local token = TOKENS[i]
|
||||||
|
|
||||||
if token.type == "WORD" then
|
if token.type == "WORD" then
|
||||||
if current_doc_element.tag_name == "#text" then
|
if current_doc_element.tag_name == ":text" then
|
||||||
current_doc_element = current_doc_element.parent
|
current_doc_element = current_doc_element.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ function M.parse_tokens_into_document( TOKENS )
|
||||||
|
|
||||||
|
|
||||||
if token.type == "TEXT" then
|
if token.type == "TEXT" then
|
||||||
local new_elem = M.make_dom_element( "#text", current_doc_element )
|
local new_elem = M.make_dom_element( ":text", current_doc_element )
|
||||||
new_elem.content = token.value
|
new_elem.content = token.value
|
||||||
current_doc_element = new_elem
|
current_doc_element = new_elem
|
||||||
|
|
||||||
|
@ -411,7 +411,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function M.clean_text_nodes(node)
|
function M.clean_text_nodes(node)
|
||||||
if node.tag_name ~= "#text" then
|
if node.tag_name ~= ":text" then
|
||||||
-- Don't clean anything in raw text tags
|
-- Don't clean anything in raw text tags
|
||||||
if RAW_TEXT_TAGS[node.tag_name] then
|
if RAW_TEXT_TAGS[node.tag_name] then
|
||||||
return
|
return
|
||||||
|
@ -451,15 +451,15 @@ function M.print_document(node, indent)
|
||||||
-- Create the indentation string (e.g., " " for each level)
|
-- Create the indentation string (e.g., " " for each level)
|
||||||
local indent_str = string.rep(indent_level_str, indent)
|
local indent_str = string.rep(indent_level_str, indent)
|
||||||
|
|
||||||
if node.tag_name == "#text" then
|
if node.tag_name == ":text" then
|
||||||
print(indent_str .. "<#text>\n" .. node.content .. "\n" .. indent_str .. "</#text>")
|
print(indent_str .. "<:text>\n" .. node.content .. "\n" .. indent_str .. "</:text>")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local node_name = ""
|
local node_name = ""
|
||||||
|
|
||||||
-- Print the current node's tag name
|
-- Print the current node's tag name
|
||||||
node_name = node_name .. indent_str .. "<" .. (node.tag_name or "#root")
|
node_name = node_name .. indent_str .. "<" .. (node.tag_name or ":root")
|
||||||
|
|
||||||
-- Print attributes if any
|
-- Print attributes if any
|
||||||
if next(node.attributes) ~= nil then
|
if next(node.attributes) ~= nil then
|
||||||
|
@ -480,10 +480,12 @@ function M.print_document(node, indent)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Print the closing tag
|
-- Print the closing tag
|
||||||
print(indent_str .. "</" .. (node.tag_name or "#root") .. ">")
|
print(indent_str .. "</" .. (node.tag_name or ":root") .. ">")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function M.parse( html_string )
|
function M.parse( html_string )
|
||||||
local clean_html = M.preprocess( html_string )
|
local clean_html = M.preprocess( html_string )
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue