Skip to content

Commit 7c6cd4e

Browse files
authored
fix(shortcodes): use semicolon delimiter to avoid smart typography issue (#13915)
* test(smoke): add regression test for shortcode with trailing dash (#13913) * Add .gitignore from running tests * fix(shortcodes): use semicolon delimiter to avoid smart typography issue (#13913) Shortcodes followed by a trailing dash were being hex-encoded in output because Pandoc's +smart extension converts -- to en-dash, breaking the UUID pattern match during decode. Changed the delimiter from - to ; in the UUID-HEX encoding format to prevent this collision with smart typography. * test(smoke): add semicolon edge case to shortcode test (#13913)
2 parents 6112370 + d541684 commit 7c6cd4e

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/resources/pandoc/datadir/lpegshortcode.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,13 @@ local function string_to_hex(str)
321321
end
322322

323323
local md_shortcode_2_uuid = "b58fc729-690b-4000-b19f-365a4093b2ff"
324-
local md_shortcode_2_uuid_pattern = "b58fc729%-690b%-4000%-b19f%-365a4093b2ff%-"
324+
local md_shortcode_2_uuid_pattern = "b58fc729%-690b%-4000%-b19f%-365a4093b2ff;"
325325
local function md_escaped_shortcode_2_fun(s)
326326
return table.concat({
327327
md_shortcode_2_uuid,
328-
"-",
328+
";",
329329
string_to_hex("{{{<" .. s .. ">}}}"),
330-
"-"
330+
";"
331331
})
332332
end
333333

@@ -340,9 +340,9 @@ local function md_shortcode_2_fun(open, space, lst, close)
340340
raw = raw .. close
341341
return table.concat({
342342
md_shortcode_2_uuid,
343-
"-",
343+
";",
344344
string_to_hex(raw),
345-
"-"
345+
";"
346346
});
347347
end
348348

src/resources/pandoc/datadir/readqmd.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ local function hex_to_string(hex)
121121
end
122122

123123
local function readqmd(txt, opts)
124-
local uuid_pattern = "b58fc729%-690b%-4000%-b19f%-365a4093b2ff%-([A-Fa-f0-9]+)%-"
124+
local uuid_pattern = "b58fc729%-690b%-4000%-b19f%-365a4093b2ff;([A-Fa-f0-9]+);"
125125
local tags
126126
txt = md_fenced_div.attempt_to_fix_fenced_div(txt)
127127
txt, tags = escape_invalid_tags(txt)

tests/docs/shortcodes/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/.quarto/
2+
3+
**/*.quarto_ipynb
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Shortcode with trailing punctuation
3+
format: html
4+
_quarto:
5+
tests:
6+
html:
7+
ensureFileRegexMatches:
8+
-
9+
- '<p>Normal shortcode: [0-9]+\.[0-9]+\.[0-9]+</p>'
10+
- '<p>Shortcode with trailing dash: [0-9]+\.[0-9]+\.[0-9]+-</p>'
11+
- '<p>Shortcode with trailing semicolon: [0-9]+\.[0-9]+\.[0-9]+;suffix</p>'
12+
- []
13+
---
14+
15+
Normal shortcode: {{< version >}}
16+
17+
Shortcode with trailing dash: {{< version >}}-
18+
19+
Shortcode with trailing semicolon: {{< version >}};suffix

0 commit comments

Comments
 (0)