From b3897fad0cc5a34efb5b5f4c44a6611abec39c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:20:57 +0100 Subject: [PATCH 1/5] build: vendor schema 2.4.0 and quarto-lua-modules 2.13.0 --- _extensions/code-window/_dependencies.yml | 6 +- .../_vendor/quarto-wizard/schema.lua | 307 +++++++++++++++--- 2 files changed, 265 insertions(+), 48 deletions(-) diff --git a/_extensions/code-window/_dependencies.yml b/_extensions/code-window/_dependencies.yml index 4a89493..9d47bf2 100644 --- a/_extensions/code-window/_dependencies.yml +++ b/_extensions/code-window/_dependencies.yml @@ -3,7 +3,7 @@ sources: quarto-lua-modules: origin: "https://github.com/mcanouil/quarto-lua-modules" fetch: "{origin}/releases/download/{version}/{file}" - version: "2.10.0" + version: "2.13.0" licence: MIT files: html.lua: @@ -27,10 +27,10 @@ sources: quarto-wizard: origin: "https://github.com/mcanouil/quarto-wizard" fetch: "{origin}/releases/download/{version}/{file}" - version: "2.2.0" + version: "2.4.0" licence: MIT tag-prefix: schema-v files: schema.lua: - sha256: "84e0a5a7bae8d71a6d601d581e3e819ace96613cc76c6e9dd3cf79eee629df78" + sha256: "851551fdd2fb415bcab3b8c2b7779281e61ac7dde50ba35194434dcde338e6c8" runtime: any diff --git a/_extensions/code-window/_vendor/quarto-wizard/schema.lua b/_extensions/code-window/_vendor/quarto-wizard/schema.lua index add64b8..0a7a094 100644 --- a/_extensions/code-window/_vendor/quarto-wizard/schema.lua +++ b/_extensions/code-window/_vendor/quarto-wizard/schema.lua @@ -3,7 +3,7 @@ --- @license MIT --- @copyright 2026 Mickaël Canouil --- @author Mickaël Canouil ---- @version 2.2.0 +--- @version 2.4.0 --- --- Implements the v2 extension schema vocabulary published at --- . @@ -27,11 +27,57 @@ M.SCHEMA_VERSION = 'https://m.canouil.dev/quarto-wizard/assets/schema/v2/extensi --- harness can install stubs before the first call. local _env = {} ---- Render a Pandoc value as plain text. +--- The marks that a `Quoted` element had in the source. +local _QUOTE_MARKS = { SingleQuote = "'", DoubleQuote = '"' } + +--- The characters that Pandoc's `smart` extension writes inside `Str`, mapped +--- back to what the source had. A typographic character that the author typed +--- also becomes ASCII, the same trade-off that `_QUOTE_MARKS` makes. +local _SMART_CHARACTERS = { + ['‘'] = "'", + ['’'] = "'", + ['“'] = '"', + ['”'] = '"', + ['–'] = '--', + ['—'] = '---', + ['…'] = '...', +} + +--- The walk that puts raw HTML, quotes and smart punctuation back as the +--- source text. +local _LITERAL_FILTER = { + Str = function(str) + local text = str.text + for typographic, ascii in pairs(_SMART_CHARACTERS) do + text = text:gsub(typographic, ascii) + end + return pandoc.Str(text) + end, + RawInline = function(raw) + return pandoc.Str(raw.text) + end, + RawBlock = function(raw) + return pandoc.Plain({ pandoc.Str(raw.text) }) + end, + Quoted = function(quoted) + local mark = _QUOTE_MARKS[quoted.quotetype] + local inlines = pandoc.Inlines({ pandoc.Str(mark) }) + inlines:extend(quoted.content) + inlines:insert(pandoc.Str(mark)) + return inlines + end, +} + +--- Render a Pandoc value as the plain text the document wrote. +--- Quarto reads a metadata string as Markdown, so raw HTML arrives as +--- `RawInline` or `RawBlock`, quotes arrive as `Quoted`, and `smart` turns +--- `'`, `--`, `---` and `...` into typographic characters. `stringify` alone +--- drops the raw HTML and keeps the typographic marks, so a label such as +--- `'A & x'` would come back as `A & x`. --- @param value any Pandoc value --- @return string Plain text function _env.stringify(value) - return pandoc.utils.stringify(value) + return pandoc.utils.stringify(value:walk(_LITERAL_FILTER)) end --- Report the Pandoc type of a value. @@ -81,6 +127,10 @@ local NUMERIC_KEYWORDS = { 'minLength', 'maxLength', 'minItems', 'maxItems', } +--- Keywords whose value is a boolean. `additionalProperties` can also hold a +--- descriptor. `deprecated` is not listed, because a string there is a message. +local BOOLEAN_KEYWORDS = { 'required', 'uniqueItems', 'enumCaseInsensitive', 'additionalProperties' } + --- Every keyword the v2 field descriptor may carry, mapped to whether this --- module enforces it. Annotations are carried through untouched for tooling. M.KEYWORDS = { @@ -823,6 +873,50 @@ local function _trim(text) return (text:gsub('^%s+', ''):gsub('%s+$', '')) end +local _DOUBLE_QUOTED_ESCAPES = { n = '\n', t = '\t', r = '\r' } + +--- Read the body of a quoted scalar up to its closing quote. +--- In double quotes, `\` escapes the next character. +--- In single quotes, `''` stands for one quote. +--- The closing quote must be the last character of the text. +--- @param text string Trimmed scalar text, opening quote included +--- @param line_number number Line number for errors +--- @return string|nil value Unquoted value +--- @return string|nil err +local function _parse_quoted(text, line_number) + local quote = text:sub(1, 1) + local style = quote == '"' and 'double-quoted' or 'single-quoted' + local out = {} + local index = 2 + while index <= #text do + local char = text:sub(index, index) + if quote == '"' and char == '\\' then + if index == #text then + break + end + local escaped = text:sub(index + 1, index + 1) + out[#out + 1] = _DOUBLE_QUOTED_ESCAPES[escaped] or escaped + index = index + 2 + elseif char == quote and quote == "'" and text:sub(index + 1, index + 1) == "'" then + out[#out + 1] = "'" + index = index + 2 + elseif char == quote then + if index ~= #text then + local rest = text:sub(index + 1) + if not rest:match('^%s') and rest:find(quote, 1, true) then + return nil, _yaml_error(line_number, 'unescaped ' .. quote .. ' inside a ' .. style .. ' scalar') + end + return nil, _yaml_error(line_number, 'text after the closing quote of a ' .. style .. ' scalar') + end + return table.concat(out), nil + else + out[#out + 1] = char + index = index + 1 + end + end + return nil, _yaml_error(line_number, 'unterminated ' .. style .. ' scalar') +end + --- Parse a scalar, giving numbers and booleans their real Lua types. --- @param text string Scalar text --- @param line_number number Line number for errors @@ -837,33 +931,20 @@ local function _parse_scalar(text, line_number) local first = text:sub(1, 1) - if first == '"' then - if #text < 2 or text:sub(-1) ~= '"' then - return nil, _yaml_error(line_number, 'unterminated double-quoted scalar') - end - return (text:sub(2, -2):gsub('\\(.)', function(escaped) - if escaped == 'n' then return '\n' end - if escaped == 't' then return '\t' end - if escaped == 'r' then return '\r' end - return escaped - end)), nil - end - - if first == "'" then - if #text < 2 or text:sub(-1) ~= "'" then - return nil, _yaml_error(line_number, 'unterminated single-quoted scalar') - end - return (text:sub(2, -2):gsub("''", "'")), nil + if first == '"' or first == "'" then + return _parse_quoted(text, line_number) end if first == '&' or first == '*' or first == '!' then return nil, _yaml_error(line_number, 'anchors, aliases and tags are not supported') end - if text == 'true' or text == 'True' or text == 'TRUE' or text == 'yes' or text == 'Yes' then + -- YAML 1.2, which Pandoc reads, has only these booleans. `yes` and `no` are + -- booleans in YAML 1.1 alone, so they stay strings, as Pandoc hands them over. + if text == 'true' or text == 'True' or text == 'TRUE' then return true, nil end - if text == 'false' or text == 'False' or text == 'FALSE' or text == 'no' or text == 'No' then + if text == 'false' or text == 'False' or text == 'FALSE' then return false, nil end @@ -1537,19 +1618,26 @@ _compile = function(spec) end end - if type(out.required) == 'string' then - out.required = out.required:lower() == 'true' or out.required:lower() == 'yes' - end - if type(out.uniqueItems) == 'string' then - out.uniqueItems = out.uniqueItems:lower() == 'true' - end - if type(out.enumCaseInsensitive) == 'string' then - out.enumCaseInsensitive = out.enumCaseInsensitive:lower() == 'true' - end - if out.additionalProperties == 'false' then - out.additionalProperties = false - elseif out.additionalProperties == 'true' then - out.additionalProperties = true + -- A schema file is read as YAML 1.2, so `yes` and `no` reach here as + -- strings. Only `true` and `false` name a boolean, in any case. Any other + -- value is dropped and reported, because guessing what it meant would turn a + -- check on or off without telling the author. + for _, keyword in ipairs(BOOLEAN_KEYWORDS) do + local value = out[keyword] + -- An empty table is a mapping as well as a list, and `{}` is a descriptor. + local descriptor = keyword == 'additionalProperties' and type(value) == 'table' + and not (_is_array(value) and #value > 0) + if value ~= nil and type(value) ~= 'boolean' and not descriptor then + local flag, ok = _coerce_scalar(value, 'boolean') + if ok then + out[keyword] = flag + else + out._keyword_faults = out._keyword_faults or {} + out._keyword_faults[#out._keyword_faults + 1] = string.format( + 'schema declares "%s" as "%s"; write true or false.', keyword, _format_value(value)) + out[keyword] = nil + end + end end if type(out.pattern) == 'string' then @@ -1573,7 +1661,20 @@ _compile = function(spec) out.additionalProperties = _compile(out.additionalProperties) end + -- Marks a tree that holds a keyword fault anywhere, so a tree without one + -- costs nothing to check. + out._has_faults = out._keyword_faults ~= nil + or (type(out.items) == 'table' and out.items._has_faults) + or (type(out.additionalProperties) == 'table' and out.additionalProperties._has_faults) + for _, property in pairs(type(out.properties) == 'table' and out.properties or {}) do + out._has_faults = out._has_faults or (type(property) == 'table' and property._has_faults) + end + + -- A compiled descriptor compiles to itself. `_check_object` hands compiled + -- properties back to `_validate_map`, and a fresh copy would hide from the + -- `faults_seen` set, so a nested fault would be reported twice. _compiled_cache[spec] = out + _compiled_cache[out] = out return out end @@ -1642,6 +1743,31 @@ local function _check_enum(value, spec, path, context) )) end +--- Report the keyword faults of a descriptor and of the descriptors under it. +--- A fault belongs to the schema and not to a value, so it is reported once at +--- its schema path, whether or not the document supplies a value there. +local function _check_keyword_faults(spec, path, context) + if type(spec) ~= 'table' or not spec._has_faults or context.faults_seen[spec] then + return + end + context.faults_seen[spec] = true + for _, message in ipairs(spec._keyword_faults or {}) do + _report(context, 'error', path, 'schema', message) + end + _check_keyword_faults(spec.items, path .. '.items', context) + _check_keyword_faults(spec.additionalProperties, path .. '.additionalProperties', context) + if type(spec.properties) == 'table' then + local keys = {} + for key in pairs(spec.properties) do + keys[#keys + 1] = key + end + table.sort(keys) + for _, key in ipairs(keys) do + _check_keyword_faults(spec.properties[key], path .. '.' .. key, context) + end + end +end + --- Check `pattern`, reporting a pattern the module cannot compile. local function _check_pattern(value, spec, path, context) if spec.pattern == nil or type(value) ~= 'string' then @@ -1986,6 +2112,34 @@ local function _declare_spelling(sources, spelling, field, base_path, context) end +--- Build an absent object from the defaults that its properties declare. +--- The members are validated as they are built, as any default is, but a +--- `required` member is not reported: nobody wrote the object. +--- Only a descriptor whose type is `object` alone is built. A type such as +--- `[boolean, object]` stays absent, so a filter that tests the option for +--- truth does not see an object that nobody asked for. +--- @param spec table Compiled descriptor without a `default` of its own +--- @param path string Dotted path of the object +--- @param context table Validation context +--- @return table|nil Object of defaults, or nil when no property declares one +local function _build_from_defaults(spec, path, context) + local names = _type_names(spec.type) + if type(spec.properties) ~= 'table' or names == nil or #names ~= 1 or names[1] ~= 'object' then + return nil + end + + -- Set on the context rather than passed as an option, so that the check of + -- an object `default` further down the build sees it as well. + local outer = context.defaults_only + context.defaults_only = true + local built = _validate_map({}, spec.properties, path, context) + context.defaults_only = outer + if next(built) == nil then + return nil + end + return built +end + --- Validate a map of values against a map of field descriptors. --- @param values table Values to validate --- @param descriptors table Field descriptor map @@ -1993,7 +2147,8 @@ end --- @param context table Validation context --- @param options table|nil {unknown = 'warn'|'error'|'ignore', additional = descriptor} --- @return table merged Values with aliases, coercion and defaults applied ---- @return table defaulted Set of field names whose value came from `default` +--- @return table defaulted Set of field names whose value came from `default`. +--- An object built from the defaults of its properties is marked 'built'. --- @return table sources Map of every spelling the schema accepts to the --- declared name it resolves to. A reader that has to answer a question --- about a name the caller wrote asks this rather than walking the @@ -2084,6 +2239,7 @@ _validate_map = function(values, descriptors, base_path, context, options) for _, entry in ipairs(fields) do local field, spec, path = entry.name, entry.spec, entry.path local value + local built = false if entry.cleared then value = nil @@ -2095,14 +2251,26 @@ _validate_map = function(values, descriptors, base_path, context, options) value = spec.default merged[field] = value defaulted[field] = true + elseif value == nil then + -- An object without a default of its own takes one from the defaults + -- of its properties, at any depth. The build validated its members, + -- and it does not satisfy `required`: the defaults describe the + -- members, and the author still has to write the object. + value = _build_from_defaults(spec, path, context) + if value ~= nil then + merged[field] = value + defaulted[field] = 'built' + built = true + end end end -- An empty string is a value the author wrote. Only a missing key is -- absent, so `minLength`, `const` and `enum` can be tested against ''. - if spec.required == true and value == nil then + _check_keyword_faults(spec, path, context) + if spec.required == true and not context.defaults_only and (value == nil or built) then _report(context, 'error', path, 'required', 'is required but was not provided.') - elseif value ~= nil then + elseif value ~= nil and not built then _validate_value(value, spec, path, context) end end @@ -2132,7 +2300,7 @@ end --- Start a validation run. --- @return table Fresh validation context local function _new_context() - return { findings = {} } + return { findings = {}, faults_seen = {} } end --- Close a validation run and shape the public return values. @@ -2160,7 +2328,7 @@ end --- carry on with a nil schema and fail later somewhere unrelated. --- --- @param filename string|nil Path to the schema file (defaults to '_schema.yml') ---- @return table|nil schema Schema with {['$schema'], options, shortcodes, formats, projects, attributes, classes} +--- @return table|nil schema Schema with {['$schema'], options, shortcodes, formats, projects, attributes, classes, cells} --- @return string|nil err Why the schema could not be read --- @usage local schema, err = M.load_schema('_schema.yml') function M.load_schema(filename) @@ -2177,6 +2345,7 @@ function M.load_schema(filename) projects = raw.projects or {}, attributes = raw.attributes or {}, classes = raw.classes or {}, + cells = raw.cells or {}, }, nil end @@ -2258,6 +2427,7 @@ function M.validate_arguments(args, argument_specs, options) end merged[name] = value + _check_keyword_faults(spec, path, context) if spec.required == true and value == nil then _report(context, 'error', path, 'required', 'is required but was not provided.') elseif value ~= nil then @@ -2309,11 +2479,13 @@ function M.validate_shortcode(name, args, kwargs, entry, options) local declared = type(entry.attributes) == 'table' local spellings + local defaulted = {} if declared then - local attributes, _, resolved = _validate_map(kwargs or {}, entry.attributes, name, context, { + local attributes, filled, resolved = _validate_map(kwargs or {}, entry.attributes, name, context, { unknown = options.unknown or 'warn', }) merged.attributes = attributes + defaulted = filled spellings = resolved end @@ -2337,10 +2509,13 @@ function M.validate_shortcode(name, args, kwargs, entry, options) -- That is the opposite of `dependentRequired` above, which asks what -- the author wrote and treats a default as an annotation nobody -- supplied. Neither reading is a bug: they answer different questions - -- about the same instance. + -- about the same instance. An object built from the defaults of its + -- properties is the exception, as it is for `required` on a descriptor: + -- the author still has to write the object. local function _required_satisfied(required) local field = (spellings and _lookup(spellings, required)) or required - if _lookup(merged.attributes, field) ~= nil then + local value, key = _lookup(merged.attributes, field) + if value ~= nil and defaulted[key] ~= 'built' then return true end if not declared then @@ -2388,6 +2563,48 @@ function M.validate_attributes(attributes, group, schema, options) return _finish(context, merged) end +--- Validate the comment-pipe options of one code cell against the `cells` +--- section. The language is matched case-insensitively, because Quarto treats +--- `{Typst}` and `{typst}` as the same cell language. Undeclared options are +--- ignored by default, because a cell legitimately carries options from Quarto +--- and from other filters. +--- @param options table Map of option values, as read from the comment-pipe lines +--- @param language string Cell language, such as 'typst' +--- @param schema table Loaded schema +--- @param opts table|nil {unknown = 'warn'|'error'|'ignore'} +--- @return boolean valid +--- @return table errors +--- @return table warnings +--- @return table merged +--- @return table findings +--- @usage local valid, errors, warnings, merged = M.validate_cells(cell_options, 'typst', schema) +function M.validate_cells(options, language, schema, opts) + opts = opts or {} + local entry + if schema and type(schema.cells) == 'table' and type(language) == 'string' then + entry = _lookup(schema.cells, language) + if entry == nil then + local wanted = language:lower() + for key, candidate in pairs(schema.cells) do + if type(key) == 'string' and key:lower() == wanted then + entry = candidate + break + end + end + end + end + + local context = _new_context() + if type(entry) ~= 'table' or type(entry.options) ~= 'table' then + return _finish(context, options or {}) + end + + local merged = _validate_map(options or {}, entry.options, language, context, { + unknown = opts.unknown or 'ignore', + }) + return _finish(context, merged) +end + --- Validate the options of one output format against the `formats` section. --- Quarto merges the options of the selected format into the top level of the --- metadata, so the values are read from there. The format name is never a key. @@ -2437,8 +2654,8 @@ function M.validate_format(meta, format, schema, options) if type(spec) == 'table' and type(spec.aliases) == 'table' then for _, alias in ipairs(spec.aliases) do -- A schema file is not read against the meta-schema, so an unquoted - -- `no` reaches here as a boolean. `_lookup` skips a key that is not a - -- string everywhere else, and so does this. + -- `true` or `1` reaches here as a boolean or a number. `_lookup` skips + -- a key that is not a string everywhere else, and so does this. if type(alias) == 'string' then local normalised = (alias:gsub('_', '-')) if not listed[normalised] then From 653ccc7a8d3a30b4e0e12022d0c55aa3dc19a06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:25:37 +0100 Subject: [PATCH 2/5] refactor: read the hot-fix defaults from the schema Schema 2.4.0 builds the hotfix object from the defaults of its properties, so a default changed in _schema.yml alone now takes effect. HOTFIX_DEFAULTS stays only as the fallback for a format the extension does not act on and for a schema that cannot be read. --- _extensions/code-window/code-window.lua | 17 +++++++--- tests/fixtures/hotfix-default.qmd | 15 +++++++++ tests/run.sh | 41 +++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/hotfix-default.qmd diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index 4b9eefc..b3e58d3 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -46,9 +46,7 @@ local ATTRIBUTE_PREFIX = 'code-window-' --- could not be read, which is a state this extension renders through rather --- than stopping for. Everywhere else _schema.yml decides these seven, so the --- values below are a fallback and not a second place to change one of them. ---- The hotfix defaults are a different story, and are still kept by hand in ---- HOTFIX_DEFAULTS: they are nested in the schema and read on their own path, ---- so changing one in _schema.yml alone still changes nothing. +--- HOTFIX_DEFAULTS, below, is the same kind of fallback for the hot-fixes. --- All seven stay listed, because the second case has nothing else to read --- from, and an option added to the schema needs an entry here as well or it --- has no default at all on a format the extension does not act on. @@ -74,6 +72,9 @@ local VALID_COLLAPSE = { ['open'] = 'open', } +--- Fallback defaults for the hot-fixes, for the same two cases as +--- FALLBACK_DEFAULTS. Everywhere else the schema builds the "hotfix" object +--- from the defaults of its properties, and that decides. local HOTFIX_DEFAULTS = { ['code-annotations'] = true, ['skylighting'] = true, @@ -924,8 +925,16 @@ function Meta(meta) -- Each hotfix value can be: -- boolean/string: true/false to enable/disable -- map: { enabled: true/false, quarto-version: "x.y.z" } + local schema_hotfix = schema_defaults['hotfix'] + if type(schema_hotfix) ~= 'table' then + schema_hotfix = {} + end local hotfix = {} - for key, default in pairs(HOTFIX_DEFAULTS) do + for key, fallback in pairs(HOTFIX_DEFAULTS) do + local default = schema_hotfix[key] + if type(default) ~= 'boolean' then + default = fallback + end local entry = hotfix_meta and hotfix_meta[key] if entry ~= nil and pandoc.utils.type(entry) == 'table' then -- Map form: { enabled: bool, quarto-version: "x.y.z" } diff --git a/tests/fixtures/hotfix-default.qmd b/tests/fixtures/hotfix-default.qmd new file mode 100644 index 0000000..d573928 --- /dev/null +++ b/tests/fixtures/hotfix-default.qmd @@ -0,0 +1,15 @@ +--- +title: "Hot-fix defaults read from the schema" +filters: + - code-window +format: + typst: + keep-typ: true +--- + +The document sets no hot-fix, so each one takes the default that the +extension's schema declares. + +```python +x = 1 +``` diff --git a/tests/run.sh b/tests/run.sh index 9cd4e54..4c2a4c5 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -373,6 +373,47 @@ else "a #code-window( call in wrapper-default.typ" fi +# ============================================================================ +# The hot-fix defaults come from the schema +# ============================================================================ + +# Each case is a project of its own, with its own copy of the extension, so a +# change to one schema reaches no other test. The document sets no hot-fix. +# $1 case name. +hotfix_project() { + local dir="${work_dir}/hotfix-$1" + mkdir -p "${dir}" + cp -R "${repo_dir}/_extensions" "${dir}/_extensions" + cp "${tests_dir}/fixtures/hotfix-default.qmd" "${dir}/" + printf 'project:\n type: default\n' >"${dir}/_quarto.yml" +} + +# With the skylighting default turned off in the schema alone, the render +# follows the schema and writes no Skylighting override. +hotfix_project schema-off +awk '/^ skylighting:$/ { found = 1 } found && /default: true/ { sub(/true/, "false"); found = 0 } { print }' \ + "${repo_dir}/_extensions/code-window/_schema.yml" \ + >"${work_dir}/hotfix-schema-off/_extensions/code-window/_schema.yml" +render hotfix-schema-off typst +if ! grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-schema-off/hotfix-default.typ"; then + report pass "hotfix-schema-off: a hot-fix default changed in the schema alone is followed" +else + report fail "hotfix-schema-off: a hot-fix default changed in the schema alone is followed" \ + "no Skylighting override in hotfix-schema-off/hotfix-default.typ" +fi + +# Without a schema to read, the extension falls back to its own defaults, so +# the hot-fix stays on. +hotfix_project schema-missing +rm "${work_dir}/hotfix-schema-missing/_extensions/code-window/_schema.yml" +render hotfix-schema-missing typst +if grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-schema-missing/hotfix-default.typ"; then + report pass "hotfix-schema-missing: the hot-fix defaults fall back without a schema" +else + report fail "hotfix-schema-missing: the hot-fix defaults fall back without a schema" \ + "a Skylighting override in hotfix-schema-missing/hotfix-default.typ" +fi + # ============================================================================ # A Typst template styles the window through the theme state # ============================================================================ From 75b1ec7b161ba7ce96e8f84cfc532f776b589803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:35:16 +0100 Subject: [PATCH 3/5] refactor: read a hot-fix default in the map form The schema types each hot-fix as a boolean or a map, so a map default is now read like the same map in the document rather than dropped. --- _extensions/code-window/code-window.lua | 76 ++++++++++++++----------- tests/run.sh | 14 +++++ 2 files changed, 58 insertions(+), 32 deletions(-) diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index b3e58d3..7428c79 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -72,9 +72,9 @@ local VALID_COLLAPSE = { ['open'] = 'open', } ---- Fallback defaults for the hot-fixes, for the same two cases as ---- FALLBACK_DEFAULTS. Everywhere else the schema builds the "hotfix" object ---- from the defaults of its properties, and that decides. +--- The hot-fixes the extension reads, with their fallback defaults for the +--- same two cases as FALLBACK_DEFAULTS. Everywhere else the schema builds the +--- "hotfix" object from the defaults of its properties, and its value decides. local HOTFIX_DEFAULTS = { ['code-annotations'] = true, ['skylighting'] = true, @@ -139,6 +139,39 @@ local function stringify_bool(value) return value end +--- Read one hot-fix value: a boolean, or a map with "enabled" and +--- "quarto-version" keys, where a version at or below the running Quarto +--- turns the hot-fix off. The value is document metadata or a schema +--- default, so it may be a Pandoc value or a plain Lua one. +--- @param entry any The hot-fix value +--- @return boolean enabled +local function read_hotfix(entry) + local function as_string(value) + if type(value) == 'boolean' then + return value and 'true' or 'false' + end + return pandoc.utils.stringify(value) + end + if type(entry) ~= 'table' or pandoc.utils.type(entry) == 'Inlines' then + return as_string(entry) == 'true' + end + local enabled = true + if entry['enabled'] ~= nil then + enabled = as_string(entry['enabled']) == 'true' + end + local ver = entry['quarto-version'] + if ver ~= nil then + ver = as_string(ver) + if ver ~= '' then + local ok, threshold = pcall(pandoc.types.Version, ver) + if ok and quarto.version >= threshold then + enabled = false + end + end + end + return enabled +end + --- Take the attributes an author can write off a block the filter processes, --- and answer the label the language module wrote. --- Pandoc writes an attribute nothing removes into the HTML as @@ -921,43 +954,22 @@ function Meta(meta) '"skylighting-fix" is deprecated. Use "hotfix: { skylighting: true/false }" instead.') end - -- Parse hotfix options with per-hotfix version-based auto-disable. - -- Each hotfix value can be: - -- boolean/string: true/false to enable/disable - -- map: { enabled: true/false, quarto-version: "x.y.z" } + -- Each hot-fix is on or off, and the schema default comes in the same two + -- forms as a document value, so both go through read_hotfix. local schema_hotfix = schema_defaults['hotfix'] if type(schema_hotfix) ~= 'table' then schema_hotfix = {} end local hotfix = {} for key, fallback in pairs(HOTFIX_DEFAULTS) do - local default = schema_hotfix[key] - if type(default) ~= 'boolean' then - default = fallback - end local entry = hotfix_meta and hotfix_meta[key] - if entry ~= nil and pandoc.utils.type(entry) == 'table' then - -- Map form: { enabled: bool, quarto-version: "x.y.z" } - local enabled = true - if entry['enabled'] ~= nil then - enabled = pandoc.utils.stringify(entry['enabled']) == 'true' - end - local ver = entry['quarto-version'] - if ver then - ver = pandoc.utils.stringify(ver) - if ver ~= '' then - local ok, threshold = pcall(pandoc.types.Version, ver) - if ok and quarto.version >= threshold then - enabled = false - end - end - end - hotfix[key] = enabled - elseif entry ~= nil then - -- Simple boolean/string form - hotfix[key] = pandoc.utils.stringify(entry) == 'true' + if entry == nil then + entry = schema_hotfix[key] + end + if entry == nil then + hotfix[key] = fallback else - hotfix[key] = default + hotfix[key] = read_hotfix(entry) end end diff --git a/tests/run.sh b/tests/run.sh index 4c2a4c5..cea690a 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -402,6 +402,20 @@ else "no Skylighting override in hotfix-schema-off/hotfix-default.typ" fi +# The schema may also give a hot-fix default in the map form, which is read +# like the same map written in the document. +hotfix_project schema-map +awk '/^ skylighting:$/ { found = 1 } found && /default: true/ { sub(/true/, "{enabled: false}"); found = 0 } { print }' \ + "${repo_dir}/_extensions/code-window/_schema.yml" \ + >"${work_dir}/hotfix-schema-map/_extensions/code-window/_schema.yml" +render hotfix-schema-map typst +if ! grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-schema-map/hotfix-default.typ"; then + report pass "hotfix-schema-map: a hot-fix default in the map form is followed" +else + report fail "hotfix-schema-map: a hot-fix default in the map form is followed" \ + "no Skylighting override in hotfix-schema-map/hotfix-default.typ" +fi + # Without a schema to read, the extension falls back to its own defaults, so # the hot-fix stays on. hotfix_project schema-missing From f2f19f7b642da06f1561124d65862117447075db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:46:39 +0100 Subject: [PATCH 4/5] fix: read only a metadata map as a hot-fix map --- _extensions/code-window/code-window.lua | 2 +- tests/run.sh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/_extensions/code-window/code-window.lua b/_extensions/code-window/code-window.lua index 7428c79..0106399 100644 --- a/_extensions/code-window/code-window.lua +++ b/_extensions/code-window/code-window.lua @@ -152,7 +152,7 @@ local function read_hotfix(entry) end return pandoc.utils.stringify(value) end - if type(entry) ~= 'table' or pandoc.utils.type(entry) == 'Inlines' then + if pandoc.utils.type(entry) ~= 'table' then return as_string(entry) == 'true' end local enabled = true diff --git a/tests/run.sh b/tests/run.sh index cea690a..2d5691e 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -416,6 +416,22 @@ else "no Skylighting override in hotfix-schema-map/hotfix-default.typ" fi +# A value that is neither a boolean nor a map, such as a list, is read as +# text, so a list holding false turns the hot-fix off as before. +sed 's/^ keep-typ: true$/ keep-typ: true\ +extensions:\ + code-window:\ + hotfix:\ + skylighting: [false]/' \ + "${work_dir}/hotfix-default.qmd" >"${work_dir}/hotfix-list.qmd" +render hotfix-list typst +if ! grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-list.typ"; then + report pass "hotfix-list: a list value is read as text, not as a map" +else + report fail "hotfix-list: a list value is read as text, not as a map" \ + "no Skylighting override in hotfix-list.typ" +fi + # Without a schema to read, the extension falls back to its own defaults, so # the hot-fix stays on. hotfix_project schema-missing From 0e89b4044bac22978b62b43b11b17f096f5ac7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Mon, 23 Nov 2026 12:55:17 +0100 Subject: [PATCH 5/5] test: pin the hot-fix quarto-version threshold --- tests/run.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/run.sh b/tests/run.sh index 2d5691e..95886e0 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -432,6 +432,27 @@ else "no Skylighting override in hotfix-list.typ" fi +# A map with a quarto-version turns the hot-fix off from that version on. The +# first case names a version every Quarto has reached, the second one that no +# Quarto has, so the hot-fix is off and on in turn. +for threshold in 0.0.1 9999.0.0; do + sed 's/^ keep-typ: true$/ keep-typ: true\ +extensions:\ + code-window:\ + hotfix:\ + skylighting:\ + quarto-version: "'"${threshold}"'"/' \ + "${work_dir}/hotfix-default.qmd" >"${work_dir}/hotfix-version-${threshold}.qmd" + render "hotfix-version-${threshold}" typst +done +if ! grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-version-0.0.1.typ" && + grep -q '// skylighting-typst-fix override' "${work_dir}/hotfix-version-9999.0.0.typ"; then + report pass "hotfix-version: the hot-fix is off from its quarto-version on" +else + report fail "hotfix-version: the hot-fix is off from its quarto-version on" \ + "no Skylighting override with 0.0.1, and one with 9999.0.0" +fi + # Without a schema to read, the extension falls back to its own defaults, so # the hot-fix stays on. hotfix_project schema-missing