sapegin/richtypo.js

Richtypo removes non-breaking spaces in the original text

Closed this issue · 1 comments

  1. Consider text like this:
    обзор автомобиля Tesla
    I've put a non-breaking space between автомобиля and Tesla so that it would always end up on the same line.
  2. Rychtypo parses the text, adds   where it thinks is appropriate and completely removes the original ones I've put there.

Here is more on why invisible non-breaking space characters are cool: http://destroytoday.com/findings/fix-widows-with-non-breaking-spaces/

Turns out, it was not Richtypo but Marked markdown parser (Lexer inside it) that removed the non-breaking space:

Lexer.prototype.lex = function(src) {
  src = src
    .replace(/\r\n|\r/g, '\n')
    .replace(/\t/g, '    ')
    .replace(/\u00a0/g, ' ')
    .replace(/\u2424/g, '\n');

  return this.token(src, true);
};

This is where the devil hides: .replace(/\u00a0/g, ' ').

Sorry for the trouble.