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

As `--` is converted to an en-dash, we need to make an en-dash plus
another `-` into an em-dash.
This commit is contained in:
Renato Atilio
2025-03-12 22:22:08 -03:00
committed by GitHub
parent d1b63e3056
commit 9b692ede96
2 changed files with 7 additions and 4 deletions

View File

@ -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")
)
);
},
},

View File

@ -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