Skip to content

Commit ce933f9

Browse files
committed
fix crate cf JSON schema and parsing change
1 parent 2879cb4 commit ce933f9

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

crates/wasm-qmd-parser/build.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
```shell
3+
cd crates/wasm-qmd-parser
4+
# To work around this error, because Apple Clang doesn't work with wasm32-unknown-unknown?
5+
# I believe this is not required on a Linux machine.
6+
# Requires `brew install llvm`.
7+
# https://github.com/briansmith/ring/issues/1824
8+
# error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'
9+
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
10+
# To tell rustc to include our C shims located in `wasm-sysroot`, which we eventually compile into the project
11+
# with `c_shim.rs`.
12+
# https://github.com/tree-sitter/tree-sitter/discussions/1550#discussioncomment-8445285
13+
#
14+
# It also seems like we need to define HAVE_ENDIAN_H to tell tree-sitter we have `endian.h`
15+
# as it doesn't seem to pick up on that automatically?
16+
# https://github.com/tree-sitter/tree-sitter/blob/0be215e152d58351d2691484b4398ceff041f2fb/lib/src/portable/endian.h#L18
17+
export CFLAGS_wasm32_unknown_unknown="-I$(pwd)/wasm-sysroot -Wbad-function-cast -Wcast-function-type -fno-builtin -DHAVE_ENDIAN_H"
18+
# To just build the wasm-qmd-parser crate
19+
# cargo build --target wasm32-unknown-unknown
20+
# To build the wasm-pack bundle
21+
# Note that you'll need `opt-level = "s"` in your `profile.dev` cargo profile
22+
# otherwise you can get a "too many locals" error.
23+
wasm-pack build --target web --dev
24+
```

crates/wasm-qmd-parser/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ pub fn run() {
3030
panic::set_hook(Box::new(console_error_panic_hook::hook));
3131
}
3232

33-
fn json_to_pandoc(input: &str) -> Result<quarto_markdown_pandoc::pandoc::Pandoc, String> {
33+
fn json_to_pandoc(input: &str) -> Result<(quarto_markdown_pandoc::pandoc::Pandoc, quarto_markdown_pandoc::pandoc::ASTContext), String> {
3434
match readers::json::read(&mut input.as_bytes()) {
3535
Ok(doc) => Ok(doc),
3636
Err(err) => Err(format!("Unable to read as json: {:?}", err)),
3737
}
3838
}
3939

40-
fn pandoc_to_json(doc: &quarto_markdown_pandoc::pandoc::Pandoc) -> Result<String, String> {
40+
fn pandoc_to_json(doc: &quarto_markdown_pandoc::pandoc::Pandoc, context: &quarto_markdown_pandoc::pandoc::ASTContext) -> Result<String, String> {
4141
let mut buf = Vec::new();
42-
match writers::json::write(doc, &mut buf) {
42+
match writers::json::write(doc, context, &mut buf) {
4343
Ok(_) => {
4444
// Nothing to do
4545
}
@@ -81,9 +81,9 @@ pub fn parse_qmd(input: JsValue) -> JsValue {
8181
#[wasm_bindgen]
8282
pub fn write_qmd(input: JsValue) -> JsValue {
8383
let input = as_string(&input, "input");
84-
let result = json_to_pandoc(&input).unwrap();
84+
let (result, context) = json_to_pandoc(&input).unwrap();
8585

86-
let json = pandoc_to_json(&result).unwrap();
86+
let json = pandoc_to_json(&result, &context).unwrap();
8787
JsValue::from_str(&json)
8888
}
8989

@@ -92,14 +92,14 @@ pub fn convert(document: JsValue, input_format: JsValue, output_format: JsValue)
9292
let input = as_string(&document, "document");
9393
let input_format = as_string(&input_format, "input_format");
9494
let output_format = as_string(&output_format, "output_format");
95-
let doc = match input_format.as_str() {
95+
let (doc, context) = match input_format.as_str() {
9696
"qmd" => wasm_entry_points::qmd_to_pandoc(&input.as_bytes()).unwrap(),
9797
"json" => json_to_pandoc(&input).unwrap(),
9898
_ => panic!("Unsupported input format: {}", input_format),
9999
};
100100
let output = match output_format.as_str() {
101101
"qmd" => pandoc_to_qmd(&doc).unwrap(),
102-
"json" => pandoc_to_json(&doc).unwrap(),
102+
"json" => pandoc_to_json(&doc, &context).unwrap(),
103103
_ => panic!("Unsupported output format: {}", output_format),
104104
};
105105
JsValue::from_str(&output)

0 commit comments

Comments
 (0)