Skip to content

Commit 17e24ef

Browse files
committed
document editorial marks, fix qmd roundtripping
1 parent 8bcdfa5 commit 17e24ef

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

crates/quarto-markdown-pandoc/CLAUDE.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@ Whenever you start working on a coding task, follow these steps:
2525

2626
- Make a plan to yourself.
2727
- The plan should include adding appropriate tests to the test suite.
28-
- Before implementing the feature, write the test that you think should fail, and ensure that the test fails the way you expect to!
28+
- **FIRST**: Write the test that you think should fail
29+
- **SECOND**: Run ONLY that test and verify it fails with the expected error
30+
- **THIRD**: Implement the fix
31+
- **FOURTH**: Run the test again and verify it now passes
2932
- Work on the plan item by item.
3033
- You are not done until the test you wrote passes.
3134
- You are not done until the test you wrote is integrated to our test suite.
3235
- If you run out of ideas and still can't make the test pass, do not erase the test. Report back to me and we will work on it together.
3336
- If in the process of writing tests you run into an unexpected parse error, store it in a separate file and report it to me. We're still improving the parser and it's possible that you will run into bugs.
3437

38+
## BEFORE YOU IMPLEMENT ANY BUG FIX - MANDATORY CHECKLIST
39+
40+
Before implementing ANY bug fix, you MUST complete this checklist in order:
41+
42+
- [ ] Have you written the test?
43+
- [ ] Have you run the test and confirmed it fails?
44+
- [ ] Have you verified the failure is exactly what you expected?
45+
- [ ] Only after all three above are complete: proceed with implementation
46+
47+
This is non-negotiable. Do not skip this process.
48+
3549
# Error messages
3650

3751
The error message infrastructure is based on Clinton Jeffery's TOPLAS 2003 paper "Generating Syntax Errors from Examples". You don't need to read the entire paper to understand what's happening. The abstract of the paper is:
@@ -65,12 +79,12 @@ The `quarto-markdown-pandoc` binary accepts the following options:
6579
- The qmd format only supports the inline syntax for a link [link](./target.html), and not the reference-style syntax [link][1].
6680
- Always strive for test documents as small as possible. Prefer a large number of small test documents instead of small number of large documents.
6781
- When fixing bugs, always try to isolate and fix one bug at a time.
68-
- When fixing bugs using tests, run the failing test before attempting to fix issues. This helps ensuring that tests are exercising the failure as expected, and fixes actually fix the particular issue.
82+
- **CRITICAL - TEST FIRST**: When fixing bugs using tests, you MUST run the failing test BEFORE implementing any fix. This is non-negotiable. Verify the test fails in the expected way, then implement the fix, then verify the test passes.
6983
- 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.
7084
- use "cargo run --" instead of trying to find the binary location, which will often be outside of this crate.
7185
- 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.
7286
- 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.
73-
- When fixing roundtripping bugs, make sure to always add a roundtripping test to `tests/roundtrip_tests/qmd-json-qmd`.
87+
- **When fixing roundtripping bugs**: FIRST add the failing test to `tests/roundtrip_tests/qmd-json-qmd`, run it to verify it fails with the expected output, THEN implement the fix, THEN verify the test passes.
7488
- When I say "@doit", I mean "create a plan, and work on it item by item."
7589
- When you're done editing a Rust file, run `cargo fmt` on it.
7690
- If I ask you to write notes to yourself, do it in markdown and write the output in the `docs/for-claude` directory.

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,30 @@ fn write_quoted(
910910
Ok(())
911911
}
912912
fn write_span(span: &crate::pandoc::Span, buf: &mut dyn std::io::Write) -> std::io::Result<()> {
913+
let (id, classes, keyvals) = &span.attr;
914+
915+
// Check if this is an editorial mark span that should use decorated syntax
916+
// These spans have exactly one class, no ID, and no key-value pairs
917+
if id.is_empty() && classes.len() == 1 && keyvals.is_empty() {
918+
let marker = match classes[0].as_str() {
919+
"quarto-highlight" => Some("!! "),
920+
"quarto-insert" => Some("++ "),
921+
"quarto-delete" => Some("-- "),
922+
"quarto-edit-comment" => Some(">> "),
923+
_ => None,
924+
};
925+
926+
if let Some(marker) = marker {
927+
// Write using decorated syntax
928+
write!(buf, "[{}", marker)?;
929+
for inline in &span.content {
930+
write_inline(inline, buf)?;
931+
}
932+
write!(buf, "]")?;
933+
return Ok(());
934+
}
935+
}
936+
913937
// Spans always use bracket syntax: [content]{#id .class key=value}
914938
// Even empty attributes should be written as [content]{} for proper roundtripping
915939
write!(buf, "[")?;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This paragraph has [!! a highlight], [++ an insertion], [-- a deletion], and [>> a comment] all together.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Here is [!! a highlight].
2+
3+
Here is [++ an insertion].
4+
5+
Here is [-- a deletion].
6+
7+
Here is [>> a comment].

0 commit comments

Comments
 (0)