FEATURE: Add a typographer rule to replace (pa) with ¶. (#12478)

This commit is contained in:
Roman Rizzi 2021-03-22 15:04:08 -03:00 committed by GitHub
parent 4e46732346
commit ccc44baa10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -1625,6 +1625,7 @@ var bar = 'bar';
"<p>!!! ??? ,</p>"
);
assert.cookedOptions("(tm) (TM)", enabledTypographer, "<p>™ ™</p>");
assert.cookedOptions("(pa) (PA)", enabledTypographer, "<p>¶ ¶</p>");
});
test("default typhographic replacements - dashes", function (assert) {

View File

@ -6,6 +6,7 @@
// ???????? → ???, !!!!! → !!!, `,,` → `,`
// -- → &ndash;, --- → &mdash;
// --> <-- -> <- to → ← → ←
// (pa) (PA) → ¶
//
// Disabled replacements:
//
@ -14,7 +15,16 @@
// (p) (P) -> §
let RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--|-->|<--|->|<-/;
let SCOPED_ABBR_RE = /\((tm)\)/gi;
let SCOPED_ABBR_RE = /\((tm|pa)\)/gi;
let SCOPED_ABBR = {
pa: "¶",
tm: "™",
};
function replaceFn(match, name) {
return SCOPED_ABBR[name.toLowerCase()];
}
function replaceScoped(inlineTokens) {
let i, token;
@ -22,9 +32,7 @@ function replaceScoped(inlineTokens) {
for (i = inlineTokens.length - 1; i >= 0; i--) {
token = inlineTokens[i];
if (token.type === "text") {
token.content = token.content.replace(SCOPED_ABBR_RE, () => {
return "™";
});
token.content = token.content.replace(SCOPED_ABBR_RE, replaceFn);
}
}
}