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
5 changes: 5 additions & 0 deletions news/changelog-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

- Add Slovak translation (thanks @tom67)
- Improve Italian translation of 'proof' (thanks @espinielli)

## Docusaurus Format

- Support for `code-line-numbers` in Docusaurus output ([#5152](https://github.com/quarto-dev/quarto-cli/issues/5152))

27 changes: 0 additions & 27 deletions src/resources/extensions/quarto/docusaurus/docusaurus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

local kQuartoRawHtml = "quartoRawHtml"
local rawHtmlVars = pandoc.List()
local reactPreamble = pandoc.List()

function Pandoc(doc)
-- insert exports at the top if we have them
Expand All @@ -17,12 +16,6 @@ function Pandoc(doc)
doc.blocks:insert(1, pandoc.RawBlock("markdown", exports .. "\n"))
end

-- insert react preamble if we have it
if #reactPreamble > 0 then
local preamble = table.concat(reactPreamble, "\n")
doc.blocks:insert(1, pandoc.RawBlock("markdown", preamble .. "\n"))
end

return doc
end

Expand Down Expand Up @@ -59,23 +52,3 @@ function RawBlock(el)
end
end



-- transform pandoc "title" to docusaures title. for code blocks
-- with no class, give them one so that they aren't plain 4 space indented
function CodeBlock(el)
local lang = el.attr.classes[1]
local title = el.attr.attributes["filename"] or el.attr.attributes["title"]
if lang and title then
-- docusaures code block attributes don't conform to any syntax
-- that pandoc natively understands, so return the CodeBlock as
-- "raw" markdown (so it bypasses pandoc processing entirely)
return pandoc.RawBlock("markdown",
"\n```" .. lang .. " title=\"" .. title .. "\"\n" ..
el.text .. "\n```\n"
)
elseif #el.attr.classes == 0 then
el.attr.classes:insert('text')
return el
end
end
59 changes: 32 additions & 27 deletions src/resources/extensions/quarto/docusaurus/docusaurus_writer.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
local kQuartoRawHtml = "quartoRawHtml"
local rawHtmlVars = pandoc.List()
local reactPreamble = pandoc.List()

local function addPreamble(preamble)
Expand Down Expand Up @@ -44,25 +42,43 @@ local function tabset(node, filter)
return tabs
end

local codeBlock = function(el, filename)
local title = filename or el.attr.attributes["filename"] or el.attr.attributes["title"]
local showLineNumbers = el.attr.classes:includes('number-lines')
if lang or title or showLineNumbers then
if not lang then
lang = 'text'
end
local code = "\n```" .. lang
if showLineNumbers then
code = code .. " showLineNumbers"
end
if title then
code = code .. " title=\"" .. title .. "\""
end
code = code .. "\n" .. el.text .. "\n```\n"

-- docusaures code block attributes don't conform to any syntax
-- that pandoc natively understands, so return the CodeBlock as
-- "raw" markdown (so it bypasses pandoc processing entirely)
return pandoc.RawBlock("markdown", code)

elseif #el.attr.classes == 0 then
el.attr.classes:insert('text')
return el
end

return nil
end

function Writer(doc, opts)
local filter
filter = {
CodeBlock = codeBlock,

DecoratedCodeBlock = function(node)
local el = node.code_block
local lang = el.attr.classes[1]
local title = node.filename or el.attr.attributes["filename"] or el.attr.attributes["title"]

if lang and title then
return pandoc.RawBlock("markdown",
"\n```" .. lang .. " title=\"" .. title .. "\"\n" ..
el.text .. "\n```\n"
)
elseif #el.attr.classes == 0 then
el.attr.classes:insert('text')
return el
end

return nil
return codeBlock(el, node.filename)
end,

Tabset = function(node)
Expand All @@ -83,17 +99,6 @@ function Writer(doc, opts)

doc = quarto._quarto.ast.walk(doc, filter)

-- insert exports at the top if we have them
if #rawHtmlVars > 0 then
local exports = ("export const %s =\n[%s];"):format(kQuartoRawHtml,
table.concat(
rawHtmlVars:map(function(var) return '`'.. var .. '`' end),
","
)
)
doc.blocks:insert(1, pandoc.RawBlock("markdown", exports .. "\n"))
end

-- insert react preamble if we have it
if #reactPreamble > 0 then
local preamble = table.concat(reactPreamble, "\n")
Expand Down