|
|
@ -15,7 +15,9 @@ |
|
|
|
// - fractionals 1/2, 1/4, 3/4 -> ½, ¼, ¾
|
|
|
|
// - miltiplication 2 x 4 -> 2 × 4
|
|
|
|
|
|
|
|
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/; |
|
|
|
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,/; |
|
|
|
|
|
|
|
var DASHES_RE = /--/; |
|
|
|
|
|
|
|
// Workaround for phantomjs - need regex without /g flag,
|
|
|
|
// or root check will fail every second time
|
|
|
@ -66,7 +68,29 @@ function replace_rare(inlineTokens) { |
|
|
|
// .., ..., ....... -> …
|
|
|
|
// but ?..... & !..... -> ?.. & !..
|
|
|
|
.replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') |
|
|
|
.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ',') |
|
|
|
.replace(/([?!]){4,}/g, '$1$1$1').replace(/,{2,}/g, ','); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (token.type === 'link_open' && token.info === 'auto') { |
|
|
|
inside_autolink--; |
|
|
|
} |
|
|
|
|
|
|
|
if (token.type === 'link_close' && token.info === 'auto') { |
|
|
|
inside_autolink++; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function replace_dashes(inlineTokens) { |
|
|
|
var i, token, inside_autolink = 0; |
|
|
|
|
|
|
|
for (i = inlineTokens.length - 1; i >= 0; i--) { |
|
|
|
token = inlineTokens[i]; |
|
|
|
|
|
|
|
if (token.type === 'text' && !inside_autolink) { |
|
|
|
if (DASHES_RE.test(token.content)) { |
|
|
|
token.content = token.content |
|
|
|
// em-dash
|
|
|
|
.replace(/(^|[^-])---(?=[^-]|$)/mg, '$1\u2014') |
|
|
|
// en-dash
|
|
|
@ -94,6 +118,7 @@ module.exports = function replace(state) { |
|
|
|
var optionIsObject = typeof typographerOption === 'object'; |
|
|
|
var replaceRare = !optionIsObject || typographerOption.rare; |
|
|
|
var replaceIP = !optionIsObject || typographerOption.intellectualProperty; |
|
|
|
var replaceDashes = !optionIsObject || typographerOption.dashes; |
|
|
|
|
|
|
|
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { |
|
|
|
|
|
|
@ -103,6 +128,10 @@ module.exports = function replace(state) { |
|
|
|
replace_scoped(state.tokens[blkIdx].children); |
|
|
|
} |
|
|
|
|
|
|
|
if (replaceDashes && DASHES_RE.test(state.tokens[blkIdx].content)) { |
|
|
|
replace_dashes(state.tokens[blkIdx].children); |
|
|
|
} |
|
|
|
|
|
|
|
if (replaceRare && RARE_RE.test(state.tokens[blkIdx].content)) { |
|
|
|
replace_rare(state.tokens[blkIdx].children); |
|
|
|
} |
|
|
|