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 /js | |
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 'js')
-rw-r--r-- | js/lib/inlines.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/js/lib/inlines.js b/js/lib/inlines.js index b9bf805..79d2c90 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -87,8 +87,6 @@ var reFinalSpace = / *$/; var reInitialSpace = /^ */; -var reAsciiAlnum = /[a-z0-9]/i; - var reLinkLabel = /^\[(?:[^\\\[\]]|\\[\[\]]){0,1000}\]/; // Matches a string of non-special characters. @@ -238,6 +236,7 @@ var scanDelims = function(cc) { var numdelims = 0; var char_before, char_after, cc_after; var startpos = this.pos; + var left_flanking, right_flanking, can_open, can_close; char_before = this.pos === 0 ? '\n' : this.subject.charAt(this.pos - 1); @@ -254,17 +253,22 @@ var scanDelims = function(cc) { char_after = fromCodePoint(cc_after); } - var can_open = numdelims > 0 && !(reWhitespaceChar.test(char_after)) && + left_flanking = numdelims > 0 && + !(reWhitespaceChar.test(char_after)) && !(rePunctuation.test(char_after) && !(/\s/.test(char_before)) && !(rePunctuation.test(char_before))); - var can_close = numdelims > 0 && !(reWhitespaceChar.test(char_before)) && + right_flanking = numdelims > 0 && + !(reWhitespaceChar.test(char_before)) && !(rePunctuation.test(char_before) && !(reWhitespaceChar.test(char_after)) && !(rePunctuation.test(char_after))); if (cc === C_UNDERSCORE) { - can_open = can_open && !((reAsciiAlnum).test(char_before)); - can_close = can_close && !((reAsciiAlnum).test(char_after)); + can_open = left_flanking && !right_flanking; + can_close = right_flanking && !left_flanking; + } else { + can_open = left_flanking; + can_close = right_flanking; } this.pos = startpos; return { numdelims: numdelims, |