readChapters static method
Implementation
static Future<List<EpubChapter>> readChapters(
List<EpubChapterRef> chapterRefs) async {
var result = <EpubChapter>[];
await Future.forEach(chapterRefs, (EpubChapterRef chapterRef) async {
var chapter = EpubChapter();
chapter.ContentFileName = chapterRef.ContentFileName;
chapter.Anchor = chapterRef.Anchor;
chapter.HtmlContent = await chapterRef.readHtmlContent();
var doc = chapter.HtmlContent == null ? dom.Document() : parse(chapter.HtmlContent);
chapter.Title = chapterRef.Title;
for (var node in doc.head?.children ?? []) {
if (node != null && node.localName == 'title') {
print('TITLE: ' + node.localName);
chapter.Title = node.text;
break;
}
}
chapter.Paragraphs = parseParagraphsFromDoc(doc);
print('New EPUB_PARSER: ${chapterRef.SubChapters!.length} for chap: ' +
chapterRef.ContentFileName!);
print('PARA LENGTH start: ${chapter.Paragraphs.length} for chap: ' +
chapterRef.ContentFileName!);
// chapter.SubChapters = await readChapters(chapterRef.SubChapters!);
// chapter.SubChapters?.forEach((subChapter) {
// chapter.Paragraphs.addAll(subChapter.Paragraphs);
// });
// await appendParagraphs(chapter);
print('PARA LENGTH end : ${chapter.Paragraphs.length} for chap: ' +
chapterRef.ContentFileName!);
result.add(chapter);
});
return result;
}