Skip to content

Commit dfdcca9

Browse files
cscheidclaude
andauthored
Pipe table alignment markers (#5) (#46)
* Implement table captions in tree-sitter grammar Implements support for Pandoc-style table captions that appear after pipe tables using the tree-sitter grammar for precise parsing. Table caption syntax: - Blank line followed by ": caption text" - Caption must appear immediately after a pipe table - Only the ': caption' format is supported Implementation approach: - Added table_caption rule to tree-sitter grammar as child of pipe_table - Table captions are parsed at grammar level, not in postprocessor - Reverted _line rule to disallow paragraphs starting with ':' (restores safety check for detecting accidental fenced div continuation) Changes: - Modified tree-sitter-markdown/grammar.js to add table_caption rule - Updated pipe_table processor to extract caption from parse tree - Added table_caption handler in treesitter.rs dispatcher - Removed postprocessor caption detection logic and with_blocks filter - Removed extract_table_caption function from postprocess.rs Benefits: - Table captions only recognized in correct context (after pipe tables) - Restored paragraph safety check prevents malformed documents - Cleaner separation between grammar structure and AST transformation - Better performance by eliminating block scanning in postprocessor Output matches Pandoc's JSON AST structure with caption attached to table's caption.long field as a Plain block. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * tests for pipe table alignment --------- Co-authored-by: Claude <[email protected]>
1 parent b248a0c commit dfdcca9

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Right | Left | Center | Default |
2+
|------:|:-----|:------:|---------|
3+
| R1 | L1 | C1 | D1 |
4+
| R2 | L2 | C2 | D2 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Right | Left | Center | Default |
2+
|------:|:-----|:------:|---------|
3+
| R1 | L1 | C1 | D1 |
4+
| R2 | L2 | C2 | D2 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| Right | Left | Center | Default |
2+
|------:|:-----|:------:|---------|
3+
| R1 | L1 | C1 | D1 |
4+
| R2 | L2 | C2 | D2 |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"astContext":{"filenames":["tests/snapshots/json/table-alignment.qmd"]},"blocks":[{"c":[["",[],[]],[null,[]],[[{"t":"AlignRight"},{"t":"ColWidthDefault"}],[{"t":"AlignLeft"},{"t":"ColWidthDefault"}],[{"t":"AlignCenter"},{"t":"ColWidthDefault"}],[{"t":"AlignDefault"},{"t":"ColWidthDefault"}]],[["",[],[]],[[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"Right","l":{"end":{"column":7,"offset":7,"row":0},"filenameIndex":0,"start":{"column":2,"offset":2,"row":0}},"t":"Str"}],"l":{"end":{"column":8,"offset":8,"row":0},"filenameIndex":0,"start":{"column":2,"offset":2,"row":0}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"Left","l":{"end":{"column":14,"offset":14,"row":0},"filenameIndex":0,"start":{"column":10,"offset":10,"row":0}},"t":"Str"}],"l":{"end":{"column":15,"offset":15,"row":0},"filenameIndex":0,"start":{"column":10,"offset":10,"row":0}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"Center","l":{"end":{"column":23,"offset":23,"row":0},"filenameIndex":0,"start":{"column":17,"offset":17,"row":0}},"t":"Str"}],"l":{"end":{"column":24,"offset":24,"row":0},"filenameIndex":0,"start":{"column":17,"offset":17,"row":0}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"Default","l":{"end":{"column":33,"offset":33,"row":0},"filenameIndex":0,"start":{"column":26,"offset":26,"row":0}},"t":"Str"}],"l":{"end":{"column":34,"offset":34,"row":0},"filenameIndex":0,"start":{"column":26,"offset":26,"row":0}},"t":"Plain"}]]]]]],[[["",[],[]],0,[],[[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"R1","l":{"end":{"column":4,"offset":76,"row":2},"filenameIndex":0,"start":{"column":2,"offset":74,"row":2}},"t":"Str"}],"l":{"end":{"column":8,"offset":80,"row":2},"filenameIndex":0,"start":{"column":2,"offset":74,"row":2}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"L1","l":{"end":{"column":12,"offset":84,"row":2},"filenameIndex":0,"start":{"column":10,"offset":82,"row":2}},"t":"Str"}],"l":{"end":{"column":15,"offset":87,"row":2},"filenameIndex":0,"start":{"column":10,"offset":82,"row":2}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"C1","l":{"end":{"column":19,"offset":91,"row":2},"filenameIndex":0,"start":{"column":17,"offset":89,"row":2}},"t":"Str"}],"l":{"end":{"column":24,"offset":96,"row":2},"filenameIndex":0,"start":{"column":17,"offset":89,"row":2}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"D1","l":{"end":{"column":28,"offset":100,"row":2},"filenameIndex":0,"start":{"column":26,"offset":98,"row":2}},"t":"Str"}],"l":{"end":{"column":34,"offset":106,"row":2},"filenameIndex":0,"start":{"column":26,"offset":98,"row":2}},"t":"Plain"}]]]],[["",[],[]],[[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"R2","l":{"end":{"column":4,"offset":112,"row":3},"filenameIndex":0,"start":{"column":2,"offset":110,"row":3}},"t":"Str"}],"l":{"end":{"column":8,"offset":116,"row":3},"filenameIndex":0,"start":{"column":2,"offset":110,"row":3}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"L2","l":{"end":{"column":12,"offset":120,"row":3},"filenameIndex":0,"start":{"column":10,"offset":118,"row":3}},"t":"Str"}],"l":{"end":{"column":15,"offset":123,"row":3},"filenameIndex":0,"start":{"column":10,"offset":118,"row":3}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"C2","l":{"end":{"column":19,"offset":127,"row":3},"filenameIndex":0,"start":{"column":17,"offset":125,"row":3}},"t":"Str"}],"l":{"end":{"column":24,"offset":132,"row":3},"filenameIndex":0,"start":{"column":17,"offset":125,"row":3}},"t":"Plain"}]],[["",[],[]],{"t":"AlignDefault"},1,1,[{"c":[{"c":"D2","l":{"end":{"column":28,"offset":136,"row":3},"filenameIndex":0,"start":{"column":26,"offset":134,"row":3}},"t":"Str"}],"l":{"end":{"column":34,"offset":142,"row":3},"filenameIndex":0,"start":{"column":26,"offset":134,"row":3}},"t":"Plain"}]]]]]]],[["",[],[]],[]]],"l":{"end":{"column":0,"offset":144,"row":4},"filenameIndex":0,"start":{"column":0,"offset":0,"row":0}},"t":"Table"}],"meta":{},"pandoc-api-version":[1,23,1]}

0 commit comments

Comments
 (0)