Skip to content

Commit 251360a

Browse files
committed
lua - escape fenced code correctly at line beginning (#14177)
1 parent cb7f370 commit 251360a

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

news/changelog-1.9.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,5 @@ All changes included in 1.9:
222222
- ([#13998](https://github.com/quarto-dev/quarto-cli/issues/13998)): Fix YAML validation error with CR-only line terminators (old Mac format). Documents using `\r` line endings no longer fail with "Expected YAML front matter to contain at least 2 lines".
223223
- ([#14012](https://github.com/quarto-dev/quarto-cli/issues/14012)): Add `fr-CA` language translation for Quebec French inclusive writing conventions, using parenthetical forms instead of middle dots for author labels. (author: @tdhock)
224224
- ([#14032](https://github.com/quarto-dev/quarto-cli/issues/14032)): Add `editor_options` with `chunk_output_type` to YAML schema for autocompletion and validation in RStudio and Positron.
225-
- ([#14156](https://github.com/quarto-dev/quarto-cli/issues/14156)): Avoid O(n^2) performance in handling large code blocks.
225+
- ([#14156](https://github.com/quarto-dev/quarto-cli/issues/14156)): Avoid O(n^2) performance in handling large code blocks.
226+
- ([#14177](https://github.com/quarto-dev/quarto-cli/issues/14177)): Escape fenced code correctly when backticks occur at the beginning of a line.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ 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-
-- The original pattern cannot cross newlines (due to [^`\n]+), so processing
12-
-- per-line is semantically equivalent and avoids catastrophic backtracking.
13-
local line_pattern = "([^`\n]+`+)" .. patterns.engine_escape
10+
11+
local line_pattern = "([^`\n]*`+)" .. patterns.engine_escape
1412
local function unescape_inline_engine_codes(text)
1513
if not text:find("{{", 1, true) then
1614
return text
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Issue with fenced inline code at beginning of line"
3+
_quarto:
4+
tests:
5+
html:
6+
ensureFileRegexMatches:
7+
- []
8+
- ["\\{\\{"]
9+
---
10+
11+
For teaching materials explaining how to use insert inline code, I would like to display source code demonstrating how to use inline code in the rendered version of a Quarto document. Here's an example below:
12+
13+
``` markdown
14+
## Inline code demo
15+
16+
`{{r}} nrow(penguins)` penguins are included in the amazing `penguins` dataset.
17+
On average these penguins weigh `{{r}} mean(penguins$body_mass, na.rm = TRUE)` grams, although the lightest weighs `{{r}} min(penguins$body_mass, na.rm = TRUE)` g and the heaviest `{{r}} max(penguins$body_mass, na.rm = TRUE)` g.
18+
```
19+
20+
When the paragraph above is rendered, the inline code snippets are all correctly rendered as fenced code except the first one that retains its double curly brackets (see screenshot).

0 commit comments

Comments
 (0)