Skip to content

Commit a4cbe8d

Browse files
committed
Successful VE load with wasm parser!
1 parent d3202fa commit a4cbe8d

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

apps/vscode-editor/src/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import { editorThemeFromStore } from "./theme";
2929
import "editor-ui/src/styles";
3030
import "./styles.scss"
3131

32-
import main from "./wasm-qmd-parser/";
33-
3432
async function runEditor() {
3533
try {
3634
// init localization
@@ -56,10 +54,7 @@ async function runEditor() {
5654
setEditorTheme(editorThemeFromStore(store));
5755
root.render(<App store={store} editorId={editorId} host={host} context={context} request={request}/>);
5856

59-
console.log('hello!!!')
60-
let m = await main();
61-
let parsed = m.parse_qmd("# Hello\n");
62-
console.log('parsed', parsed);
57+
6358
} catch (error) {
6459
console.error('error',error);
6560
}

packages/editor/src/pandoc/pandoc_converter.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { pandocFromProsemirror } from './pandoc_from_prosemirror';
4444
import { isParagraphNode } from '../api/paragraph';
4545
import { PandocFormat, PandocWriterOptions } from '../api/pandoc-types';
4646
import { escapeRegExpCharacters, lines, normalizeNewlines } from 'core';
47+
import main from "../../../../apps/vscode-editor/src/wasm-qmd-parser";
4748

4849
export type PandocLineWrapping = 'none' | 'column' | 'sentence';
4950

@@ -69,6 +70,7 @@ export class PandocConverter {
6970
private readonly markdownPostProcessors: readonly PandocMarkdownPostProcessorFn[];
7071
private readonly pandoc: PandocServer;
7172
private readonly pandocCapabilities: PandocCapabilities;
73+
private m: any;
7274

7375
constructor(
7476
schema: Schema,
@@ -91,6 +93,9 @@ export class PandocConverter {
9193

9294
this.pandoc = pandoc;
9395
this.pandocCapabilities = pandocCapabilities;
96+
97+
const me = this
98+
main().then(result => { me.m = result })
9499
}
95100

96101
public async toProsemirror(markdown: string, format: PandocFormat): Promise<PandocToProsemirrorResult> {
@@ -104,20 +109,20 @@ export class PandocConverter {
104109
// that's how preprocessors hoist content through pandoc into our prosemirror token parser.
105110
// we always need to read with auto_identifiers so we can catch any auto-generated ids
106111
// required to fulfill links inside the document (we will strip out heading ids that
107-
// aren't explicit or a link target using the heading_ids returned with the ast).
112+
// aren't explicit or a link target using the heading_ids returned with the ast).
108113
//
109114
// we always read all forms of tables (since they can always be written back out as raw_html)
110115
//
111116
// we also always read math (since it can always be output as 'asciimath')
112-
117+
113118
// determine type of auto_ids
114119
const autoIds = format.extensions.gfm_auto_identifiers ? 'gfm_auto_identifiers' : 'auto_identifiers';
115120
const targetFormat = adjustedFormat(
116121
format.fullName,
117-
['raw_html', 'raw_attribute', 'backtick_code_blocks', autoIds,
118-
'grid_tables', 'pipe_tables', 'multiline_tables', 'simple_tables',
119-
'tex_math_dollars'],
120-
['smart'],
122+
['raw_html', 'raw_attribute', 'backtick_code_blocks', autoIds,
123+
'grid_tables', 'pipe_tables', 'multiline_tables', 'simple_tables',
124+
'tex_math_dollars'],
125+
['smart'],
121126
);
122127

123128
// run preprocessors
@@ -131,8 +136,15 @@ export class PandocConverter {
131136
});
132137

133138
const ast = await this.pandoc.markdownToAst(markdown, targetFormat, []);
139+
140+
const wasmProducedASTString = this.m?.parse_qmd(markdown);
141+
const wasmProducedAST = JSON.parse(wasmProducedASTString)
142+
143+
console.log(JSON.stringify(ast))
144+
console.log(JSON.stringify(wasmProducedAST))
145+
134146
const result = pandocToProsemirror(
135-
ast,
147+
wasmProducedAST,
136148
this.schema,
137149
format.extensions,
138150
this.readers,
@@ -274,8 +286,8 @@ function disabledFormatOptions(format: string, pandocFormat: PandocFormat, doc:
274286

275287
// if there are tables with inline R code then disable grid tables (as the inline
276288
// R code will mess up the column boundaries)
277-
if (haveTableCellsWithInlineRcode(doc) ||
278-
(!gridTablesRequired(doc) && pandocFormat.extensions.pipe_tables)) {
289+
if (haveTableCellsWithInlineRcode(doc) ||
290+
(!gridTablesRequired(doc) && pandocFormat.extensions.pipe_tables)) {
279291
disabledTableTypes += '-grid_tables';
280292
}
281293

@@ -309,7 +321,7 @@ function gridTablesRequired(doc: ProsemirrorNode) {
309321
// paragraph with hard break
310322
const paraNode = cell.node.firstChild!;
311323
return findChildren(paraNode, node => node.type === schema.nodes.hard_break).length > 0;
312-
});
324+
});
313325
}
314326

315327
function wrapOptions(options: PandocWriterOptions) {

0 commit comments

Comments
 (0)