@@ -291,10 +291,21 @@ impl_inline_filterable_terminal!(
291291 Math ,
292292 RawInline ,
293293 Shortcode ,
294- NoteReference ,
295- Attr
294+ NoteReference
296295) ;
297296
297+ // Attr is special because it has two fields (Attr, AttrSourceInfo)
298+ // We need a custom impl that preserves attr_source
299+ // However, filters don't actually work on Attr values directly,
300+ // so this is just a placeholder that should never be called
301+ impl InlineFilterableStructure for ( pandoc:: Attr , crate :: pandoc:: attr:: AttrSourceInfo ) {
302+ fn filter_structure ( self , _: & mut Filter ) -> Inline {
303+ // Note: This should not be called in practice because Attr inlines
304+ // are stripped during postprocessing before filters run
305+ Inline :: Attr ( self . 0 , self . 1 )
306+ }
307+ }
308+
298309macro_rules! impl_inline_filterable_simple {
299310 ( $( $variant: ident) ,* ) => {
300311 $(
@@ -350,6 +361,7 @@ impl InlineFilterableStructure for pandoc::Cite {
350361 mode : cit. mode ,
351362 note_num : cit. note_num ,
352363 hash : cit. hash ,
364+ id_source : cit. id_source ,
353365 } )
354366 . collect ( ) ,
355367 content : topdown_traverse_inlines ( self . content , filter) ,
@@ -641,8 +653,22 @@ pub fn topdown_traverse_inline(inline: Inline, filter: &mut Filter) -> Inlines {
641653 Inline :: NoteReference ( note_ref) => {
642654 handle_inline_filter ! ( NoteReference , note_ref, note_reference, filter)
643655 }
644- Inline :: Attr ( attr) => {
645- handle_inline_filter ! ( Attr , attr, attr, filter)
656+ Inline :: Attr ( attr, attr_source) => {
657+ // Special handling for Attr since it has two fields and filters don't actually work on Attr tuples
658+ // Attr inlines should be stripped during postprocessing before filters run
659+ // So this branch should rarely be hit
660+ if let Some ( f) = & mut filter. inline {
661+ let inline = Inline :: Attr ( attr, attr_source) ;
662+ match f ( inline. clone ( ) ) {
663+ FilterReturn :: Unchanged ( _) => vec ! [ inline] ,
664+ FilterReturn :: FilterResult ( result, _should_recurse) => result,
665+ }
666+ } else {
667+ vec ! [ traverse_inline_structure(
668+ Inline :: Attr ( attr, attr_source) ,
669+ filter,
670+ ) ]
671+ }
646672 }
647673 Inline :: Insert ( ins) => {
648674 handle_inline_filter ! ( Insert , ins, insert, filter)
@@ -827,6 +853,7 @@ fn traverse_inline_nonterminal(inline: Inline, filter: &mut Filter) -> Inline {
827853 mode : cit. mode ,
828854 note_num : cit. note_num ,
829855 hash : cit. hash ,
856+ id_source : cit. id_source ,
830857 } )
831858 . collect ( ) ,
832859 content : topdown_traverse_inlines ( c. content , filter) ,
@@ -837,12 +864,16 @@ fn traverse_inline_nonterminal(inline: Inline, filter: &mut Filter) -> Inline {
837864 target : l. target ,
838865 content : topdown_traverse_inlines ( l. content , filter) ,
839866 source_info : l. source_info ,
867+ attr_source : l. attr_source ,
868+ target_source : l. target_source ,
840869 } ) ,
841870 Inline :: Image ( i) => Inline :: Image ( crate :: pandoc:: Image {
842871 attr : i. attr ,
843872 target : i. target ,
844873 content : topdown_traverse_inlines ( i. content , filter) ,
845874 source_info : i. source_info ,
875+ attr_source : i. attr_source ,
876+ target_source : i. target_source ,
846877 } ) ,
847878 Inline :: Note ( note) => Inline :: Note ( crate :: pandoc:: Note {
848879 content : topdown_traverse_blocks ( note. content , filter) ,
@@ -852,6 +883,7 @@ fn traverse_inline_nonterminal(inline: Inline, filter: &mut Filter) -> Inline {
852883 attr : span. attr ,
853884 content : topdown_traverse_inlines ( span. content , filter) ,
854885 source_info : span. source_info ,
886+ attr_source : span. attr_source ,
855887 } ) ,
856888 _ => panic ! ( "Unsupported inline type: {:?}" , inline) ,
857889 }
@@ -870,7 +902,7 @@ pub fn traverse_inline_structure(inline: Inline, filter: &mut Filter) -> Inline
870902 // extensions
871903 Inline :: Shortcode ( _) => inline,
872904 Inline :: NoteReference ( _) => inline,
873- Inline :: Attr ( _) => inline,
905+ Inline :: Attr ( _, _ ) => inline,
874906 _ => traverse_inline_nonterminal ( inline, filter) ,
875907 }
876908}
@@ -893,6 +925,7 @@ fn traverse_caption(
893925 long : caption
894926 . long
895927 . map ( |long| topdown_traverse_blocks ( long, filter) ) ,
928+ source_info : caption. source_info ,
896929 }
897930}
898931
0 commit comments