chapterDocument method

Document? chapterDocument(
  1. EpubChapter? chapter
)

Implementation

dom.Document? chapterDocument(EpubChapter? chapter) {
  if (chapter == null) {
    return null;
  }
  final html = chapter.HtmlContent!.replaceAllMapped(
      RegExp(r'<\s*([^\s>]+)([^>]*)\/\s*>'),
      (match) => '<${match.group(1)}${match.group(2)}></${match.group(1)}>');
  final regExp = RegExp(
    r'<body.*?>.+?</body>',
    caseSensitive: false,
    multiLine: true,
    dotAll: true,
  );
  final matches = regExp.firstMatch(html);

  return matches != null ? parse(matches.group(0)!) : null;
}