66use glob:: glob;
77use quarto_markdown_pandoc:: errors:: parse_is_good;
88use quarto_markdown_pandoc:: pandoc:: treesitter_to_pandoc;
9- use quarto_markdown_pandoc:: writers;
9+ use quarto_markdown_pandoc:: { readers , writers} ;
1010use std:: io:: Write ;
1111use std:: process:: { Command , Stdio } ;
1212use tree_sitter_qmd:: MarkdownParser ;
@@ -69,6 +69,12 @@ fn matches_canonical_pandoc_format(
6969 }
7070 let our_ast = canonicalize_pandoc_ast ( ast, output_format, output_format) ;
7171 let pandoc_ast = canonicalize_pandoc_ast ( markdown, pandoc_reader, output_format) ;
72+ if our_ast != pandoc_ast {
73+ eprintln ! ( "Format: {} -> {}" , pandoc_reader, output_format) ;
74+ eprintln ! ( "Input:\n {}" , markdown) ;
75+ eprintln ! ( "Our AST:\n {}" , our_ast) ;
76+ eprintln ! ( "Pandoc AST:\n {}" , pandoc_ast) ;
77+ }
7278 our_ast == pandoc_ast
7379}
7480
@@ -78,32 +84,18 @@ fn matches_pandoc_markdown_reader(input: &str) -> bool {
7884 }
7985 let mut buf1 = Vec :: new ( ) ;
8086 let mut buf2 = Vec :: new ( ) ;
81- writers:: native:: write (
82- & treesitter_to_pandoc (
83- & mut std:: io:: sink ( ) ,
84- & MarkdownParser :: default ( )
85- . parse ( input. as_bytes ( ) , None )
86- . unwrap ( ) ,
87- input. as_bytes ( ) ,
88- )
89- . unwrap ( ) ,
90- & mut buf1,
91- )
92- . unwrap ( ) ;
87+
88+ let doc = readers:: qmd:: read ( input. as_bytes ( ) , & mut std:: io:: sink ( ) ) . unwrap ( ) ;
89+ writers:: native:: write ( & doc, & mut buf1) . unwrap ( ) ;
9390 let native_output = String :: from_utf8 ( buf1) . expect ( "Invalid UTF-8 in output" ) ;
94- writers:: json:: write (
95- & treesitter_to_pandoc (
96- & mut std:: io:: sink ( ) ,
97- & MarkdownParser :: default ( )
98- . parse ( input. as_bytes ( ) , None )
99- . unwrap ( ) ,
100- input. as_bytes ( ) ,
101- )
102- . unwrap ( ) ,
103- & mut buf2,
104- )
105- . unwrap ( ) ;
91+ writers:: json:: write ( & doc, & mut buf2) . unwrap ( ) ;
10692 let json_output = String :: from_utf8 ( buf2) . expect ( "Invalid UTF-8 in output" ) ;
93+
94+ let mut our_value: serde_json:: Value =
95+ serde_json:: from_str ( & json_output) . expect ( "Failed to parse our JSON" ) ;
96+ remove_location_fields ( & mut our_value) ;
97+ let json_output = serde_json:: to_string ( & our_value) . expect ( "Failed to serialize our JSON" ) ;
98+
10799 matches_canonical_pandoc_format ( input, & native_output, "markdown" , "native" )
108100 && matches_canonical_pandoc_format ( input, & json_output, "markdown" , "json" )
109101}
0 commit comments