From 9e25ab2e96fe2c455b20365c6a6d26816ec0da0e Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Mon, 18 Jan 2021 09:03:58 -0300 Subject: [PATCH] FEATURE: Replace single dash arrows when the typographer is enabled. (#11730) --- .../discourse/tests/unit/lib/pretty-text-test.js | 2 ++ .../engines/discourse-markdown/typographer-arrows.js | 6 +++--- 2 files changed, 5 insertions(+), 3 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 3c7718eef72..c584911dcee 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 @@ -1566,6 +1566,8 @@ var bar = 'bar'; enabledTypographer, "

\u2192 \u2190

" ); + assert.cookedOptions("a -> b", enabledTypographer, "

a \u2192 b

"); + assert.cookedOptions("a <- b", enabledTypographer, "

a \u2190 b

"); assert.cookedOptions("a --> b", enabledTypographer, "

a \u2192 b

"); assert.cookedOptions("-->", enabledTypographer, "

\u2192

"); assert.cookedOptions("<--", enabledTypographer, "

\u2190

"); diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/typographer-arrows.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/typographer-arrows.js index cccea6d47ca..b63f52f8969 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/typographer-arrows.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/typographer-arrows.js @@ -6,7 +6,7 @@ function replaceArrows(state) { continue; } - const arrowsRegexp = /-->|<--/; + const arrowsRegexp = /-->|<--|->|<-/; if (arrowsRegexp.test(token.content)) { for (let ci = 0; ci < token.children.length; ci++) { let child = token.children[ci]; @@ -14,8 +14,8 @@ function replaceArrows(state) { if (child.type === "text") { if (arrowsRegexp.test(child.content)) { child.content = child.content - .replace(/(^|\s)-->(\s|$)/gm, "\u0020\u2192\u0020") - .replace(/(^|\s)<--(\s|$)/gm, "\u0020\u2190\u0020"); + .replace(/(^|\s)-{1,2}>(\s|$)/gm, "\u0020\u2192\u0020") + .replace(/(^|\s)<-{1,2}(\s|$)/gm, "\u0020\u2190\u0020"); } } }