Skip to content

Commit 98e4947

Browse files
authored
Bugfix/wasm json source (#108)
* wasm json source * wasm json source
1 parent ab38c50 commit 98e4947

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

crates/quarto-markdown-pandoc/src/wasm_entry_points/mod.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
use crate::readers;
77
use crate::utils::output::VerboseOutput;
8+
use crate::writers::json::JsonConfig;
89
use std::io;
910

1011
fn pandoc_to_json(
1112
doc: &crate::pandoc::Pandoc,
1213
context: &crate::pandoc::ast_context::ASTContext,
14+
include_resolved_locations: bool,
1315
) -> Result<String, String> {
1416
let mut buf = Vec::new();
15-
match crate::writers::json::write(doc, context, &mut buf) {
17+
let config = JsonConfig {
18+
include_inline_locations: include_resolved_locations,
19+
};
20+
match crate::writers::json::write_with_config(doc, context, &mut buf, &config) {
1621
Ok(_) => {
1722
// Nothing to do
1823
}
@@ -49,7 +54,7 @@ pub fn qmd_to_pandoc(
4954
}
5055
}
5156

52-
pub fn parse_qmd(input: &[u8]) -> String {
57+
pub fn parse_qmd(input: &[u8], include_resolved_locations: bool) -> String {
5358
let (pandoc, context) = qmd_to_pandoc(input).unwrap();
54-
pandoc_to_json(&pandoc, &context).unwrap()
59+
pandoc_to_json(&pandoc, &context, include_resolved_locations).unwrap()
5560
}

crates/quarto-markdown-pandoc/tests/test_wasm_entrypoints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#[test]
77
fn test_wasm_read_entrypoint() {
88
let input = "# hello _world_.\n";
9-
let result = quarto_markdown_pandoc::wasm_entry_points::parse_qmd(input.as_bytes());
9+
let result = quarto_markdown_pandoc::wasm_entry_points::parse_qmd(input.as_bytes(), true);
1010
eprintln!("result: {}", result);
1111
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ fn pandoc_to_qmd(doc: &quarto_markdown_pandoc::pandoc::Pandoc) -> Result<String,
8383
}
8484

8585
#[wasm_bindgen]
86-
pub fn parse_qmd(input: JsValue) -> JsValue {
86+
pub fn parse_qmd(input: JsValue, include_resolved_locations: JsValue) -> JsValue {
8787
let input = as_string(&input, "input");
88-
let json = wasm_entry_points::parse_qmd(input.as_bytes());
88+
let include_resolved_locations = as_string(&include_resolved_locations, "input") == "true";
89+
let json = wasm_entry_points::parse_qmd(input.as_bytes(), include_resolved_locations);
8990
JsValue::from_str(&json)
9091
}
9192

0 commit comments

Comments
 (0)