Skip to content

A platform for community discussion. Free, open, simple.

UX: make an em-dash from en-dash plus hyphen on rich editor (#31787)

Renato Atilio9b692ede9603
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/typographer-replacements.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/typographer-replacements.js
index bde087fe6ab..16c23fd14dd 100644
--- a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/typographer-replacements.js
+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/typographer-replacements.js
@@ -25,12 +25,15 @@ const extension = {
},
},
{
- match: new RegExp(`(${SCOPED_ABBR_RE.source})$`, "i"),
+ // existing for markdown-it, plus: en-dash + hyphen -> em-dash
+ match: new RegExp(`(${SCOPED_ABBR_RE.source}|\u2013-)$`, "i"),
handler: (state, match, start, end) => {
return state.tr.replaceWith(
start,
end,
- state.schema.text(replaceScopedStr(match[0]))
+ state.schema.text(
+ replaceScopedStr(match[0]).replace(/\u2013-$/, "\u2014")
+ )
);
},
},
diff --git a/spec/system/composer/prosemirror_editor_spec.rb b/spec/system/composer/prosemirror_editor_spec.rb
index 611e75f6797..5246d0c0ed1 100644
--- a/spec/system/composer/prosemirror_editor_spec.rb
+++ b/spec/system/composer/prosemirror_editor_spec.rb
@@ -130,12 +130,12 @@ describe "Composer - ProseMirror editor", type: :system do
it "supports typographer replacements" do
open_composer_and_toggle_rich_editor
composer.type_content(
- "foo +- bar... test???? wow!!!! x,, y-- a--> b<-- c-> d<- e<-> f<--> (tm) (pa)",
+ "foo +- bar... test???? wow!!!! x,, y-- --- a--> b<-- c-> d<- e<-> f<--> (tm) (pa)",
)
expect(rich).to have_css(
"p",
- text: "foo ± bar… test??? wow!!! x, y– a–> b←- c→ d← e←> f←→ ™ ¶",
+ text: "foo ± bar… test??? wow!!! x, y– — a–> b←- c→ d← e←> f←→ ™ ¶",
)
end
end