File tree Expand file tree Collapse file tree 4 files changed +58
-16
lines changed Expand file tree Collapse file tree 4 files changed +58
-16
lines changed Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ pub mod pandoc;
1212pub mod readers;
1313pub mod traversals;
1414pub mod utils;
15+ pub mod wasm_entry_points;
1516pub mod writers;
Original file line number Diff line number Diff line change 1+ /*
2+ * mod.rs
3+ * Copyright (c) 2025 Posit, PBC
4+ */
5+
6+ use std:: { io, panic} ;
7+
8+ use crate :: readers;
9+ use crate :: utils:: output:: VerboseOutput ;
10+ use crate :: utils:: tree_sitter_log_observer:: TreeSitterLogObserver ;
11+
12+ fn pandoc_to_json ( doc : & crate :: pandoc:: Pandoc ) -> Result < String , String > {
13+ let mut buf = Vec :: new ( ) ;
14+ match crate :: writers:: json:: write ( doc, & mut buf) {
15+ Ok ( _) => {
16+ // Nothing to do
17+ }
18+ Err ( err) => {
19+ return Err ( format ! ( "Unable to write as json: {:?}" , err) ) ;
20+ }
21+ }
22+
23+ match String :: from_utf8 ( buf) {
24+ Ok ( json) => Ok ( json) ,
25+ Err ( err) => Err ( format ! ( "Unable to convert json to string: {:?}" , err) ) ,
26+ }
27+ }
28+
29+ pub fn parse_qmd ( input : & [ u8 ] ) -> String {
30+ let mut output = VerboseOutput :: Sink ( io:: sink ( ) ) ;
31+ let result = match readers:: qmd:: read (
32+ input,
33+ false ,
34+ "<input>" ,
35+ & mut output,
36+ None :: < fn ( & [ u8 ] , & TreeSitterLogObserver , & str ) -> Vec < String > > ,
37+ ) {
38+ Ok ( result) => result,
39+ Err ( err) => panic ! ( "Unable to read as a qmd:\n {}" , err. join( "\n " ) ) ,
40+ } ;
41+
42+ pandoc_to_json ( & result) . unwrap ( )
43+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * test_wasm_entrypoints.rs
3+ * Copyright (c) 2025 Posit, PBC
4+ */
5+
6+ #[ test]
7+ fn test_wasm_read_entrypoint ( ) {
8+ let input = "# hello _world_.\n " ;
9+ let result = quarto_markdown_pandoc:: wasm_entry_points:: parse_qmd ( input. as_bytes ( ) ) ;
10+ eprintln ! ( "result: {}" , result) ;
11+ }
Original file line number Diff line number Diff line change @@ -17,11 +17,10 @@ pub mod c_shim;
1717
1818mod utils;
1919
20- use std:: { io , panic} ;
20+ use std:: panic;
2121
2222use quarto_markdown_pandoc:: readers;
23- use quarto_markdown_pandoc:: utils:: output:: VerboseOutput ;
24- use quarto_markdown_pandoc:: utils:: tree_sitter_log_observer:: TreeSitterLogObserver ;
23+ use quarto_markdown_pandoc:: wasm_entry_points;
2524use quarto_markdown_pandoc:: writers;
2625use wasm_bindgen:: prelude:: * ;
2726
@@ -60,23 +59,11 @@ fn pandoc_to_json(doc: &quarto_markdown_pandoc::pandoc::Pandoc) -> Result<String
6059
6160#[ wasm_bindgen]
6261pub fn parse_qmd ( input : JsValue ) -> JsValue {
63- let mut output = VerboseOutput :: Sink ( io:: sink ( ) ) ;
6462 let input = match input. as_string ( ) {
6563 Some ( input) => input,
6664 None => panic ! ( "Unable to parse `input` as a `String`." ) ,
6765 } ;
68- let result = match readers:: qmd:: read (
69- input. as_bytes ( ) ,
70- false ,
71- "<input>" ,
72- & mut output,
73- None :: < fn ( & [ u8 ] , & TreeSitterLogObserver , & str ) -> Vec < String > > ,
74- ) {
75- Ok ( result) => result,
76- Err ( err) => panic ! ( "Unable to read as a qmd:\n {}" , err. join( "\n " ) ) ,
77- } ;
78-
79- let json = pandoc_to_json ( & result) . unwrap ( ) ;
66+ let json = wasm_entry_points:: parse_qmd ( input. as_bytes ( ) ) ;
8067 JsValue :: from_str ( & json)
8168}
8269
You can’t perform that action at this time.
0 commit comments