Skip to content

Commit c1866d9

Browse files
nwellnhofkevinbackhouse
authored andcommitted
Fix parsing of emphasis before links
Fix a regression introduced with commit ed0a4bf. Also test the first delimiter against stack_bottom in process_emphasis. This happened to work with the old code and only resulted in an unnecessary scan. Fixes commonmark#424.
1 parent 75008f1 commit c1866d9

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/inlines.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ static cmark_syntax_extension *get_extension_for_special_char(cmark_parser *pars
640640
}
641641

642642
static void process_emphasis(cmark_parser *parser, subject *subj, bufsize_t stack_bottom) {
643-
delimiter *closer = subj->last_delim;
643+
delimiter *candidate;
644+
delimiter *closer = NULL;
644645
delimiter *opener;
645646
delimiter *old_closer;
646647
bool opener_found;
@@ -657,10 +658,10 @@ static void process_emphasis(cmark_parser *parser, subject *subj, bufsize_t stac
657658
}
658659

659660
// move back to first relevant delim.
660-
while (closer != NULL &&
661-
closer->previous != NULL &&
662-
closer->previous->position >= stack_bottom) {
663-
closer = closer->previous;
661+
candidate = subj->last_delim;
662+
while (candidate != NULL && candidate->position >= stack_bottom) {
663+
closer = candidate;
664+
candidate = candidate->previous;
664665
}
665666

666667
// now move forward, looking for closers, and handling each

test/regression.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,11 @@ Hello world
366366
.
367367
<p>Hello world</p>
368368
````````````````````````````````
369+
370+
Issue #424 - emphasis before links
371+
372+
```````````````````````````````` example
373+
*text* [link](#section)
374+
.
375+
<p><em>text</em> <a href="#section">link</a></p>
376+
````````````````````````````````

0 commit comments

Comments
 (0)