|
|
@ -36,26 +36,26 @@ function replaceScopedAbbr(str) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function replace(state) { |
|
|
|
var i, token, text, inlineTokens, blkIdx; |
|
|
|
|
|
|
|
if (!state.md.options.typographer) { return; } |
|
|
|
|
|
|
|
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { |
|
|
|
|
|
|
|
if (state.tokens[blkIdx].type !== 'inline') { continue; } |
|
|
|
|
|
|
|
inlineTokens = state.tokens[blkIdx].children; |
|
|
|
function replace_scoped(inlineTokens) { |
|
|
|
var i, token; |
|
|
|
|
|
|
|
for (i = inlineTokens.length - 1; i >= 0; i--) { |
|
|
|
token = inlineTokens[i]; |
|
|
|
if (token.type === 'text') { |
|
|
|
text = token.content; |
|
|
|
token.content = replaceScopedAbbr(token.content); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
text = replaceScopedAbbr(text); |
|
|
|
function replace_rare(inlineTokens) { |
|
|
|
var i, token; |
|
|
|
|
|
|
|
if (RARE_RE.test(text)) { |
|
|
|
text = text.replace(/\+-/g, '±') |
|
|
|
for (i = inlineTokens.length - 1; i >= 0; i--) { |
|
|
|
token = inlineTokens[i]; |
|
|
|
if (token.type === 'text') { |
|
|
|
if (RARE_RE.test(token.content)) { |
|
|
|
token.content = token.content |
|
|
|
.replace(/\+-/g, '±') |
|
|
|
// .., ..., ....... -> …
|
|
|
|
// but ?..... & !..... -> ?.. & !..
|
|
|
|
.replace(/\.{2,}/g, '…').replace(/([?!])…/g, '$1..') |
|
|
@ -66,9 +66,27 @@ module.exports = function replace(state) { |
|
|
|
.replace(/(^|\s)--(\s|$)/mg, '$1\u2013$2') |
|
|
|
.replace(/(^|[^-\s])--([^-\s]|$)/mg, '$1\u2013$2'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = function replace(state) { |
|
|
|
var blkIdx; |
|
|
|
|
|
|
|
if (!state.md.options.typographer) { return; } |
|
|
|
|
|
|
|
for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { |
|
|
|
|
|
|
|
token.content = text; |
|
|
|
if (state.tokens[blkIdx].type !== 'inline') { continue; } |
|
|
|
|
|
|
|
if (SCOPED_ABBR_RE.test(state.tokens[blkIdx].content)) { |
|
|
|
replace_scoped(state.tokens[blkIdx].children); |
|
|
|
} |
|
|
|
|
|
|
|
if (RARE_RE.test(state.tokens[blkIdx].content)) { |
|
|
|
replace_rare(state.tokens[blkIdx].children); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|