private static List <EpubChapter> LoadChaptersFromNcx(string ncxAbsolutePath, IEnumerable <NcxNavPoint> navigationPoints, EpubChapter parentChapter = null) { var result = new List <EpubChapter>(); var previous = parentChapter; foreach (var navigationPoint in navigationPoints) { var chapter = new EpubChapter { Title = navigationPoint.NavLabelText, Parent = parentChapter, Previous = previous }; if (previous != null) { previous.Next = chapter; } var href = new Href(navigationPoint.ContentSrc); chapter.RelativePath = href.Path; chapter.AbsolutePath = href.Path.ToAbsolutePath(ncxAbsolutePath); chapter.HashLocation = href.HashLocation; chapter.SubChapters = LoadChaptersFromNcx(ncxAbsolutePath, navigationPoint.NavPoints, chapter); result.Add(chapter); previous = chapter.SubChapters.Any() ? chapter.SubChapters.Last() : chapter; } return(result); }
private static List <EpubChapter> LoadChaptersFromNav(XElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var ns = element.Name.Namespace; var result = new List <EpubChapter>(); var ol = element.Element(ns + NavElements.Ol); if (ol == null) { return(result); } foreach (var li in ol.Elements(ns + NavElements.Li)) { var chapter = new EpubChapter(); var link = li.Element(ns + NavElements.A); if (link != null) { var url = link.Attribute("href")?.Value; if (url != null) { chapter.ContentSrc = url; var href = new Href(url); chapter.FileName = href.Filename; chapter.Anchor = href.Anchor; } var titleTextElement = li.Descendants().FirstOrDefault(e => !string.IsNullOrWhiteSpace(e.Value)); if (titleTextElement != null) { chapter.Title = titleTextElement.Value; } if (li.Element(ns + NavElements.Ol) != null) { chapter.SubChapters = LoadChaptersFromNav(li); } result.Add(chapter); } } return(result); }
private static List <EpubChapter> LoadChaptersFromNcx(IEnumerable <NcxNavPoint> navigationPoints) { var result = new List <EpubChapter>(); foreach (var navigationPoint in navigationPoints) { var chapter = new EpubChapter { Title = navigationPoint.NavLabelText }; var href = new Href(navigationPoint.ContentSrc); chapter.FileName = href.Filename; chapter.Anchor = href.Anchor; chapter.SubChapters = LoadChaptersFromNcx(navigationPoint.NavPoints); result.Add(chapter); } return(result); }
private OpfSpineItemRef toSpineItem(EpubChapter chapter) { var items = chapter.SubChapters != null && chapter.SubChapters.Any() ? chapter.SubChapters.Select(x => toSpineItem(x)).ToList() : new List <OpfSpineItemRef>(); return(new OpfSpineItemRef(chapter.Id, chapter.ContentSrc, chapter.Title, items)); }
private static List <EpubChapter> LoadChaptersFromNav(string navAbsolutePath, XElement element, EpubChapter parentChapter = null) { if (element == null) { throw new ArgumentNullException(nameof(element)); } var ns = element.Name.Namespace; var result = new List <EpubChapter>(); var previous = parentChapter; var ol = element.Element(ns + NavElements.Ol); if (ol == null) { return(result); } foreach (var li in ol.Elements(ns + NavElements.Li)) { var chapter = new EpubChapter { Parent = parentChapter, Previous = previous }; if (previous != null) { previous.Next = chapter; } var link = li.Element(ns + NavElements.A); if (link != null) { var id = link.Attribute("id")?.Value; if (id != null) { chapter.Id = id; } var url = link.Attribute("href")?.Value; if (url != null) { var href = new Href(url); chapter.RelativePath = href.Path; chapter.HashLocation = href.HashLocation; chapter.AbsolutePath = chapter.RelativePath.ToAbsolutePath(navAbsolutePath); } var titleTextElement = li.Descendants().FirstOrDefault(e => !string.IsNullOrWhiteSpace(e.Value)); if (titleTextElement != null) { chapter.Title = titleTextElement.Value; } if (li.Element(ns + NavElements.Ol) != null) { chapter.SubChapters = LoadChaptersFromNav(navAbsolutePath, li, chapter); } result.Add(chapter); previous = chapter.SubChapters.Any() ? chapter.SubChapters.Last() : chapter; } } return(result); }