diff --git a/CHANGELOG.md b/CHANGELOG.md index efe2b0a..24ee76d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Bug Fixes + +- fix: Use the first class that Pandoc can highlight as the language of a block, so `{.terminal .bash}` is labelled and highlighted as `bash`. Line-numbering classes such as `numberLines` are no longer taken for a language. (#84) + ## 1.8.0 (2026-11-04) ### New Features diff --git a/_extensions/code-window/_modules/language.lua b/_extensions/code-window/_modules/language.lua index d4763a7..20f09e4 100644 --- a/_extensions/code-window/_modules/language.lua +++ b/_extensions/code-window/_modules/language.lua @@ -2,7 +2,7 @@ --- @license MIT --- @copyright 2026 Mickaël Canouil --- @author Mickaël Canouil ---- @brief Normalise code blocks with no or unknown language class. +--- @brief Put the language class of a code block first, or add one. local cell_output = require( quarto.utils.resolve_path('_modules/cell-output.lua'):gsub('%.lua$', '')) @@ -13,12 +13,16 @@ local M = {} local known_language_cache = {} +--- Classes that turn on line numbers in Pandoc. They are not languages. +local NUMBERING_CLASSES = { ['numberLines'] = true, ['number-lines'] = true, ['number'] = true } + --- Check if a language is recognised by Pandoc's syntax highlighter. ---- Renders a test CodeBlock to HTML and checks for the sourceCode class. +--- Renders a test CodeBlock to HTML and checks that Pandoc names a language +--- on the code element, not only the sourceCode class. --- @param lang string Language identifier --- @return boolean local function is_known_language(lang) - if not lang or lang == '' then + if not lang or lang == '' or NUMBERING_CLASSES[lang] then return false end @@ -28,7 +32,7 @@ local function is_known_language(lang) local test_block = pandoc.CodeBlock('x', pandoc.Attr('', { lang })) local html = pandoc.write(pandoc.Pandoc({ test_block }), 'html') - local is_known = html:find('sourceCode') ~= nil + local is_known = html:find('