Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit 2f4cdae

Browse files
fix(transpiler): tag node & table
check if tag node exists and handle <table> without thead and tbody
1 parent afb4d19 commit 2f4cdae

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lua/nvim-devdocs/transpiler.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ M.html_to_md = function(html)
144144

145145
if child then
146146
local tag_node = child:named_child()
147-
tag_name = self:get_node_text(tag_node)
147+
if tag_node then tag_name = self:get_node_text(tag_node) end
148148
end
149149

150150
return tag_name
@@ -291,10 +291,15 @@ M.html_to_md = function(html)
291291
local children = self:filter_tag_children(node)
292292
---@type TSNode[]
293293
local tr_nodes = {}
294-
295-
-- extracts tr from thead, tbody
296-
for _, child in ipairs(children) do
297-
vim.list_extend(tr_nodes, self:filter_tag_children(child))
294+
local first_child_tag = self:get_node_tag_name(children[1])
295+
296+
if first_child_tag == "tr" then
297+
vim.list_extend(tr_nodes, children)
298+
else
299+
-- extracts tr from thead, tbody
300+
for _, child in ipairs(children) do
301+
vim.list_extend(tr_nodes, self:filter_tag_children(child))
302+
end
298303
end
299304

300305
local max_col_len_map = {}

0 commit comments

Comments
 (0)