mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
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:
@ -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) {
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user