Skip to content

Commit 75359e3

Browse files
authored
Merge pull request #553 from quarto-dev/fix-raw-html-blocks
use custom pandoc writer to preserve raw html blocks
2 parents 49abc46 + d0cb384 commit 75359e3

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

apps/vscode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.116.0 (Not yet released)
4+
5+
- Fix issue with raw html blocks being removed from document by Visual Editor (<https://github.com/quarto-dev/quarto/issues/552>)
6+
37
## 1.115.0 (Release on 20 September 2024)
48

59
- Suppress background highlight on first line (<https://github.com/quarto-dev/quarto/pull/537>).

apps/vscode/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"pandoc",
1212
"quarto"
1313
],
14-
"version": "1.115.0",
14+
"version": "1.116.0",
1515
"repository": {
1616
"type": "git",
1717
"url": "https://github.com/quarto-dev/quarto/tree/main/apps/vscode"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---@diagnostic disable: undefined-global
2+
---
3+
--- Writer for markdown that preserves raw html attributes.
4+
---
5+
--- This changed in pandoc 3.2, see https://github.com/rstudio/rstudio/issues/15189.
6+
7+
local html_formats = pandoc.List{'html', 'html4', 'html5'}
8+
function Writer (doc, opts)
9+
if opts.extensions:includes 'raw_attribute' then
10+
doc = doc:walk{
11+
RawBlock = function (raw)
12+
if html_formats:includes(raw.format) then
13+
local md = pandoc.write(pandoc.Pandoc(raw), 'markdown-raw_html')
14+
return pandoc.RawBlock('markdown', md)
15+
end
16+
end
17+
}
18+
end
19+
return pandoc.write(doc, {format = 'markdown', extensions = opts.extensions}, opts)
20+
end
21+
22+
Extensions = pandoc.format.extensions 'markdown'
23+
Template = pandoc.template.default 'markdown'

packages/editor-server/src/server/pandoc.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ import { EditorServerOptions } from './server';
5555

5656
export function pandocServer(options: EditorServerOptions) : PandocServer {
5757

58+
// work around change in pandoc 3.2+: https://github.com/jgm/pandoc/issues/9677 by
59+
// using a custom pandoc writer
60+
function substituteCustomMarkdownWriter(format: string): string {
61+
const customWriterScript = path.join(options.pandoc.resourcesDir, 'md-writer.lua')
62+
return format.replace(/^markdown(?=[-+]|$)/, customWriterScript);
63+
}
64+
5865
async function runPandoc(args: readonly string[] | null, stdin?: string) : Promise<string> {
5966
return pandoc(options.pandoc, args, stdin);
6067
}
@@ -100,9 +107,9 @@ export function pandocServer(options: EditorServerOptions) : PandocServer {
100107
return ast;
101108
},
102109
async astToMarkdown(ast: PandocAst, format: string, options: string[]): Promise<string> {
103-
const markdown = await runPandoc(
110+
const markdown = await runPandoc(
104111
["--from", "json",
105-
"--to", format, ...options],
112+
"--to", substituteCustomMarkdownWriter(format), ...options],
106113
JSON.stringify(ast)
107114
);
108115
return markdown;

0 commit comments

Comments
 (0)