Skip to content

Commit 5bd30cb

Browse files
authored
Merge pull request #482 from ImmanuelHaffner/fix/tostring-balanced-parens
fix(tostring): support balanced parentheses in URL link destinations
2 parents 9c17d2b + 0114472 commit 5bd30cb

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lua/markview/renderers/markdown/tostring.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,12 @@ local code = lpeg.C( at_valid * lpeg.P("`")^1 * code_content^1 * lpeg.P("`")^1 )
631631

632632
local hyperlink_content = lpeg.P("\\]") + ( 1 - lpeg.P("]") );
633633
local hyperlink_no_src = lpeg.C( lpeg.P("[") * hyperlink_content^0 * lpeg.P("]") ) / md_str.hyperlink_no_src;
634-
local src_content = lpeg.P("\\)") + ( 1 - lpeg.S(") \t") );
634+
-- Supports balanced parentheses in URLs per CommonMark spec §6.7:
635+
-- https://spec.commonmark.org/0.31.2/#link-destination
636+
local src_content = lpeg.P{
637+
"src";
638+
src = lpeg.P("\\)") + (lpeg.P("(") * lpeg.V("src")^0 * lpeg.P(")")) + ( 1 - lpeg.S(") \t") );
639+
};
635640
local hyperlink_src = lpeg.C( lpeg.P("[") * hyperlink_content^0 * lpeg.P("](") * src_content^0 * lpeg.P(")") ) / md_str.hyperlink_src;
636641
local hyperlink = hyperlink_src + hyperlink_no_src;
637642

0 commit comments

Comments
 (0)