Skip to content

Commit

Permalink
Merge branch 'bugfix/8919'
Browse files Browse the repository at this point in the history
  • Loading branch information
cscheid committed Feb 28, 2024
2 parents 61640f0 + 87c6259 commit 47b869c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 5 additions & 0 deletions news/changelog-1.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ All changes included in 1.5:

- ([#8382](https://github.com/quarto-dev/quarto-cli/issues/8382)): Strip whitespace from `div.columns` elements that might have been introduced by third-party processing.

## Docusaurus Format

- ([#8919](https://github.com/quarto-dev/quarto-cli/issues/8919)): Ensure enough backticks in code cell declarations.

## Website

- ([#6779](https://github.com/quarto-dev/quarto-cli/issues/6779)): Add support for `logo-href` and `logo-alt` in `sidebar` (books and websites)
Expand Down Expand Up @@ -51,6 +55,7 @@ All changes included in 1.5:
- ([#8433](https://github.com/quarto-dev/quarto-cli/issues/8433)): Escape jupyter widget states that contain `</script>` so they can be embedded in HTML documents.
- When searching for kernelspecs that match `python`, prefer one one that matches an active Python venv.
- ([#8454](https://github.com/quarto-dev/quarto-cli/issues/8454)): Allow Jupyter engine to handle markdown files with mixed-case extensions.
- ([#8919](https://github.com/quarto-dev/quarto-cli/issues/8919)): Ensure enough backticks in `quarto convert` from `.ipynb` to `.qmd` files.

## Website Listings

Expand Down
10 changes: 8 additions & 2 deletions src/command/convert/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ async function mdFromCodeCell(
return [];
}

// determine the largest number of backticks in the cell
const maxBackticks = Math.max(
...cell.source.map((line) => line.match(/^`+/g)?.[0].length || 0),
);
const backticks = "`".repeat(maxBackticks + 1);

// begin code cell
const md: string[] = ["```{" + language + "}\n"];
const md: string[] = [backticks + "{" + language + "}\n"];

// partition
const { yaml, source } = await partitionCellOptions(language, cell.source);
Expand Down Expand Up @@ -215,7 +221,7 @@ async function mdFromCodeCell(
md.push(...mdEnsureTrailingNewline(source));

// end code cell
md.push("```\n");
md.push(backticks + "\n");

return md;
}
13 changes: 11 additions & 2 deletions src/resources/extensions/quarto/docusaurus/docusaurus_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ function render_folded_block(block)
end
end

local function max_backticks(el)
local v = 0
for w in el.text:gmatch("`+") do
v = math.max(v, #w)
end
return v
end

function code_block(code_block_slot, filename)
function process(el)
local lang = el.attr.classes[1]
Expand All @@ -68,7 +76,8 @@ function code_block(code_block_slot, filename)
if not lang then
lang = 'text'
end
local code = "\n```" .. lang
local backticks = string.rep("`", math.max(3, max_backticks(el) + 1))
local code = "\n" .. backticks .. lang
if codeLineNumbers then
code = code .. " {" .. codeLineNumbers .. "}"
end
Expand All @@ -78,7 +87,7 @@ function code_block(code_block_slot, filename)
if title then
code = code .. " title=\"" .. title .. "\""
end
code = code .. "\n" .. el.text .. "\n```\n"
code = code .. "\n" .. el.text .. "\n" .. backticks .. "\n"

-- docusaures code block attributes don't conform to any syntax
-- that pandoc natively understands, so return the CodeBlock as
Expand Down
18 changes: 18 additions & 0 deletions tests/docs/smoke-all/2024/02/28/8919-a.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
jupyter: python3
_quarto:
tests:
docusaurus-md:
ensureFileRegexMatches:
- ["````"]
---

````{python}
message = """
Content
```python
print("Hello, world!")
```
"""
````

0 comments on commit 47b869c

Please sign in to comment.