Skip to content

Commit 95ea2a8

Browse files
authored
Docs for editorial marks (#62)
* document editorial marks, fix qmd roundtripping * attempt to make claude remember red-light/green-light tdd
1 parent ede5980 commit 95ea2a8

File tree

7 files changed

+206
-4
lines changed

7 files changed

+206
-4
lines changed

CLAUDE.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22

33
The main documentation for this repository is located at:
44
[crates/quarto-markdown-pandoc/CLAUDE.md](crates/quarto-markdown-pandoc/CLAUDE.md)
5+
6+
## **CRITICAL - TEST-DRIVEN DEVELOPMENT**
7+
8+
When fixing ANY bug:
9+
1. **FIRST**: Write the test
10+
2. **SECOND**: Run the test and verify it fails as expected
11+
3. **THIRD**: Implement the fix
12+
4. **FOURTH**: Run the test and verify it passes
13+
14+
**This is non-negotiable. Never implement a fix before verifying the test fails.**
15+
16+
## General Instructions
17+
518
- in this repository, "qmd" means "quarto markdown", the dialect of markdown we are developing. Although we aim to be largely compatible with Pandoc, it is not necessarily the case that a discrepancy in the behavior is a bug.
619
- the qmd format only supports the inline syntax for a link [link](./target.html), and not the reference-style syntax [link][1].
720
- Always strive for test documents as small as possible. Prefer a large number of small test documents instead of small number of large documents.
821
- When fixing bugs, always try to isolate and fix one bug at a time.
9-
- 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.
22+
- **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.
1023
- 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.
1124
- use "cargo run --" instead of trying to find the binary location, which will often be outside of this crate.
1225
- when calling shell scripts, ALWAYS BE MINDFUL of the current directory you're operating in. use `pwd` as necessary to avoid confusing yourself over commands that use relative paths.

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].

docs/syntax/editorial-marks.qmd

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
---
2+
title: "Editorial Marks"
3+
---
4+
5+
## Overview
6+
7+
Editorial marks allow you to annotate your text with suggestions, highlights, and comments during the editing and review process. In `quarto-markdown`, these marks use a special bracket syntax and are converted to Pandoc AST spans with specific CSS classes that can be styled or processed by filters.
8+
9+
## Syntax
10+
11+
Editorial marks use a square bracket syntax with special marker characters:
12+
13+
- `[!! text]` - Highlight
14+
- `[++ text]` - Insertion suggestion
15+
- `[-- text]` - Deletion suggestion
16+
- `[>> text]` - Comment
17+
18+
The opening bracket is followed by two marker characters, then a space, and then the content to be marked. The mark is closed with a closing bracket.
19+
20+
## Conversion to Pandoc AST
21+
22+
When converted to Pandoc AST, editorial marks become `Span` elements with specific CSS classes:
23+
24+
- `[!! ...]``Span ("", ["quarto-highlight"], []) [...]`
25+
- `[++ ...]``Span ("", ["quarto-insert"], []) [...]`
26+
- `[-- ...]``Span ("", ["quarto-delete"], []) [...]`
27+
- `[>> ...]``Span ("", ["quarto-edit-comment"], []) [...]`
28+
29+
These classes can be used to apply styling in HTML output or to process the marks with Pandoc filters.
30+
31+
## Examples
32+
33+
### Highlight
34+
35+
Use `[!! text]` to highlight important sections that need attention:
36+
37+
This paragraph contains [!! an important section] that should be reviewed.
38+
39+
```markdown
40+
This paragraph contains [!! an important section] that should be reviewed.
41+
```
42+
43+
### Insertion Suggestion
44+
45+
Use `[++ text]` to suggest text that should be added:
46+
47+
The document needs [++ additional context here] to be complete.
48+
49+
```markdown
50+
The document needs [++ additional context here] to be complete.
51+
```
52+
53+
### Deletion Suggestion
54+
55+
Use `[-- text]` to suggest text that should be removed:
56+
57+
This sentence has [-- unnecessary words] that can be deleted.
58+
59+
```markdown
60+
This sentence has [-- unnecessary words] that can be deleted.
61+
```
62+
63+
### Comment
64+
65+
Use `[>> text]` to add editorial comments or notes:
66+
67+
The conclusion [>> needs more supporting evidence] requires revision.
68+
69+
```markdown
70+
The conclusion [>> needs more supporting evidence] requires revision.
71+
```
72+
73+
### Multiple Marks in One Paragraph
74+
75+
You can use multiple editorial marks in a single paragraph:
76+
77+
This paragraph has [!! a highlight], [++ an insertion], [-- a deletion], and [>> a comment] all together.
78+
79+
```markdown
80+
This paragraph has [!! a highlight], [++ an insertion], [-- a deletion], and [>> a comment] all together.
81+
```
82+
83+
### Nested Formatting
84+
85+
Editorial marks can contain other inline formatting:
86+
87+
The section needs [++ **bold text** and *italic text*] to emphasize the point.
88+
89+
```markdown
90+
The section needs [++ **bold text** and *italic text*] to emphasize the point.
91+
```
92+
93+
## Use Cases
94+
95+
Editorial marks are particularly useful for:
96+
97+
- **Collaborative editing**: Team members can suggest changes without directly modifying the text
98+
- **Review workflows**: Reviewers can highlight issues and suggest improvements
99+
- **Track changes**: Similar to word processor track changes, but in plain text
100+
- **Editorial comments**: Editors can leave notes without disrupting the flow of the document
101+
102+
## Processing Editorial Marks
103+
104+
Since editorial marks are converted to spans with CSS classes, you can:
105+
106+
1. **Style them in HTML output**: Use CSS to visually distinguish different mark types
107+
2. **Process with Lua filters**: Write Pandoc Lua filters to convert marks to other formats
108+
3. **Accept/reject suggestions**: Build tools to process insertion and deletion suggestions
109+
4. **Generate reports**: Extract all comments and highlights for review
110+
111+
### Example CSS Styling
112+
113+
```css
114+
.quarto-highlight {
115+
background-color: yellow;
116+
}
117+
118+
.quarto-insert {
119+
color: green;
120+
text-decoration: underline;
121+
}
122+
123+
.quarto-delete {
124+
color: red;
125+
text-decoration: line-through;
126+
}
127+
128+
.quarto-edit-comment {
129+
color: blue;
130+
font-style: italic;
131+
}
132+
```
133+
134+
## Availability
135+
136+
Editorial marks are currently only available when using `quarto-markdown-pandoc`. This syntax will be integrated into Quarto's markdown processing in future releases.
137+
138+
## Limitations
139+
140+
- Editorial marks only support inline content, not block-level elements
141+
- The marker characters (`!!`, `++`, `--`, `>>`) must be followed by a space
142+
- Editorial marks cannot be nested within each other

docs/syntax/index.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ The features documented here are currently under development. The syntax and beh
1111
## Available Features
1212

1313
- [Definition Lists](definition-lists.qmd) - Create definition lists using an embedded markdown DSL
14+
- [Editorial Marks](editorial-marks.qmd) - Annotate text with highlights, insertions, deletions, and comments
1415
- [Footnotes](footnotes.qmd) - Add footnotes with inline or fenced block syntax

0 commit comments

Comments
 (0)