Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/quarto-markdown-pandoc/src/wasm_entry_points/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

use crate::readers;
use crate::utils::output::VerboseOutput;
use crate::writers::json::JsonConfig;
use std::io;

fn pandoc_to_json(
doc: &crate::pandoc::Pandoc,
context: &crate::pandoc::ast_context::ASTContext,
include_resolved_locations: bool,
) -> Result<String, String> {
let mut buf = Vec::new();
match crate::writers::json::write(doc, context, &mut buf) {
let config = JsonConfig {
include_inline_locations: include_resolved_locations,
};
match crate::writers::json::write_with_config(doc, context, &mut buf, &config) {
Ok(_) => {
// Nothing to do
}
Expand Down Expand Up @@ -49,7 +54,7 @@ pub fn qmd_to_pandoc(
}
}

pub fn parse_qmd(input: &[u8]) -> String {
pub fn parse_qmd(input: &[u8], include_resolved_locations: bool) -> String {
let (pandoc, context) = qmd_to_pandoc(input).unwrap();
pandoc_to_json(&pandoc, &context).unwrap()
pandoc_to_json(&pandoc, &context, include_resolved_locations).unwrap()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#[test]
fn test_wasm_read_entrypoint() {
let input = "# hello _world_.\n";
let result = quarto_markdown_pandoc::wasm_entry_points::parse_qmd(input.as_bytes());
let result = quarto_markdown_pandoc::wasm_entry_points::parse_qmd(input.as_bytes(), true);
eprintln!("result: {}", result);
}
5 changes: 3 additions & 2 deletions crates/wasm-qmd-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ fn pandoc_to_qmd(doc: &quarto_markdown_pandoc::pandoc::Pandoc) -> Result<String,
}

#[wasm_bindgen]
pub fn parse_qmd(input: JsValue) -> JsValue {
pub fn parse_qmd(input: JsValue, include_resolved_locations: JsValue) -> JsValue {
let input = as_string(&input, "input");
let json = wasm_entry_points::parse_qmd(input.as_bytes());
let include_resolved_locations = as_string(&include_resolved_locations, "input") == "true";
let json = wasm_entry_points::parse_qmd(input.as_bytes(), include_resolved_locations);
JsValue::from_str(&json)
}

Expand Down