MarkdownStrip: Support all languages

We were only supporting English, and even if we use the regexp \w, that
seems to only work for English and not all languages.
This commit is contained in:
Vishesh Handa
2020-06-19 13:09:25 +02:00
parent a22f5ae758
commit 215f12d4d8
2 changed files with 18 additions and 12 deletions

View File

@ -1,16 +1,11 @@
import 'dart:convert';
import 'dart:core';
var _regExp = RegExp('[a-zA-Z0-9]');
String stripMarkdownFormatting(String markdown) {
var output = StringBuffer();
var lines = LineSplitter.split(markdown);
for (var line in lines) {
if (!line.contains(_regExp)) {
continue;
}
line = line.trim();
if (line.startsWith('#')) {
line = line.replaceAll('#', '');
@ -24,7 +19,7 @@ String stripMarkdownFormatting(String markdown) {
output.write(' ');
}
return output.toString();
return output.toString().trimRight();
}
String replaceMarkdownChars(String line) {

View File

@ -16,7 +16,7 @@ Hello
""";
expect(stripMarkdownFormatting(input), 'Test Header Hello');
});
}, skip: true);
test('Itemized LIsts', () {
var input = """Itemized lists
@ -53,5 +53,16 @@ look like:
expect(stripMarkdownFormatting(input),
'Itemized lists • this one • that one • four');
});
test('Russian Sentence', () {
var input = "Не́которые иностра́нцы ду́мают";
expect(stripMarkdownFormatting(input), input);
});
test('Russian Word', () {
var input = "Не́которые";
expect(stripMarkdownFormatting(input), input);
});
});
}