From c06b2e39ed3e2806f2e80c3005293bc777f0210c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:18:27 +0200 Subject: [PATCH 1/9] fix: write the token definitions for inline code A Typst document with inline code and no code block failed to compile, because Pandoc had nothing left to highlight and wrote no token definitions for the tokens the inline pass had already written. The filter now builds the definitions from the document's own highlight method and writes them once. --- CHANGELOG.md | 1 + .../_modules/hotfix/skylighting-typst-fix.lua | 55 ++++++++++++++++++- tests/fixtures/inline-code-only.qmd | 15 +++++ tests/fixtures/inline-code-with-block.qmd | 19 +++++++ tests/run.sh | 17 ++++++ 5 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/inline-code-only.qmd create mode 100644 tests/fixtures/inline-code-with-block.qmd diff --git a/CHANGELOG.md b/CHANGELOG.md index c7853c0..4c7c08e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Bug Fixes +- fix: Write the syntax highlighting definitions into a Typst document that has inline code and no code block. Such a document failed to compile before, because the definitions never reached it. - fix: Remove the code-window attributes from a block that sets code-window-enabled="false", and from a block that sets code-window-lines when lines-label is off. They reached the HTML output as data-code-window-* attributes before. (#63) - fix: Remove the extension's own label attribute when the output format gets no window chrome, so a writer that keeps attributes no longer prints it. (#63) - fix: Check every code block attribute in the code-window group against the schema, so a value nothing validated before, such as code-window-enabled, is now reported when it is wrong. The extension's own duplicate warnings for an invalid code-window-style or code-window-collapse are removed, since the schema already names the same mistake. (#60) diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index 7d1aef8..13dd735 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -155,6 +155,39 @@ local function build_raw_line_annotation_rule() ]==], circled, circled) end +--- Build the syntax highlighting token definitions for Typst. +--- The inline pass writes its tokens itself, so Pandoc sees nothing left to +--- highlight and writes no definitions for a document that has no code block. +--- Writing one throwaway block with the document's own highlight method gives +--- the definitions for the theme in use. +--- @return string|nil Typst #let definitions, or nil when there are none +local function build_highlight_macros() + local hm = PANDOC_WRITER_OPTIONS and PANDOC_WRITER_OPTIONS.highlight_method + if not hm then return nil end + + local ok, rendered = pcall(function() + return pandoc.write( + pandoc.Pandoc({ pandoc.CodeBlock('x', pandoc.Attr('', { 'python' })) }), + 'typst', + pandoc.WriterOptions({ + highlight_method = hm, + template = pandoc.template.compile(pandoc.template.default('typst')), + }) + ) + end) + if not ok or type(rendered) ~= 'string' then return nil end + + local definitions = {} + for line in rendered:gmatch('[^\n]+') do + if line:match('^#let %a+Tok%(s%) =') then + table.insert(definitions, line) + end + end + if #definitions == 0 then return nil end + + return '// code-window highlight macros\n' .. table.concat(definitions, '\n') .. '\n' +end + --- Process inline Code for Typst format. --- Renders the Code element through Pandoc's Typst writer to get syntax- --- highlighted output, then wraps it in a box with the theme background colour. @@ -256,7 +289,16 @@ local function process_inline_code(doc) return doc end - local code_filter = { Code = function(el) return process_typst_inline(el) end } + local wrote_tokens = false + local code_filter = { + Code = function(el) + local replaced = process_typst_inline(el) + if replaced.t == 'RawInline' and replaced.text:find('Tok(', 1, true) then + wrote_tokens = true + end + return replaced + end, + } local title_filter = { Code = function(el) return pandoc.RawInline('typst', '`' .. el.text .. '`') @@ -281,6 +323,17 @@ local function process_inline_code(doc) end doc.blocks = walk_blocks(doc.blocks) + + -- A code block makes Pandoc write the same definitions into the preamble. + -- Typst takes the later binding, and both sets hold the same values, so the + -- pair is harmless and the document compiles either way. + if wrote_tokens then + local macros = build_highlight_macros() + if macros then + table.insert(doc.blocks, 1, pandoc.RawBlock('typst', macros)) + end + end + return doc end diff --git a/tests/fixtures/inline-code-only.qmd b/tests/fixtures/inline-code-only.qmd new file mode 100644 index 0000000..a2aabf9 --- /dev/null +++ b/tests/fixtures/inline-code-only.qmd @@ -0,0 +1,15 @@ +--- +title: "Inline code, no block" +filters: + - code-window +format: + typst: + keep-typ: true +--- + +The document below has inline code and no code block. + +The filter writes the inline code as highlighted Typst, so the token +definitions have to reach the document on their own. + +A paragraph with `inline code` in it. diff --git a/tests/fixtures/inline-code-with-block.qmd b/tests/fixtures/inline-code-with-block.qmd new file mode 100644 index 0000000..77af5c6 --- /dev/null +++ b/tests/fixtures/inline-code-with-block.qmd @@ -0,0 +1,19 @@ +--- +title: "Inline code and a block" +filters: + - code-window +format: + typst: + keep-typ: true +--- + +The document below has inline code and a code block. + +Pandoc writes the token definitions for the block, so the definitions the +filter adds for the inline code are a second set of the same names. + +A paragraph with `inline code` in it. + +```python +x = 1 +``` diff --git a/tests/run.sh b/tests/run.sh index ae328f0..ea3d432 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -85,6 +85,23 @@ for fixture in cell-output-bare cell-output-classed; do fi done +# ============================================================================ +# The token definitions reach a document the filter highlights +# ============================================================================ + +# The filter writes inline code as pre-rendered Typst tokens, so the token +# definitions have to be in the document whether or not a code block put them +# there. A document with no code block fails to compile without them. +for fixture in inline-code-only inline-code-with-block; do + render "${fixture}" typst + if grep -q '^#let NormalTok(' "${work_dir}/${fixture}.typ"; then + report pass "${fixture}: the token definitions reach the document" + else + report fail "${fixture}: the token definitions reach the document" \ + "a #let NormalTok( definition in ${fixture}.typ" + fi +done + # ============================================================================ # A per-block style override reaches the output # ============================================================================ From e0a7887ea1f6fb29b54ceba01363048b60083da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:23:56 +0200 Subject: [PATCH 2/9] refactor: box inline code around the code element The inline pass rendered each Code element to Typst itself and put the result in a raw inline. Pandoc then had nothing to highlight, so it wrote no token definitions. The pass now wraps the element in place. Pandoc highlights it, writes the definitions, and the inline output is unchanged. --- CHANGELOG.md | 2 +- .../_modules/hotfix/skylighting-typst-fix.lua | 105 ++++-------------- tests/fixtures/inline-code-with-block.qmd | 19 ---- tests/run.sh | 24 ++-- 4 files changed, 33 insertions(+), 117 deletions(-) delete mode 100644 tests/fixtures/inline-code-with-block.qmd diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7c08e..a3223f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Bug Fixes -- fix: Write the syntax highlighting definitions into a Typst document that has inline code and no code block. Such a document failed to compile before, because the definitions never reached it. +- fix: Keep inline code in a Typst document as a code element, so Pandoc writes the syntax highlighting definitions for it. A document with inline code and no code block failed to compile before. - fix: Remove the code-window attributes from a block that sets code-window-enabled="false", and from a block that sets code-window-lines when lines-label is off. They reached the HTML output as data-code-window-* attributes before. (#63) - fix: Remove the extension's own label attribute when the output format gets no window chrome, so a writer that keeps attributes no longer prints it. (#63) - fix: Check every code block attribute in the code-window group against the schema, so a value nothing validated before, such as code-window-enabled, is now reported when it is wrong. The extension's own duplicate warnings for an invalid code-window-style or code-window-collapse are removed, since the schema already names the same mistake. (#60) diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index 13dd735..6ce0580 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -155,77 +155,34 @@ local function build_raw_line_annotation_rule() ]==], circled, circled) end ---- Build the syntax highlighting token definitions for Typst. ---- The inline pass writes its tokens itself, so Pandoc sees nothing left to ---- highlight and writes no definitions for a document that has no code block. ---- Writing one throwaway block with the document's own highlight method gives ---- the definitions for the theme in use. ---- @return string|nil Typst #let definitions, or nil when there are none -local function build_highlight_macros() - local hm = PANDOC_WRITER_OPTIONS and PANDOC_WRITER_OPTIONS.highlight_method - if not hm then return nil end - - local ok, rendered = pcall(function() - return pandoc.write( - pandoc.Pandoc({ pandoc.CodeBlock('x', pandoc.Attr('', { 'python' })) }), - 'typst', - pandoc.WriterOptions({ - highlight_method = hm, - template = pandoc.template.compile(pandoc.template.default('typst')), - }) - ) - end) - if not ok or type(rendered) ~= 'string' then return nil end - - local definitions = {} - for line in rendered:gmatch('[^\n]+') do - if line:match('^#let %a+Tok%(s%) =') then - table.insert(definitions, line) - end - end - if #definitions == 0 then return nil end - - return '// code-window highlight macros\n' .. table.concat(definitions, '\n') .. '\n' -end - --- Process inline Code for Typst format. ---- Renders the Code element through Pandoc's Typst writer to get syntax- ---- highlighted output, then wraps it in a box with the theme background colour. +--- Puts the Code element in a box that carries the theme background colour. +--- The element itself stays in the document, so Pandoc highlights it and +--- writes the token definitions for it. --- @param el pandoc.Code Inline code element ---- @return pandoc.RawInline|pandoc.Code Transformed or original element +--- @return pandoc.Inlines The boxed code local function process_typst_inline(el) local hm = PANDOC_WRITER_OPTIONS and PANDOC_WRITER_OPTIONS.highlight_method - local bg_fill = nil - local write_opts = nil - - if hm then - local bg = hm['background-color'] - if bg and type(bg) == 'string' then - bg_fill = string.format('rgb("%s")', bg) - end - write_opts = pandoc.WriterOptions({ - highlight_method = hm, - }) - end - - local rendered = pandoc.write(pandoc.Pandoc({ pandoc.Plain({ el }) }), 'typst', write_opts) - rendered = rendered:gsub('%s+$', '') - if rendered == '' then return el end + local bg = hm and hm['background-color'] + local opening, closing - local typst_code - if bg_fill then - typst_code = string.format( - '#box(fill: %s, inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, stroke: none)[%s]', - bg_fill, rendered) + if type(bg) == 'string' then + opening = string.format( + '#box(fill: rgb("%s"), inset: (x: 3pt, y: 0pt), outset: (y: 3pt), ' + .. 'radius: 2pt, stroke: none)[', bg) + closing = ']' else - typst_code = string.format( - '#context { let _bg = _cw-page-bg(); let _f = _cw-fg(_bg); ' - .. 'box(fill: color.mix((_f, 10%%), (_bg, 90%%)), ' - .. 'inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, stroke: none)[%s] }', - rendered) + opening = '#context { let _bg = _cw-page-bg(); let _f = _cw-fg(_bg); ' + .. 'box(fill: color.mix((_f, 10%), (_bg, 90%)), ' + .. 'inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, stroke: none)[' + closing = '] }' end - return pandoc.RawInline('typst', typst_code) + return pandoc.Inlines({ + pandoc.RawInline('typst', opening), + el, + pandoc.RawInline('typst', closing), + }) end --- Inject Skylighting override at the start of the document. @@ -289,16 +246,7 @@ local function process_inline_code(doc) return doc end - local wrote_tokens = false - local code_filter = { - Code = function(el) - local replaced = process_typst_inline(el) - if replaced.t == 'RawInline' and replaced.text:find('Tok(', 1, true) then - wrote_tokens = true - end - return replaced - end, - } + local code_filter = { Code = function(el) return process_typst_inline(el) end } local title_filter = { Code = function(el) return pandoc.RawInline('typst', '`' .. el.text .. '`') @@ -323,17 +271,6 @@ local function process_inline_code(doc) end doc.blocks = walk_blocks(doc.blocks) - - -- A code block makes Pandoc write the same definitions into the preamble. - -- Typst takes the later binding, and both sets hold the same values, so the - -- pair is harmless and the document compiles either way. - if wrote_tokens then - local macros = build_highlight_macros() - if macros then - table.insert(doc.blocks, 1, pandoc.RawBlock('typst', macros)) - end - end - return doc end diff --git a/tests/fixtures/inline-code-with-block.qmd b/tests/fixtures/inline-code-with-block.qmd deleted file mode 100644 index 77af5c6..0000000 --- a/tests/fixtures/inline-code-with-block.qmd +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "Inline code and a block" -filters: - - code-window -format: - typst: - keep-typ: true ---- - -The document below has inline code and a code block. - -Pandoc writes the token definitions for the block, so the definitions the -filter adds for the inline code are a second set of the same names. - -A paragraph with `inline code` in it. - -```python -x = 1 -``` diff --git a/tests/run.sh b/tests/run.sh index ea3d432..8864355 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -86,21 +86,19 @@ for fixture in cell-output-bare cell-output-classed; do done # ============================================================================ -# The token definitions reach a document the filter highlights +# Inline code keeps the token definitions in a document with no code block # ============================================================================ -# The filter writes inline code as pre-rendered Typst tokens, so the token -# definitions have to be in the document whether or not a code block put them -# there. A document with no code block fails to compile without them. -for fixture in inline-code-only inline-code-with-block; do - render "${fixture}" typst - if grep -q '^#let NormalTok(' "${work_dir}/${fixture}.typ"; then - report pass "${fixture}: the token definitions reach the document" - else - report fail "${fixture}: the token definitions reach the document" \ - "a #let NormalTok( definition in ${fixture}.typ" - fi -done +# The filter boxes inline code and leaves the element itself in place, so +# Pandoc highlights it and writes the token definitions. The render fails to +# compile when they are missing, and the grep says why. +render inline-code-only typst +if grep -q '^#let NormalTok(' "${work_dir}/inline-code-only.typ"; then + report pass "inline-code-only: the token definitions reach the document" +else + report fail "inline-code-only: the token definitions reach the document" \ + "a #let NormalTok( definition in inline-code-only.typ" +fi # ============================================================================ # A per-block style override reaches the output From 9ea64cc49524d0d90f39747083223442bdb59480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:27:13 +0200 Subject: [PATCH 3/9] test: describe what the inline code fixture guards --- tests/fixtures/inline-code-only.qmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/inline-code-only.qmd b/tests/fixtures/inline-code-only.qmd index a2aabf9..65d5eb9 100644 --- a/tests/fixtures/inline-code-only.qmd +++ b/tests/fixtures/inline-code-only.qmd @@ -9,7 +9,7 @@ format: The document below has inline code and no code block. -The filter writes the inline code as highlighted Typst, so the token -definitions have to reach the document on their own. +The filter boxes the inline code and leaves the element in place, so Pandoc +writes the token definitions for it. A paragraph with `inline code` in it. From 0bf2ad67894ec2a4ddd50dcb11c740651925b67e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:29:58 +0200 Subject: [PATCH 4/9] docs: describe what the inline pass does now --- .../code-window/_modules/hotfix/skylighting-typst-fix.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index 6ce0580..b3f0bc4 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -235,8 +235,8 @@ local function is_title_scaffold(div) return true end ---- Walk the document tree and convert inline Code to RawInline with ---- background styling. Code in title scaffolds is converted to plain +--- Walk the document tree and box inline Code with background styling. +--- Code in title scaffolds is converted to plain --- Typst backtick code to avoid Skylighting tokens with inner quotes --- that would break the string parameter Quarto generates. --- The typst-title-fix post-quarto filter then evaluates the string From 851f05838231cceeda62742256f3227bc2db19f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:32:33 +0200 Subject: [PATCH 5/9] test: render inline code with no theme colour --- tests/fixtures/inline-code-no-theme.qmd | 17 +++++++++++++++++ tests/run.sh | 10 ++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/fixtures/inline-code-no-theme.qmd diff --git a/tests/fixtures/inline-code-no-theme.qmd b/tests/fixtures/inline-code-no-theme.qmd new file mode 100644 index 0000000..f572db7 --- /dev/null +++ b/tests/fixtures/inline-code-no-theme.qmd @@ -0,0 +1,17 @@ +--- +title: "Inline code, no theme" +filters: + - code-window +highlight-style: none +format: + typst: + keep-typ: true +--- + +The document below turns syntax highlighting off, so the theme gives no +background colour. + +The filter then boxes the inline code with a colour it mixes from the page, +and that box has to compile too. + +A paragraph with `inline code` in it. diff --git a/tests/run.sh b/tests/run.sh index 8864355..ecec923 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -100,6 +100,16 @@ else "a #let NormalTok( definition in inline-code-only.typ" fi +# A theme that gives no background colour takes the other box, which mixes its +# colour from the page. The render compiles that box. +render inline-code-no-theme typst +if grep -q 'box(fill: color.mix' "${work_dir}/inline-code-no-theme.typ"; then + report pass "inline-code-no-theme: the box takes its colour from the page" +else + report fail "inline-code-no-theme: the box takes its colour from the page" \ + "a box(fill: color.mix call in inline-code-no-theme.typ" +fi + # ============================================================================ # A per-block style override reaches the output # ============================================================================ From 709e1d29b178176080608ed730b8d5e7715d07b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:33:22 +0200 Subject: [PATCH 6/9] docs: reference the pull request in the changelog [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3223f0..4db0b6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ ### Bug Fixes -- fix: Keep inline code in a Typst document as a code element, so Pandoc writes the syntax highlighting definitions for it. A document with inline code and no code block failed to compile before. +- fix: Keep inline code in a Typst document as a code element, so Pandoc writes the syntax highlighting definitions for it. A document with inline code and no code block failed to compile before. (#65) - fix: Remove the code-window attributes from a block that sets code-window-enabled="false", and from a block that sets code-window-lines when lines-label is off. They reached the HTML output as data-code-window-* attributes before. (#63) - fix: Remove the extension's own label attribute when the output format gets no window chrome, so a writer that keeps attributes no longer prints it. (#63) - fix: Check every code block attribute in the code-window group against the schema, so a value nothing validated before, such as code-window-enabled, is now reported when it is wrong. The extension's own duplicate warnings for an invalid code-window-style or code-window-collapse are removed, since the schema already names the same mistake. (#60) From 4767a65e151aad7e827703e777f1c086ce5f3e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:38:25 +0200 Subject: [PATCH 7/9] test: check the box that names the theme colour --- tests/run.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/run.sh b/tests/run.sh index ecec923..065914f 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -100,6 +100,14 @@ else "a #let NormalTok( definition in inline-code-only.typ" fi +# A theme with a background colour takes the box that names the colour. +if grep -q 'box(fill: rgb(' "${work_dir}/inline-code-only.typ"; then + report pass "inline-code-only: the box takes the colour of the theme" +else + report fail "inline-code-only: the box takes the colour of the theme" \ + "a box(fill: rgb( call in inline-code-only.typ" +fi + # A theme that gives no background colour takes the other box, which mixes its # colour from the page. The render compiles that box. render inline-code-no-theme typst From e56f6a908fc729eed23504e98ae4467845d261e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:42:39 +0200 Subject: [PATCH 8/9] test: render a document with a block and inline code --- .../_modules/hotfix/skylighting-typst-fix.lua | 2 ++ tests/fixtures/inline-code-with-block.qmd | 19 +++++++++++++++++++ tests/run.sh | 11 +++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/fixtures/inline-code-with-block.qmd diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index b3f0bc4..334598d 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -236,6 +236,8 @@ local function is_title_scaffold(div) end --- Walk the document tree and box inline Code with background styling. +--- The extension contributes the pass once, so it sees each Code element +--- once and boxes it once. --- Code in title scaffolds is converted to plain --- Typst backtick code to avoid Skylighting tokens with inner quotes --- that would break the string parameter Quarto generates. diff --git a/tests/fixtures/inline-code-with-block.qmd b/tests/fixtures/inline-code-with-block.qmd new file mode 100644 index 0000000..2f1c4c1 --- /dev/null +++ b/tests/fixtures/inline-code-with-block.qmd @@ -0,0 +1,19 @@ +--- +title: "Inline code and a block" +filters: + - code-window +format: + typst: + keep-typ: true +--- + +The document below has inline code and a code block. + +The boxed inline code and the block that goes through the Skylighting +override share one document, and that document has to compile. + +A paragraph with `inline code` in it. + +```python +x = 1 +``` diff --git a/tests/run.sh b/tests/run.sh index 065914f..0b5c929 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -108,6 +108,17 @@ else "a box(fill: rgb( call in inline-code-only.typ" fi +# A code block goes through the Skylighting override, and the inline code +# keeps its own box in the same document. +render inline-code-with-block typst +if grep -q '^#Skylighting(' "${work_dir}/inline-code-with-block.typ" && + grep -q 'box(fill: rgb(' "${work_dir}/inline-code-with-block.typ"; then + report pass "inline-code-with-block: the block and the inline code share the document" +else + report fail "inline-code-with-block: the block and the inline code share the document" \ + "a #Skylighting( call and a box(fill: rgb( call in inline-code-with-block.typ" +fi + # A theme that gives no background colour takes the other box, which mixes its # colour from the page. The render compiles that box. render inline-code-no-theme typst From 91e0f5fae2197732d7c4c36b5d5de6409865cd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sun, 20 Sep 2026 20:46:27 +0200 Subject: [PATCH 9/9] refactor: name the shape of the inline code box --- .../_modules/hotfix/skylighting-typst-fix.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua index 334598d..a3a48d3 100644 --- a/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua +++ b/_extensions/code-window/_modules/hotfix/skylighting-typst-fix.lua @@ -155,6 +155,10 @@ local function build_raw_line_annotation_rule() ]==], circled, circled) end +--- Shape of the box that holds inline code, after its fill. +local _inline_box_style = 'inset: (x: 3pt, y: 0pt), outset: (y: 3pt), ' + .. 'radius: 2pt, stroke: none)[' + --- Process inline Code for Typst format. --- Puts the Code element in a box that carries the theme background colour. --- The element itself stays in the document, so Pandoc highlights it and @@ -167,14 +171,11 @@ local function process_typst_inline(el) local opening, closing if type(bg) == 'string' then - opening = string.format( - '#box(fill: rgb("%s"), inset: (x: 3pt, y: 0pt), outset: (y: 3pt), ' - .. 'radius: 2pt, stroke: none)[', bg) + opening = string.format('#box(fill: rgb("%s"), ', bg) .. _inline_box_style closing = ']' else opening = '#context { let _bg = _cw-page-bg(); let _f = _cw-fg(_bg); ' - .. 'box(fill: color.mix((_f, 10%), (_bg, 90%)), ' - .. 'inset: (x: 3pt, y: 0pt), outset: (y: 3pt), radius: 2pt, stroke: none)[' + .. 'box(fill: color.mix((_f, 10%), (_bg, 90%)), ' .. _inline_box_style closing = '] }' end