Skip to content

Commit

Permalink
More elegant fix for #383.
Browse files Browse the repository at this point in the history
The problem arose as follows. The input was

```
*****Hello*world****
```

We have an `openers_bottom` table that limits how far back you have to
look for an opener. It is indexed to the type of delimiter (`_` or `*`)
and the length of the closing delimiter mod 3.  So after we fail to match
the opener `*****` to `*`, we set the openers_bottom for `(*, 1)` to the
location of `*`, effectively removing the `*****` as a possible opener for
any run of `*`s with a length mod 3 of 1, including the final `****` in this
example. This procedure ignores the fact that the length mod 3
restriction only matters if one of the delimiters can be both an opener
and a closer.

To fix this problem, we index the `openers_bottom` table not just to
the type of delimiter and the length of the closing delimiter mod 3,
but to whether the closing delimiter can also be an opener.
  • Loading branch information
jgm committed Jun 19, 2021
1 parent 2d8a2f8 commit 34250e1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
delimiter *old_closer;
bool opener_found;
int openers_bottom_index = 0;
delimiter *openers_bottom[6] = {stack_bottom, stack_bottom, stack_bottom,
delimiter *openers_bottom[9] = {stack_bottom, stack_bottom, stack_bottom,
stack_bottom, stack_bottom, stack_bottom,
stack_bottom, stack_bottom, stack_bottom};

// move back to first relevant delim.
Expand All @@ -667,7 +668,8 @@ static void process_emphasis(subject *subj, delimiter *stack_bottom) {
openers_bottom_index = 2;
break;
case '*':
openers_bottom_index = 3 + (closer->length % 3);
openers_bottom_index = 3 +
(closer->can_open ? 3 : 0) + (closer->length % 3);
break;
default:
assert(false);
Expand Down

0 comments on commit 34250e1

Please sign in to comment.