Skip to content

Commit a2311e4

Browse files
committed
use a simpler two-pass solution
1 parent 5428e75 commit a2311e4

File tree

3 files changed

+2
-54
lines changed

3 files changed

+2
-54
lines changed

crates/quarto-markdown-pandoc/src/pandoc/treesitter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::pandoc::treesitter_utils::pipe_table::{
3232
process_pipe_table, process_pipe_table_cell, process_pipe_table_delimiter_cell,
3333
process_pipe_table_delimiter_row, process_pipe_table_header_or_row,
3434
};
35-
use crate::pandoc::treesitter_utils::postprocess::{merge_strs, postprocess, split_cite_content_strings};
35+
use crate::pandoc::treesitter_utils::postprocess::{merge_strs, postprocess};
3636
use crate::pandoc::treesitter_utils::quoted_span::process_quoted_span;
3737
use crate::pandoc::treesitter_utils::raw_attribute::process_raw_attribute;
3838
use crate::pandoc::treesitter_utils::raw_specifier::process_raw_specifier;
@@ -753,6 +753,5 @@ pub fn treesitter_to_pandoc<T: Write>(
753753
};
754754
let result = postprocess(pandoc)?;
755755
let result = merge_strs(result);
756-
let result = split_cite_content_strings(result);
757756
Ok(result)
758757
}

crates/quarto-markdown-pandoc/src/pandoc/treesitter_utils/postprocess.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -542,57 +542,6 @@ fn as_smart_str(s: String) -> String {
542542
}
543543
}
544544

545-
/// Re-split Cite content strings after merge_strs to match Pandoc's behavior
546-
/// Pandoc breaks up citation suffix text by spaces
547-
pub fn split_cite_content_strings(pandoc: Pandoc) -> Pandoc {
548-
topdown_traverse(
549-
pandoc,
550-
&mut Filter::new().with_cite(|mut cite| {
551-
// Split any merged strings in the cite content back into separate Str/Space inlines
552-
// Only split if the content contains spaces (i.e., hasn't been split yet)
553-
let mut needs_split = false;
554-
for inline in &cite.content {
555-
if let Inline::Str(s) = inline {
556-
// Check for regular space or non-breaking space (U+00A0)
557-
if s.text.contains(' ') || s.text.contains('\u{00A0}') {
558-
needs_split = true;
559-
break;
560-
}
561-
}
562-
}
563-
564-
if !needs_split {
565-
return Unchanged(cite);
566-
}
567-
568-
let mut new_content: Vec<Inline> = vec![];
569-
for inline in cite.content {
570-
if let Inline::Str(s) = inline {
571-
// Split by regular spaces and non-breaking spaces
572-
let words: Vec<&str> = s.text.split(|c| c == ' ' || c == '\u{00A0}').collect();
573-
for (i, word) in words.iter().enumerate() {
574-
if i > 0 {
575-
new_content.push(Inline::Space(Space {
576-
source_info: SourceInfo::with_range(empty_range()),
577-
}));
578-
}
579-
if !word.is_empty() {
580-
new_content.push(Inline::Str(Str {
581-
text: word.to_string(),
582-
source_info: s.source_info.clone(),
583-
}));
584-
}
585-
}
586-
} else {
587-
new_content.push(inline);
588-
}
589-
}
590-
cite.content = new_content;
591-
FilterResult(vec![Inline::Cite(cite)], true)
592-
}),
593-
)
594-
}
595-
596545
/// Merge consecutive Str inlines and apply smart typography
597546
pub fn merge_strs(pandoc: Pandoc) -> Pandoc {
598547
topdown_traverse(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[ Para [Cite [Citation { citationId = "smith04", citationPrefix = [], citationSuffix = [Str "p. 33"], citationMode = AuthorInText, citationNoteNum = 1, citationHash = 0 }] [Str "@smith04", Space, Str "[p.", Space, Str "33]"]] ]
1+
[ Para [Cite [Citation { citationId = "smith04", citationPrefix = [], citationSuffix = [Str "p. 33"], citationMode = AuthorInText, citationNoteNum = 1, citationHash = 0 }] [Str "@smith04", Space, Str "[p. 33]"]] ]

0 commit comments

Comments
 (0)