Skip to content

Commit

Permalink
Merge pull request #9328 from quarto-dev/bugfix/9179
Browse files Browse the repository at this point in the history
Docusaurus - use RawBlock for tables that would be emitted as HTML
  • Loading branch information
cscheid committed Apr 10, 2024
2 parents bb8fbf6 + 4788b53 commit 5f5ce54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All changes included in 1.5:
## Docusaurus Format

- ([#8919](https://github.com/quarto-dev/quarto-cli/issues/8919)): Ensure enough backticks in code cell declarations.
- ([#9179](https://github.com/quarto-dev/quarto-cli/issues/9179)): Emit tables that Pandoc would write as HTML as RawBlock elements to ensure they are rendered correctly in Docusaurus.

## Website

Expand Down
10 changes: 10 additions & 0 deletions src/resources/extensions/quarto/docusaurus/docusaurus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ local function tabset(node)
return tabs
end

local function Table(tbl)
local out = pandoc.write(pandoc.Pandoc({tbl}), FORMAT, PANDOC_WRITER_OPTIONS)
-- if the table was written in a way that looks like HTML, then wrap it in the right RawBlock way
if string.match(out, "^%s*%<table") then
local unwrapped = pandoc.RawBlock('html', out)
return RawBlock(unwrapped)
end
end

quarto._quarto.ast.add_renderer("Tabset", function()
return quarto._quarto.format.isDocusaurusOutput()
end, function(node)
Expand Down Expand Up @@ -178,6 +187,7 @@ return {
RawBlock = RawBlock,
DecoratedCodeBlock = DecoratedCodeBlock,
CodeBlock = CodeBlock,
Table = Table,
},
{
Pandoc = Pandoc,
Expand Down
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/2024/04/10/9179.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Broken Tables
_quarto:
tests:
docusaurus-md:
ensureFileRegexMatches:
- ["dangerouslySetInnerHTML"]
---

# Broken Markdown Tables

+-------+
| # ad |
+-------+

0 comments on commit 5f5ce54

Please sign in to comment.