@@ -46,6 +46,7 @@ use crate::pandoc::treesitter_utils::text_helpers::*;
4646use crate :: pandoc:: treesitter_utils:: thematic_break:: process_thematic_break;
4747use crate :: pandoc:: treesitter_utils:: uri_autolink:: process_uri_autolink;
4848
49+ use crate :: pandoc:: ast_context:: ASTContext ;
4950use crate :: pandoc:: block:: { Block , Blocks , BulletList , OrderedList , Paragraph , Plain , RawBlock } ;
5051use crate :: pandoc:: inline:: {
5152 Delete , EditComment , Emph , Highlight , Inline , Insert , Note , RawInline , Space , Str , Strikeout ,
@@ -57,7 +58,6 @@ use crate::pandoc::location::{
5758 node_source_info_with_context,
5859} ;
5960use crate :: pandoc:: pandoc:: Pandoc ;
60- use crate :: pandoc:: parse_context:: ParseContext ;
6161use core:: panic;
6262use once_cell:: sync:: Lazy ;
6363use regex:: Regex ;
@@ -70,7 +70,7 @@ use treesitter_utils::pandocnativeintermediate::PandocNativeIntermediate;
7070fn process_list (
7171 node : & tree_sitter:: Node ,
7272 children : Vec < ( String , PandocNativeIntermediate ) > ,
73- context : & ParseContext ,
73+ context : & ASTContext ,
7474) -> PandocNativeIntermediate {
7575 // a list is loose if it has at least one loose item
7676 // an item is loose if
@@ -222,9 +222,9 @@ fn process_list(
222222}
223223
224224fn process_list_item (
225- node : & tree_sitter:: Node ,
225+ list_item_node : & tree_sitter:: Node ,
226226 children : Vec < ( String , PandocNativeIntermediate ) > ,
227- context : & ParseContext ,
227+ context : & ASTContext ,
228228) -> PandocNativeIntermediate {
229229 let mut list_attr: Option < ListAttributes > = None ;
230230 let children = children
@@ -250,19 +250,23 @@ fn process_list_item(
250250 }
251251 match child {
252252 PandocNativeIntermediate :: IntermediateBlock ( block) => Some ( block) ,
253- PandocNativeIntermediate :: IntermediateMetadataString ( text, range ) => {
253+ PandocNativeIntermediate :: IntermediateMetadataString ( text, _range ) => {
254254 // for now we assume it's metadata and emit it as a rawblock
255255 Some ( Block :: RawBlock ( RawBlock {
256256 format : "quarto_minus_metadata" . to_string ( ) ,
257257 text,
258- source_info : SourceInfo :: with_range ( range ) ,
258+ source_info : node_source_info_with_context ( list_item_node , context ) ,
259259 } ) )
260260 }
261261 _ => None ,
262262 }
263263 } )
264264 . collect ( ) ;
265- PandocNativeIntermediate :: IntermediateListItem ( children, node_location ( node) , list_attr)
265+ PandocNativeIntermediate :: IntermediateListItem (
266+ children,
267+ node_location ( list_item_node) ,
268+ list_attr,
269+ )
266270}
267271
268272// Macro for simple emphasis-like inline processing
@@ -290,19 +294,19 @@ fn process_native_inline<T: Write>(
290294 whitespace_re : & Regex ,
291295 inline_buf : & mut T ,
292296 node_text_fn : impl Fn ( ) -> String ,
293- context : & ParseContext ,
297+ context : & ASTContext ,
294298) -> Inline {
295299 match child {
296300 PandocNativeIntermediate :: IntermediateInline ( inline) => inline,
297301 PandocNativeIntermediate :: IntermediateBaseText ( text, range) => {
298302 if let Some ( _) = whitespace_re. find ( & text) {
299303 Inline :: Space ( Space {
300- source_info : SourceInfo :: new ( context. filename . clone ( ) , range) ,
304+ source_info : SourceInfo :: new ( context. primary_filename ( ) . cloned ( ) , range) ,
301305 } )
302306 } else {
303307 Inline :: Str ( Str {
304308 text : apply_smart_quotes ( text) ,
305- source_info : SourceInfo :: new ( context. filename . clone ( ) , range) ,
309+ source_info : SourceInfo :: new ( context. primary_filename ( ) . cloned ( ) , range) ,
306310 } )
307311 }
308312 }
@@ -349,7 +353,7 @@ fn process_native_inlines<T: Write>(
349353 children : Vec < ( String , PandocNativeIntermediate ) > ,
350354 whitespace_re : & Regex ,
351355 inlines_buf : & mut T ,
352- context : & ParseContext ,
356+ context : & ASTContext ,
353357) -> Vec < Inline > {
354358 let mut inlines: Vec < Inline > = Vec :: new ( ) ;
355359 for ( _, child) in children {
@@ -361,12 +365,12 @@ fn process_native_inlines<T: Write>(
361365 PandocNativeIntermediate :: IntermediateBaseText ( text, range) => {
362366 if let Some ( _) = whitespace_re. find ( & text) {
363367 inlines. push ( Inline :: Space ( Space {
364- source_info : SourceInfo :: new ( context. filename . clone ( ) , range) ,
368+ source_info : SourceInfo :: new ( context. primary_filename ( ) . cloned ( ) , range) ,
365369 } ) )
366370 } else {
367371 inlines. push ( Inline :: Str ( Str {
368372 text,
369- source_info : SourceInfo :: new ( context. filename . clone ( ) , range) ,
373+ source_info : SourceInfo :: new ( context. primary_filename ( ) . cloned ( ) , range) ,
370374 } ) )
371375 }
372376 }
@@ -388,7 +392,7 @@ fn native_visitor<T: Write>(
388392 node : & tree_sitter:: Node ,
389393 children : Vec < ( String , PandocNativeIntermediate ) > ,
390394 input_bytes : & [ u8 ] ,
391- context : & ParseContext ,
395+ context : & ASTContext ,
392396) -> PandocNativeIntermediate {
393397 // TODO What sounded like a good idea with two buffers
394398 // is becoming annoying now...
@@ -436,8 +440,8 @@ fn native_visitor<T: Write>(
436440 | "code_content"
437441 | "latex_content"
438442 | "text_base" => create_base_text_from_node_text ( node, input_bytes) ,
439- "document" => process_document ( children, context) ,
440- "section" => process_section ( children, context) ,
443+ "document" => process_document ( node , children, context) ,
444+ "section" => process_section ( node , children, context) ,
441445 "paragraph" => process_paragraph ( node, children, context) ,
442446 "indented_code_block" => {
443447 process_indented_code_block ( node, children, input_bytes, & indent_re, context)
@@ -453,13 +457,17 @@ fn native_visitor<T: Write>(
453457 "key_value_value" => string_as_base_text ( ) ,
454458 "link_title" => process_link_title ( node, input_bytes, context) ,
455459 "link_text" => PandocNativeIntermediate :: IntermediateInlines ( native_inlines ( children) ) ,
456- "image" => {
457- treesitter_utils:: image:: process_image ( & mut image_buf, node_text, children, context)
458- }
460+ "image" => treesitter_utils:: image:: process_image (
461+ node,
462+ & mut image_buf,
463+ node_text,
464+ children,
465+ context,
466+ ) ,
459467 "image_description" => {
460468 PandocNativeIntermediate :: IntermediateInlines ( native_inlines ( children) )
461469 }
462- "inline_link" => process_inline_link ( & mut link_buf, node_text, children, context) ,
470+ "inline_link" => process_inline_link ( node , & mut link_buf, node_text, children, context) ,
463471 "key_value_specifier" => process_key_value_specifier ( buf, children, context) ,
464472 "raw_specifier" => process_raw_specifier ( node, input_bytes, context) ,
465473 "emphasis" => emphasis_inline ! (
@@ -665,7 +673,7 @@ pub fn treesitter_to_pandoc<T: Write>(
665673 buf : & mut T ,
666674 tree : & tree_sitter_qmd:: MarkdownTree ,
667675 input_bytes : & [ u8 ] ,
668- context : & ParseContext ,
676+ context : & ASTContext ,
669677) -> Result < Pandoc , Vec < String > > {
670678 let result = bottomup_traverse_concrete_tree (
671679 & mut tree. walk ( ) ,
0 commit comments