Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| a | b |
|---|---|
| `|` | oh no |
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| a | b |
|---|---|
| $|$ | math |
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Test | Description |
|------|-------------|
| `` ` `` | backtick in code |
| ``` | ``` | pipe in triple backtick code |
| `a|b|c` | multiple pipes |
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| Test | Description |
|------|-------------|
| `|` | backtick code with pipe |
| $|$ | latex span with pipe |
| `a|b` | more code |
| $x|y$ | more math |
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| `|` | normal text | `a|b` |
| regular | `||` | more text |
| `x | y` | text | `|>` |
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| $|$ | normal text | $a|b$ |
| regular | $||$ | more text |
| $x | y$ | text | $|>$ |
42 changes: 38 additions & 4 deletions crates/tree-sitter-qmd/tree-sitter-markdown/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,21 +454,47 @@ module.exports = grammar({
),
),

// Code span within pipe table cells - simplified version that only handles backticks
_pipe_table_code_span: $ => seq(
$._code_span_start,
repeat(choice(
$._word,
$._whitespace,
common.punctuation_without($, []),
)),
$._code_span_close,
),

// Latex span within pipe table cells - simplified version that only handles dollar signs
_pipe_table_latex_span: $ => seq(
$._latex_span_start,
repeat(choice(
$._word,
$._whitespace,
common.punctuation_without($, []),
)),
$._latex_span_close,
),

_pipe_table_cell_contents: $ => prec.right(
seq(
choice(
$._word,
$._display_math_state_track_marker,
$._inline_math_state_track_marker,
$._display_math_state_track_marker,
$._inline_math_state_track_marker,
$._backslash_escape,
$._pipe_table_code_span,
$._pipe_table_latex_span,
common.punctuation_without($, ['|']),
),
repeat(choice(
$._word,
$._display_math_state_track_marker,
$._inline_math_state_track_marker,
$._display_math_state_track_marker,
$._inline_math_state_track_marker,
$._whitespace,
$._backslash_escape,
$._pipe_table_code_span,
$._pipe_table_latex_span,
common.punctuation_without($, ['|']),
)))),

Expand Down Expand Up @@ -569,6 +595,14 @@ module.exports = grammar({
// special tokens to allow external scanner serialization to happen
$._display_math_state_track_marker,
$._inline_math_state_track_marker,

// code span delimiters for parsing pipe table cells
$._code_span_start,
$._code_span_close,

// latex span delimiters for parsing pipe table cells
$._latex_span_start,
$._latex_span_close,
],
precedences: $ => [
[$._setext_heading1, $._block],
Expand Down
Loading