From 6b3225c88db31b5ad593a4376c7b810a01006782 Mon Sep 17 00:00:00 2001 From: Luckas Date: Thu, 14 Sep 2023 21:41:14 +0300 Subject: [PATCH] fix(transpiler): img & table col length Add a linebreak after img tags & fix non-even column length --- lua/nvim-devdocs/transpiler.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/nvim-devdocs/transpiler.lua b/lua/nvim-devdocs/transpiler.lua index 9891d6d..4d614de 100644 --- a/lua/nvim-devdocs/transpiler.lua +++ b/lua/nvim-devdocs/transpiler.lua @@ -212,9 +212,9 @@ function transpiler:eval(node) if tag_name == "a" then result = string.format("[%s](%s)", result, attributes.href) elseif tag_name == "img" and string.match(attributes.src, "^data:") then - result = string.format("![%s](%s)", attributes.alt, "data:inline_image") + result = string.format("![%s](%s)\n", attributes.alt, "data:inline_image") elseif tag_name == "img" then - result = string.format("![%s](%s)", attributes.alt, attributes.src) + result = string.format("![%s](%s)\n", attributes.alt, attributes.src) elseif tag_name == "pre" and attributes["data-language"] then result = "\n```" .. attributes["data-language"] .. "\n" .. result .. "\n```\n" elseif tag_name == "abbr" then @@ -325,7 +325,7 @@ function transpiler:eval_table(node) inner_result = inner_result .. self:eval(tcol_child) end - result_map[i][j] = inner_result + result_map[i][j] = inner_result:gsub("\n", "") colspan_map[i][j] = attributes.colspan and attributes.colspan or 1 if max_col_len_map[j] == nil then max_col_len_map[j] = 0 end @@ -342,7 +342,7 @@ function transpiler:eval_table(node) if not col_len then break end - result = result .. "| " .. string.gsub(value, "\n", "") .. string.gsub(string.rep(" ", col_len - #value + 1), "\n", "") + result = result .. "| " .. value .. string.rep(" ", col_len - #value + 1) current_col = current_col + 1 if colspan > 1 then