Fix example sentence missing pieces bug

This commit is contained in:
Oystein Kristoffer Tveit 2022-02-13 01:12:55 +01:00
parent cf70eea0a1
commit 202be67ebb
1 changed files with 12 additions and 3 deletions

View File

@ -92,10 +92,19 @@ List<String> _getKanjiAndKana(Element div) {
return [kanji, kana]; return [kanji, kana];
} }
List<ExampleSentencePiece> getPieces(Element sentenceElement) { Element normalizeSentenceElement(Element sentenceElement) =>
final pieceElements = sentenceElement.querySelectorAll('li.clearfix'); Element.html('<ul>' +
sentenceElement.children.first.innerHtml.replaceAllMapped(
RegExp(r'(?<=^|<\/li>)\s*([^<>]+)\s*(?=<li)'),
(match) =>
'<li class="clearfix"><span class="unlinked">${match.group(0)}</span></li>',
) +
'</ul>');
return pieceElements.map((var e) { List<ExampleSentencePiece> getPieces(Element sentenceElement) {
return normalizeSentenceElement(sentenceElement)
.querySelectorAll('li.clearfix')
.map((var e) {
final unlifted = assertNotNull( final unlifted = assertNotNull(
variable: e.querySelector('.unlinked')?.text, variable: e.querySelector('.unlinked')?.text,
errorMessage: errorMessage: