From 9ac5ec778d7d72c8ac02a81b2e430479b7380302 Mon Sep 17 00:00:00 2001 From: "Kyle E. Mitchell" Date: Sun, 7 Mar 2021 21:40:53 -0800 Subject: [PATCH] Support switching rare and scoped typographer replacements --- lib/rules_core/replacements.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/rules_core/replacements.js b/lib/rules_core/replacements.js index 533496f..4080314 100644 --- a/lib/rules_core/replacements.js +++ b/lib/rules_core/replacements.js @@ -85,21 +85,25 @@ function replace_rare(inlineTokens) { } } - module.exports = function replace(state) { var blkIdx; + var typographerOption = state.md.options.typographer; + + if (!typographerOption) { return; } - if (!state.md.options.typographer) { return; } + var optionIsObject = typeof typographerOption === 'object'; + var replaceRare = !optionIsObject || typographerOption.rare; + var replaceIP = !optionIsObject || typographerOption.intellectualProperty; for (blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--) { if (state.tokens[blkIdx].type !== 'inline') { continue; } - if (SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) { + if (replaceIP && SCOPED_ABBR_TEST_RE.test(state.tokens[blkIdx].content)) { replace_scoped(state.tokens[blkIdx].children); } - if (RARE_RE.test(state.tokens[blkIdx].content)) { + if (replaceRare && RARE_RE.test(state.tokens[blkIdx].content)) { replace_rare(state.tokens[blkIdx].children); }