Skip to content

Commit 4d7d33e

Browse files
committed
smart apostrophe handling
1 parent bee0aae commit 4d7d33e

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

crates/quarto-markdown-pandoc/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ The `quarto-markdown-pandoc` binary accepts the following options:
6262
- If you need to fix parser bugs, you will find use in running the application with "-v", which will provide a large amount of information from the tree-sitter parsing process, including a print of the concrete syntax tree out to stderr.
6363
- When fixing inconsistency bugs, use `pandoc -t json -i <input_file>` to get Pandoc's output, and `cargo run -- -t json -i <input_file>` to get our output.
6464
- When fixing roundtripping bugs, make sure to always add a roundtripping test to `tests/roundtrip_tests/qmd-json-qmd`.
65+
- When I say "@doit", I mean "create a plan, and work on it item by item."

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ fn create_specifier_base_text(
160160
PandocNativeIntermediate::IntermediateBaseText(id, node_location(node))
161161
}
162162

163+
// Helper function to convert straight apostrophes to smart quotes
164+
// Converts ASCII apostrophe (') to Unicode right single quotation mark (')
165+
fn apply_smart_quotes(text: String) -> String {
166+
text.replace('\'', "\u{2019}")
167+
}
168+
163169
// Helper function to create simple line break inlines
164170
fn create_line_break_inline(node: &tree_sitter::Node, is_hard: bool) -> PandocNativeIntermediate {
165171
let range = node_location(node);
@@ -1696,7 +1702,7 @@ fn process_native_inline<T: Write>(
16961702
})
16971703
} else {
16981704
Inline::Str(Str {
1699-
text,
1705+
text: apply_smart_quotes(text),
17001706
source_info: SourceInfo::with_range(range),
17011707
})
17021708
}

crates/quarto-markdown-pandoc/src/writers/qmd.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,15 @@ fn determine_backticks(text: &str) -> String {
660660
"`".repeat(max_backticks + 1)
661661
}
662662

663+
// Helper function to reverse smart quotes conversion
664+
// Converts Unicode right single quotation mark (') back to ASCII apostrophe (')
665+
fn reverse_smart_quotes(text: &str) -> String {
666+
text.replace('\u{2019}', "'")
667+
}
668+
663669
fn write_str(s: &Str, buf: &mut dyn std::io::Write) -> std::io::Result<()> {
664670
// FIXME what are the escaping rules that Pandoc uses?
665-
write!(buf, "{}", s.text)
671+
write!(buf, "{}", reverse_smart_quotes(&s.text))
666672
}
667673

668674
fn write_space(_: &crate::pandoc::Space, buf: &mut dyn std::io::Write) -> std::io::Result<()> {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project's important.
2+
3+
I can't believe it's working! We're done.

0 commit comments

Comments
 (0)