Skip to content

Conversation

@vezwork
Copy link
Collaborator

@vezwork vezwork commented Nov 25, 2025

This is an experiment to see if we can use a WASM build of quarto-markdown to parse qmd source when loading the Visual Editor.

We were able to! There is still much more testing to be done once we have a more feature-complete quarto-markdown.

When reading the "Files changed" in this PR, please ignore the files in [‎apps/vscode-editor/src/wasm-qmd-parser/](https://github.com/quarto-dev/quarto/pull/871/files#diff-9066ed64f17eccb6ac009ae7293d2468718eeb3624b2daddfdfdcd2b7a0585ea), they are all copy&pasted from the WASM build of quarto-markdown. They would be imported somehow in the future.

@vezwork vezwork changed the title Experimental: wasm qmd parser Experimental: wasm qmd parser for VE loading Nov 25, 2025
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${nonce}'; style-src ${webview.cspSource} 'unsafe-inline'; img-src https: data: ${webview.cspSource}; font-src data: ${webview.cspSource};">
<meta http-equiv="Content-Security-Policy" content="
default-src 'none';
script-src 'nonce-${nonce}' 'unsafe-eval';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to add 'unsafe-eval' to Content-Security-Policy to be able to execute WASM in the client/Visual-Editor.

Comment on lines +97 to +98
const me = this
main().then(result => { me.m = result })
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for this code, it loads the parser wasm and then sets it as the m property on the PandocConverter class.

Comment on lines +140 to +144
const wasmProducedASTString = this.m?.parse_qmd(markdown);
const wasmProducedAST = JSON.parse(wasmProducedASTString)

console.log(JSON.stringify(ast))
console.log(JSON.stringify(wasmProducedAST))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the heart of where the qmd source is parsed, right before being turned into the prosemirror document that is the Visual Editor.

I tested some simple documents and we are able to parse them and convert them to prosemirror without using pandoc!

We have to be quite careful though, there has been a ton of pre and post processing being done to the pandoc AST previously. It is unclear if those are all hacks to fix issues with how the source is parsed, or if some of them add genuine functionality to the parse that qmd-parser wouldn't be doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants