From 14b997d9350b3ee3f6d67fb12b470bf406d4a31b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 18 Jan 2015 10:41:54 -0800 Subject: 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. --- src/inlines.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/inlines.c') 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; } -- cgit v1.2.3