markdown
markdown copied to clipboard
Non-breaking space causing issues with certain combinations of text
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)
If you copy and paste them on the markdown tester, it renders as in this image

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.