Browse Source

Fixed punctuation check in emphasis

pull/41/head
Vitaly Puzrin 9 years ago
parent
commit
c2312d971f
  1. 51
      lib/common/utils.js
  2. 11
      lib/rules_inline/emphasis.js
  3. 31
      lib/rules_inline/text.js
  4. 8
      test/fixtures/markdown-it/commonmark_extras.txt

51
lib/common/utils.js

@ -41,7 +41,7 @@ function arrayReplaceAt(src, pos, newElements) {
////////////////////////////////////////////////////////////////////////////////
var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~])/g;
function unescapeMd(str) {
if (str.indexOf('\\') < 0) { return str; }
@ -223,6 +223,54 @@ function isPunctChar(char) {
return BMP_PUNCT_RE.test(char);
}
// Markdown ASCII punctuation characters.
//
// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
// http://spec.commonmark.org/0.15/#ascii-punctuation-character
//
// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range.
//
function isMdAsciiPunct(ch) {
switch (ch) {
case 0x21/* ! */:
case 0x22/* " */:
case 0x23/* # */:
case 0x24/* $ */:
case 0x25/* % */:
case 0x26/* & */:
case 0x27/* ' */:
case 0x28/* ( */:
case 0x29/* ) */:
case 0x2A/* * */:
case 0x2B/* + */:
case 0x2C/* , */:
case 0x2D/* - */:
case 0x2E/* . */:
case 0x2F/* / */:
case 0x3A/* : */:
case 0x3B/* ; */:
case 0x3C/* < */:
case 0x3D/* = */:
case 0x3E/* > */:
case 0x3F/* ? */:
case 0x40/* @ */:
case 0x5B/* [ */:
case 0x5C/* \ */:
case 0x5D/* ] */:
case 0x5E/* ^ */:
case 0x5F/* _ */:
case 0x60/* ` */:
case 0x7B/* { */:
case 0x7C/* | */:
case 0x7D/* } */:
case 0x7E/* ~ */:
return true;
default:
return false;
}
}
////////////////////////////////////////////////////////////////////////////////
exports.assign = assign;
@ -236,5 +284,6 @@ exports.escapeHtml = escapeHtml;
exports.arrayReplaceAt = arrayReplaceAt;
exports.normalizeLink = normalizeLink;
exports.isWhiteSpace = isWhiteSpace;
exports.isMdAsciiPunct = isMdAsciiPunct;
exports.isPunctChar = isPunctChar;
exports.escapeRE = escapeRE;

11
lib/rules_inline/emphasis.js

@ -2,8 +2,9 @@
'use strict';
var isWhiteSpace = require('../common/utils').isWhiteSpace;
var isPunctChar = require('../common/utils').isPunctChar;
var isWhiteSpace = require('../common/utils').isWhiteSpace;
var isPunctChar = require('../common/utils').isPunctChar;
var isMdAsciiPunct = require('../common/utils').isMdAsciiPunct;
function isAlphaNum(code) {
@ -31,8 +32,10 @@ function scanDelims(state, start) {
nextChar = pos < max ? state.src.charCodeAt(pos) : -1;
isLastPunctChar = lastChar >= 0 && isPunctChar(String.fromCharCode(lastChar));
isNextPunctChar = nextChar >= 0 && isPunctChar(String.fromCharCode(nextChar));
isLastPunctChar = lastChar >= 0 &&
(isMdAsciiPunct(lastChar) || isPunctChar(String.fromCharCode(lastChar)));
isNextPunctChar = nextChar >= 0 &&
(isMdAsciiPunct(nextChar) || isPunctChar(String.fromCharCode(nextChar)));
isLastWhiteSpace = lastChar >= 0 && isWhiteSpace(lastChar);
isNextWhiteSpace = nextChar >= 0 && isWhiteSpace(nextChar);

31
lib/rules_inline/text.js

@ -7,30 +7,35 @@
// Rule to skip pure text
// '{}$%@~+=:' reserved for extentions
// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~
// !!!! Don't confuse with "Markdown ASCII Punctuation" chars
// http://spec.commonmark.org/0.15/#ascii-punctuation-character
function isTerminatorChar(ch) {
switch (ch) {
case 0x0A/* \n */:
case 0x5C/* \ */:
case 0x60/* ` */:
case 0x2A/* * */:
case 0x5F/* _ */:
case 0x5E/* ^ */:
case 0x5B/* [ */:
case 0x5D/* ] */:
case 0x21/* ! */:
case 0x23/* # */:
case 0x24/* $ */:
case 0x25/* % */:
case 0x26/* & */:
case 0x2A/* * */:
case 0x2B/* + */:
case 0x2D/* - */:
case 0x3A/* : */:
case 0x3C/* < */:
case 0x3D/* = */:
case 0x3E/* > */:
case 0x40/* @ */:
case 0x5B/* [ */:
case 0x5C/* \ */:
case 0x5D/* ] */:
case 0x5E/* ^ */:
case 0x5F/* _ */:
case 0x60/* ` */:
case 0x7B/* { */:
case 0x7D/* } */:
case 0x24/* $ */:
case 0x25/* % */:
case 0x40/* @ */:
case 0x7E/* ~ */:
case 0x2B/* + */:
case 0x3D/* = */:
case 0x3A/* : */:
return true;
default:
return false;

8
test/fixtures/markdown-it/commonmark_extras.txt

@ -52,6 +52,14 @@ Issue #55:
.
Issue #35. `<` shoud work as punctuation
.
an **(:**<br>
.
<p>an <strong>(:</strong><br></p>
.
Should unescape only needed things in link destinations/titles:
.
[test](<\f\o\o\>\\>)

Loading…
Cancel
Save