Skip to content

Commit 6d2cfb7

Browse files
committed
fix regression
1 parent 38748ca commit 6d2cfb7

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
*/
88

99
use crate::pandoc::ast_context::ASTContext;
10-
use crate::pandoc::inline::{Delete, EditComment, Highlight, Inline, Insert, Inlines};
11-
use crate::pandoc::location::node_source_info_with_context;
10+
use crate::pandoc::inline::{Delete, EditComment, Highlight, Inline, Inlines, Insert, Space, Str};
11+
use crate::pandoc::location::{SourceInfo, node_source_info_with_context};
12+
use once_cell::sync::Lazy;
13+
use regex::Regex;
1214
use std::collections::HashMap;
1315
use std::io::Write;
1416

1517
use super::pandocnativeintermediate::PandocNativeIntermediate;
18+
use super::text_helpers::apply_smart_quotes;
1619

1720
macro_rules! process_editorial_mark {
1821
($struct_name:ident) => {
@@ -23,6 +26,7 @@ macro_rules! process_editorial_mark {
2326
children: Vec<(String, PandocNativeIntermediate)>,
2427
context: &ASTContext,
2528
) -> PandocNativeIntermediate {
29+
let whitespace_re: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s+").unwrap());
2630
let mut attr = ("".to_string(), vec![], HashMap::new());
2731
let mut content: Inlines = vec![];
2832

@@ -37,6 +41,32 @@ macro_rules! process_editorial_mark {
3741
PandocNativeIntermediate::IntermediateInlines(mut inlines) => {
3842
content.append(&mut inlines);
3943
}
44+
PandocNativeIntermediate::IntermediateBaseText(text, range) => {
45+
if let Some(_) = whitespace_re.find(&text) {
46+
content.push(Inline::Space(Space {
47+
source_info: SourceInfo::new(
48+
if context.filenames.is_empty() {
49+
None
50+
} else {
51+
Some(0)
52+
},
53+
range,
54+
),
55+
}))
56+
} else {
57+
content.push(Inline::Str(Str {
58+
text: apply_smart_quotes(text),
59+
source_info: SourceInfo::new(
60+
if context.filenames.is_empty() {
61+
None
62+
} else {
63+
Some(0)
64+
},
65+
range,
66+
),
67+
}))
68+
}
69+
}
4070
PandocNativeIntermediate::IntermediateUnknown(_) => {
4171
// Skip unknown nodes (delimiters, etc.)
4272
}

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,7 @@ pub fn postprocess(doc: Pandoc) -> Result<Pandoc, Vec<String>> {
399399
classes.extend(insert.attr.1);
400400
FilterResult(
401401
vec![Inline::Span(Span {
402-
attr: (
403-
insert.attr.0,
404-
classes,
405-
insert.attr.2,
406-
),
402+
attr: (insert.attr.0, classes, insert.attr.2),
407403
content,
408404
source_info: empty_source_info(),
409405
})],
@@ -416,11 +412,7 @@ pub fn postprocess(doc: Pandoc) -> Result<Pandoc, Vec<String>> {
416412
classes.extend(delete.attr.1);
417413
FilterResult(
418414
vec![Inline::Span(Span {
419-
attr: (
420-
delete.attr.0,
421-
classes,
422-
delete.attr.2,
423-
),
415+
attr: (delete.attr.0, classes, delete.attr.2),
424416
content,
425417
source_info: empty_source_info(),
426418
})],
@@ -433,11 +425,7 @@ pub fn postprocess(doc: Pandoc) -> Result<Pandoc, Vec<String>> {
433425
classes.extend(highlight.attr.1);
434426
FilterResult(
435427
vec![Inline::Span(Span {
436-
attr: (
437-
highlight.attr.0,
438-
classes,
439-
highlight.attr.2,
440-
),
428+
attr: (highlight.attr.0, classes, highlight.attr.2),
441429
content,
442430
source_info: empty_source_info(),
443431
})],
@@ -450,11 +438,7 @@ pub fn postprocess(doc: Pandoc) -> Result<Pandoc, Vec<String>> {
450438
classes.extend(edit_comment.attr.1);
451439
FilterResult(
452440
vec![Inline::Span(Span {
453-
attr: (
454-
edit_comment.attr.0,
455-
classes,
456-
edit_comment.attr.2,
457-
),
441+
attr: (edit_comment.attr.0, classes, edit_comment.attr.2),
458442
content,
459443
source_info: empty_source_info(),
460444
})],

0 commit comments

Comments
 (0)