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

Commit

Permalink
update: additional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasRanarison committed Sep 15, 2023
1 parent ac7c56f commit 8f44b86
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions lua/nvim-devdocs/transpiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down Expand Up @@ -82,17 +63,38 @@ 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",
"thead",
"tbody",
}

local is_skipable_tag = function(tag_name) return vim.tbl_contains(skipable_tags, tag_name) end

----------------------------------------------------------------

local transpiler = {}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8f44b86

Please sign in to comment.