Skip to content

Commit a38b543

Browse files
committed
better fix to avoid regression
1 parent 251360a commit a38b543

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/resources/filters/quarto-pre/engine-escape.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ function engine_escape()
77
-- Line-by-line replacement for the pattern (\n?[^`\n]+`+){({+([^<}]+)}+)}
88
-- which suffers from O(n^2) backtracking on long lines without backticks.
99
-- See https://github.com/quarto-dev/quarto-cli/issues/14156
10-
11-
local line_pattern = "([^`\n]*`+)" .. patterns.engine_escape
10+
-- Start-of-line fix for https://github.com/quarto-dev/quarto-cli/issues/14177
11+
--
12+
-- Two patterns for inline engine escape replacement:
13+
-- 1. Start-of-line: match 1-2 backticks only (inline code, not code fences)
14+
-- 2. Mid-line: match any backticks preceded by non-backtick text
15+
-- This avoids over-processing code fence patterns (```{{engine}}) produced by step 2.
16+
local sol_pattern = "^(``?)" .. patterns.engine_escape
17+
local mid_pattern = "([^`\n]+`+)" .. patterns.engine_escape
1218
local function unescape_inline_engine_codes(text)
1319
if not text:find("{{", 1, true) then
1420
return text
@@ -27,7 +33,8 @@ function engine_escape()
2733
pos = len + 1
2834
end
2935
if line:find("`", 1, true) and line:find("{{", 1, true) then
30-
line = line:gsub(line_pattern, "%1%2")
36+
line = line:gsub(sol_pattern, "%1%2")
37+
line = line:gsub(mid_pattern, "%1%2")
3138
end
3239
result[#result + 1] = line
3340
end

0 commit comments

Comments
 (0)