示例#1
0
        private NavigationPoint ProcessNavPoint(
            XElement element, NavigationOrderProcessor orderProcessor, string basePath, IEnumerable <File> files)
        {
            var title = element.Elements()
                        .Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.NavLabelElementName))
                        .Elements().Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.TextElementName))
                        .Value;

            var contentText = element.Elements()
                              .Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.ContentElementName))
                              .GetAttributeValueOrNull(NcxXmlNames.SrcAttributeName) !;
            var filePath  = SrcTextSplitter.GetFileName(contentText);
            var elementId = SrcTextSplitter.GetElementId(contentText);

            var fileFullPath = EpubPathHelper.ExpandPath(basePath, filePath);
            var file         = files.Single(f => f.Path.EqualsIgnoreCaseWithNull(fileFullPath));

            var order = orderProcessor.GetOrder(element);

            var children = FilterAndSelectChildNavPoints(element, orderProcessor, basePath, files);

            return(new NavigationPoint(title, file, elementId, order, children));
        }
示例#2
0
        private NavigationPoint ProcessListItemRecursive(
            XElement listItem, NavigationOrderProcessor navigationOrderProcessor, string basePath, IEnumerable <File> files)
        {
            var linkElement = listItem.Elements()
                              .Single(element => element.Name.Equals(XmlNamespaces.XHtml + XHtmlTocXmlNames.LinkElementName));

            var title     = linkElement.Value;
            var srcPath   = linkElement.GetAttributeValueOrNull(XHtmlTocXmlNames.HrefAttributeName) !;
            var filePath  = SrcTextSplitter.GetFileName(srcPath);
            var elementId = SrcTextSplitter.GetElementId(srcPath);
            var order     = navigationOrderProcessor.GetOrder(listItem);

            var fileFullPath = EpubPathHelper.ExpandPath(basePath, filePath);
            var file         = files.Single(f => f.Path.EqualsIgnoreCaseWithNull(fileFullPath));

            var childOrderedList = listItem.Elements()
                                   .Cast <XElement?>().SingleOrDefault(
                e => e !.Name.Equals(XmlNamespaces.XHtml + XHtmlTocXmlNames.OrderedListElementName));
            var children = childOrderedList != null
                ? ProcessOrderedListRecursive(childOrderedList, navigationOrderProcessor, basePath, files).ToArray()
                : Array.Empty <NavigationPoint>();

            return(new NavigationPoint(title, file, elementId, order, children));
        }