markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Non-breaking space causing issues with certain combinations of text

Open KevinTheGray opened this issue 6 years ago • 0 comments

This is using version 2.0.3

Take these two lines: 'X: Text' 'X: Text'

Visually they look the same, however the top one uses a non-breaking space, and the bottom is just a normal space. (Github may remove the nonbreaking space)

Screen Shot 2019-05-14 at 4 38 01 PM

If you copy and paste them on the markdown tester, it renders as in this image Screen Shot 2019-05-14 at 4 33 09 PM

I built this simple main.dart that demonstrates what's happening:


void debugString(String line) {
  for (final rune in line.runes) {
    print(rune);
  }
}

void debugElement(Element element) {
  print(element.tag);
  for (final child in element.children) {
    if (child is Text) {
      print(child.text);
    } else if (child is Element) {
      debugElement(child);
    }
  }
}

void markdownDebug(String line) {
  debugString(line);
  final document = Document(encodeHtml: false);
  final List<Node> children =
  document.parseLines([line]);
  debugElement(children[0] as Element);
}

main() {
  print('=========');
  print('With U+A0');
  print('=========');
  markdownDebug('*X:* Text');
  print('============');
  print('Without U+A0');
  print('============');
  markdownDebug('*X:* Text');
}

Which gives the following output

=========
With U+A0
=========
42
88
58
42
160
84
101
120
116
p
*
X:* Text
============
Without U+A0
============
42
88
58
42
32
84
101
120
116
p
em
X:
 Text

This is pretty easy to work around with a find/replace... but some users must be using some editor that uses non-breaking spaces, and it took us a little bit to figure out what was going on.

KevinTheGray avatar May 14 '19 20:05 KevinTheGray