From 8f44b8696c121a2f8bacac52cb11061e1c0e9a18 Mon Sep 17 00:00:00 2001 From: Luckas Date: Fri, 15 Sep 2023 07:09:58 +0300 Subject: [PATCH] update: additional changes --- lua/nvim-devdocs/transpiler.lua | 52 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/lua/nvim-devdocs/transpiler.lua b/lua/nvim-devdocs/transpiler.lua index 4913dad..20425aa 100644 --- a/lua/nvim-devdocs/transpiler.lua +++ b/lua/nvim-devdocs/transpiler.lua @@ -13,25 +13,6 @@ local normalize_html = function(str) return str end -local inline_tags = { - "span", - "a", - "strong", - "em", - "abbr", - "code", - "i", - "s", - "sub", - "sup", - "mark", - "small", - "var", - "kbd", -} - -local is_inline_tag = function(tag_name) return vim.tbl_contains(inline_tags, tag_name) end - local tag_mappings = { h1 = { left = "# ", right = "\n\n" }, h2 = { left = "## ", right = "\n\n" }, @@ -82,10 +63,29 @@ local tag_mappings = { hr = { right = "---\n\n" }, } -local skipable_tag = { +local inline_tags = { + "span", + "a", + "strong", + "em", + "abbr", + "code", + "i", + "s", + "sub", + "sup", + "mark", + "small", + "var", + "kbd", +} + +local is_inline_tag = function(tag_name) return vim.tbl_contains(inline_tags, tag_name) end + +local skipable_tags = { "input", - -- exceptions, table -> child + -- exceptions, (parent) table -> child "tr", "td", "th", @@ -93,6 +93,8 @@ local skipable_tag = { "tbody", } +local is_skipable_tag = function(tag_name) return vim.tbl_contains(skipable_tags, tag_name) end + ---------------------------------------------------------------- local transpiler = {} @@ -162,7 +164,7 @@ function transpiler:get_node_attributes(node) local attributes = {} local tag_node = node:named_child() - if tag_node == nil then return {} end + if not tag_node then return {} end local tag_children = tag_node:named_children() @@ -235,7 +237,7 @@ function transpiler:eval(node) end end - if vim.tbl_contains(skipable_tag, tag_name) then return "" end + if is_skipable_tag(tag_name) then return "" end if tag_name == "a" then result = string.format("[%s](%s)", result, attributes.href) @@ -356,9 +358,9 @@ function transpiler:eval_table(node) inner_result = inner_result:gsub("\n", "") result_map[i][j] = inner_result - colspan_map[i][j] = attributes.colspan and attributes.colspan or 1 + colspan_map[i][j] = attributes.colspan or 1 - if max_col_len_map[j] == nil then max_col_len_map[j] = 1 end + if not max_col_len_map[j] then max_col_len_map[j] = 1 end if max_col_len_map[j] < #inner_result then max_col_len_map[j] = #inner_result end end end