From ccc44baa10294c7582246edec973cdf2b0445103 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Mon, 22 Mar 2021 15:04:08 -0300 Subject: [PATCH] =?UTF-8?q?FEATURE:=20Add=20a=20typographer=20rule=20to=20?= =?UTF-8?q?replace=20(pa)=20with=20=C2=B6.=20(#12478)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discourse/tests/unit/lib/pretty-text-test.js | 1 + .../custom-typographer-replacements.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js index 86e2fd72d75..995d96cef96 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js @@ -1625,6 +1625,7 @@ var bar = 'bar'; "

!!! ??? ,

" ); assert.cookedOptions("(tm) (TM)", enabledTypographer, "

™ ™

"); + assert.cookedOptions("(pa) (PA)", enabledTypographer, "

¶ ¶

"); }); test("default typhographic replacements - dashes", function (assert) { diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/custom-typographer-replacements.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/custom-typographer-replacements.js index 220e75fe275..5ac02093bde 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/custom-typographer-replacements.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/custom-typographer-replacements.js @@ -6,6 +6,7 @@ // ???????? → ???, !!!!! → !!!, `,,` → `,` // -- → –, --- → — // --> <-- -> <- 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); } } }