diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-18 10:41:54 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-18 10:47:08 -0800 |
commit | 14b997d9350b3ee3f6d67fb12b470bf406d4a31b (patch) | |
tree | b9a1416f18c27458849d48b8769c53100f55d008 /src | |
parent | b34e19cd2f32342fafd6ae76de4e537240784f71 (diff) |
Changed rule for `_` emphasis and strong emphasis.
To prevent intra-word emphasis, we used to check to see if
the delimiter was followed/preceded by an ASCII alphanumeric.
We now do something more elegant: whereas an opening `*` must
be left-flanking, an opening `_` must be left-flanking *and not
right-flanking*. And so on for the other cases.
All the original tests passed except some tests with Russian
text with internal `_`, which formerly created emphasis but no
longer do with the new rule. These tests have been adjusted.
A few new test cases have been added to illustrate the rule.
The C and JS implementations have both been updated.
Diffstat (limited to 'src')
-rw-r--r-- | src/inlines.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/inlines.c b/src/inlines.c index 2487f63..2c12408 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -250,6 +250,7 @@ scan_delims(subject* subj, unsigned char c, bool * can_open, bool * can_close) int32_t after_char = 0; int32_t before_char = 0; int len; + bool left_flanking, right_flanking; if (subj->pos == 0) { before_char = 10; @@ -277,19 +278,20 @@ scan_delims(subject* subj, unsigned char c, bool * can_open, bool * can_close) if (len == -1) { after_char = 10; } - *can_open = numdelims > 0 && !utf8proc_is_space(after_char) && + left_flanking = numdelims > 0 && !utf8proc_is_space(after_char) && !(utf8proc_is_punctuation(after_char) && !utf8proc_is_space(before_char) && !utf8proc_is_punctuation(before_char)); - *can_close = numdelims > 0 && !utf8proc_is_space(before_char) && + right_flanking = numdelims > 0 && !utf8proc_is_space(before_char) && !(utf8proc_is_punctuation(before_char) && !utf8proc_is_space(after_char) && !utf8proc_is_punctuation(after_char)); if (c == '_') { - *can_open = *can_open && !(before_char < 128 && - cmark_isalnum((char)before_char)); - *can_close = *can_close && !(before_char < 128 && - cmark_isalnum((char)after_char)); + *can_open = left_flanking && !right_flanking; + *can_close = right_flanking && !left_flanking; + } else { + *can_open = left_flanking; + *can_close = right_flanking; } return numdelims; } |