28

Related to Two hyphens get changed to a long dash in titles (-- vs -)

HTML comments in titles look broken, with the opening "<!—" being converted to an em-dash, while the closing "-->" remains valid.

Putting aside the discussion on whether smart quotes in a programming site is a bad idea or a terrible idea, this just looks ugly and inconsistent.

Stack Overflow question for example: Confused about <!-- ko if: $parent.name == name --> in knockout js

2
  • To the Stack Overflow Team: If we type the title one way, we want it that way. Please don't change our titles. :)
    – Eb946207
    Commented Jan 14, 2019 at 1:05
  • 1
    Also, you can fix this problem by inserting a zero width non-joiner in between the two characters.
    – Eb946207
    Commented Jan 14, 2019 at 1:17

1 Answer 1

20

The client-side code causing the error is a regex looking for 2-3 dashes and a space:

e=e.replace(/---?(\s)/g,"—$1")

It can be corrected to also require a space before the dashes:

e=e.replace(/(\s)---?(\s)/g,"$1—$2")

This will also resolve cases like i--.

From a quick check in the data explorer, it looks like in most people do place spaces on both sides for emdashes: https://data.stackexchange.com/stackoverflow/query/edit/730462

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .