Skip to content

Commit 395aaa0

Browse files
committed
Fix spoiler parsing in table boundary detection.
Made-with: Cursor
1 parent 3e837d1 commit 395aaa0

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/md4c.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,8 +2599,6 @@ md_opener_stack(MD_CTX* ctx, int mark_index)
25992599

26002600
case _T('~'): return (mark->end - mark->beg == 1) ? &TILDE_OPENERS_1 : &TILDE_OPENERS_2;
26012601

2602-
case _T('|'): return &PIPE_OPENERS;
2603-
26042602
case _T('!'):
26052603
case _T('['): return &BRACKET_OPENERS;
26062604

@@ -3858,11 +3856,6 @@ md_analyze_pipe(MD_CTX* ctx, int mark_index)
38583856
{
38593857
MD_MARK* mark = &ctx->marks[mark_index];
38603858

3861-
/* Only 2-char || marks are spoiler delimiters; single | is a table boundary
3862-
* or wiki-link separator. */
3863-
if(mark->end - mark->beg != 2)
3864-
return;
3865-
38663859
if((mark->flags & MD_MARK_POTENTIAL_CLOSER) && PIPE_OPENERS.top >= 0) {
38673860
int opener_index = PIPE_OPENERS.top;
38683861

@@ -4108,12 +4101,6 @@ md_analyze_marks(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines,
41084101
case '!': /* Pass through. */
41094102
case ']': md_analyze_bracket(ctx, i); break;
41104103
case '&': md_analyze_entity(ctx, i); break;
4111-
case '|':
4112-
if(ctx->marks[i].end - ctx->marks[i].beg == 2)
4113-
md_analyze_pipe(ctx, i);
4114-
else
4115-
md_analyze_table_cell_boundary(ctx, i);
4116-
break;
41174104
case '_': /* Pass through. */
41184105
case '*': md_analyze_emph(ctx, i); break;
41194106
case '~': md_analyze_tilde(ctx, i); break;
@@ -4138,6 +4125,7 @@ md_analyze_marks(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines,
41384125
static int
41394126
md_analyze_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines, int table_mode)
41404127
{
4128+
int i;
41414129
int ret;
41424130

41434131
/* Reset the previously collected stack of marks. */
@@ -4157,7 +4145,12 @@ md_analyze_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines, int table
41574145
/* (2) Analyze table cell boundaries. */
41584146
MD_ASSERT(n_lines == 1);
41594147
ctx->n_table_cell_boundaries = 0;
4160-
md_analyze_marks(ctx, lines, n_lines, 0, ctx->n_marks, _T("|"), 0);
4148+
for(i = 0; i < ctx->n_marks; i++) {
4149+
MD_MARK* mark = &ctx->marks[i];
4150+
if(!(mark->flags & MD_MARK_RESOLVED) &&
4151+
mark->ch == '|' && mark->end - mark->beg == 1)
4152+
md_analyze_table_cell_boundary(ctx, i);
4153+
}
41614154
return ret;
41624155
}
41634156

test/spec-spoiler.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,29 @@ A spoiler inside a table cell:
360360
--fspoiler --ftables
361361
````````````````````````````````
362362

363+
Spoiler parsing must not interfere with table cell boundary detection:
364+
365+
```````````````````````````````` example
366+
x
367+
|-
368+
||||||||||
369+
.
370+
<table>
371+
<thead>
372+
<tr>
373+
<th>x</th>
374+
</tr>
375+
</thead>
376+
<tbody>
377+
<tr>
378+
<td><x-spoiler></x-spoiler><x-spoiler></x-spoiler>||</td>
379+
</tr>
380+
</tbody>
381+
</table>
382+
.
383+
--fspoiler --github
384+
````````````````````````````````
385+
363386

364387
## Interaction with other extensions
365388

0 commit comments

Comments
 (0)