Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug Fixes

- fix: Stand the Skylighting hot-fix down when the filter is off, so a Typst document that sets `enabled: false` compiles. It failed on an undeclared name before. (#71)
- fix: Keep a block's own language where the filter derives no name for it, which means the filter is off, or `auto-filename` is off, or the output format is neither HTML nor Typst. The block was relabelled as `default` before, and the language the author wrote was lost. (#66)
- 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)
Expand Down
9 changes: 8 additions & 1 deletion _extensions/code-window/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,19 @@ local filters = {

local skylighting_mod = load_skylighting_hotfix_module()

-- The hot-fix exists only to serve the chrome, so it asks draws_chrome like
-- every other pass that does. Its Skylighting override calls the colour helpers,
-- and code_window.Pandoc is what declares them, so asking hotfix_skylighting
-- alone left the override in a document that declared none.
for _, subfilter in ipairs(skylighting_mod.filters or {}) do
local wrapped = {}
for element_type, handler in pairs(subfilter) do
wrapped[element_type] = function(...)
if not code_window.draws_chrome() then
return nil
end
local cfg = code_window.CONFIG()
if not cfg or not cfg.hotfix_skylighting then
if not cfg.hotfix_skylighting then
return nil
end
if skylighting_mod.set_wrapper then
Expand Down
4 changes: 2 additions & 2 deletions docs/examples.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ The extension compares that string with the running Quarto.
At or above the named version the hot-fix stays out, whatever `enabled` says.
An upgrade thus retires the hot-fix with no further edit.

Two pairs are linked.
`code-annotations` and `skylighting` are linked.

`code-annotations` and `skylighting` work together: the first resolves the annotations, and the second supplies the rule that draws the circled marker beside an annotated line.
Turn `skylighting` off, and the numbered list stays under the block while every marker inside it goes, along with the block styling and the inline code backgrounds the same module supplies.

`typst-title` follows `enabled`: with the filter off, theorem titles stay as Quarto writes them.
Every hot-fix follows `enabled`: with the filter off, none of them acts, and the Typst document comes out as Quarto writes it.

See [Hot-fixes](reference.qmd#hot-fixes) for what each one corrects.

Expand Down
1 change: 1 addition & 0 deletions docs/reference.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ In Typst the chrome is a call to the `wrapper` function, emitted into the docume

Typst output needs a few corrections that Quarto does not yet make itself.
Each is on by default and each can be given a version at which it switches itself off, so an upgrade retires it without a code change.
All of them follow `enabled`, so a document that turns the filter off takes no hot-fix at all.

| Hot-fix | What it corrects |
| --- | --- |
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/filter-disabled-no-language.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ filters:
extensions:
code-window:
enabled: false
format:
typst:
keep-typ: true
---

A block with no language gains none while the filter is off. The block below is
indented rather than fenced, which gives the same code block with no language.

The inline code in `x = 1` keeps the shape Quarto gives it too, because the
hot-fix that boxes it stands down with the filter.

x = 1
6 changes: 6 additions & 0 deletions tests/fixtures/filter-disabled.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ filters:
extensions:
code-window:
enabled: false
format:
typst:
keep-typ: true
---

A filter that is off leaves every block as Quarto writes it. The block below
keeps the language its author gave it, even though Pandoc cannot highlight it
and the filter would relabel it when it is on.

The inline code in `x = 1` keeps the shape Quarto gives it too, because the
hot-fix that boxes it stands down with the filter.

```foo
x = 1
```
38 changes: 38 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,44 @@ else
"a default class, a cw-auto class, and data-filename=\"foo\" on the block"
fi

# ============================================================================
# The Typst hot-fix stands down with the filter
# ============================================================================

# The hot-fix contributes two passes, and both write Typst that only the
# filter's own preamble declares. That preamble is not written with the filter
# off, so both passes have to stand down there. The block pass is caught by the
# "_cw-" prefix the colour helpers and the annotation state share. The inline
# pass takes a different shape where the theme gives a background colour, and
# names no helper at all, so the box itself is the thing to look for.
for fixture in filter-disabled filter-disabled-no-language; do
render "${fixture}" typst

# Both assertions below are negative, and a missing file would answer them
# the same way a clean render does. So the file is checked for first.
if [ -f "${work_dir}/${fixture}.typ" ]; then
report pass "${fixture}: the render keeps its Typst source"
else
report fail "${fixture}: the render keeps its Typst source" \
"a ${fixture}.typ in the work directory"
continue
fi

if grep -q '_cw-' "${work_dir}/${fixture}.typ"; then
report fail "${fixture}: the block pass stands down with the filter" \
"no _cw- helper call in ${fixture}.typ"
else
report pass "${fixture}: the block pass stands down with the filter"
fi

if grep -q 'box(fill: rgb(' "${work_dir}/${fixture}.typ"; then
report fail "${fixture}: the inline pass stands down with the filter" \
"no box(fill: rgb( call in ${fixture}.typ"
else
report pass "${fixture}: the inline pass stands down with the filter"
fi
done

# ============================================================================
# The schema is where an option's default is written down
# ============================================================================
Expand Down
Loading