From a94abd88606be45f6b932d650cc2281ee7a365ee Mon Sep 17 00:00:00 2001 From: Shawon Date: Wed, 6 Nov 2024 10:40:24 +0600 Subject: [PATCH] fix: Fixed escaling of characters This fixes width calculation issues of escaped characters inside of $$. Ref: #177 --- lua/markview/renderers/markdown.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lua/markview/renderers/markdown.lua b/lua/markview/renderers/markdown.lua index 352bb5d..c7e0a64 100644 --- a/lua/markview/renderers/markdown.lua +++ b/lua/markview/renderers/markdown.lua @@ -86,6 +86,17 @@ markdown.output = function (str) local esc = config("escapes"); local ent = config("entities"); + for escaped in str:gmatch("\\(%$)") do + if not esc then + break; + end + + str = str:gsub(concat({ + "\\", + escaped + }), " "); + end + for latex in str:gmatch("%$([^%$]*)%$") do ---+${custom, Handle LaTeX blocks} str = str:gsub(concat({ @@ -108,9 +119,7 @@ markdown.output = function (str) str = str:gsub(concat({ "\\", escaped - }), concat({ - escaped - })); + }), " "); end for inline_code in str:gmatch("`(.-)`") do