Exemplo n.º 1
0
        public static string FixupUrl(string uri, string itemPath, Dictionary <string, string> newAbsolutePaths)
        {
            // special case, it's a link to anchor on same page
            if (uri[0] == '#')
            {
                return(uri);
            }

            // internal URLs are relative, so, if not relative
            // leave it alone
            Uri testUrl = null;

            if (!Uri.TryCreate(uri, UriKind.Relative, out testUrl))
            {
                return(uri);
            }

            var    fragments       = uri.Split(new char[] { '#' });
            var    path            = fragments[0];
            var    urlAbsolutePath = ZipUtils.RelativePathToAbsolute(itemPath, path);
            string newAbsolutePath = null;

            if (!newAbsolutePaths.TryGetValue(urlAbsolutePath, out newAbsolutePath))
            {
                // URL isn't in set to update
                return(uri);
            }
            var newRelativePath = ZipUtils.AbsolutePathToRelative(itemPath, newAbsolutePath);

            if (2 == fragments.Length)
            {
                newRelativePath += "#" + fragments[1];
            }
            return(newRelativePath);
        }
Exemplo n.º 2
0
 public XElement ToXElement(string opfFolder)
 {
     return(new XElement(Epub.PackageNs + "item",
                         new XAttribute("href", ZipUtils.AbsolutePathToRelative(opfFolder, this.AbsolutePath)),
                         new XAttribute("id", Id),
                         new XAttribute("media-type", MediaType)
                         ));
 }
Exemplo n.º 3
0
        public XElement ToXElement(string opfFolder)
        {
            string href = Item == null
                ? string.Empty
                : ZipUtils.AbsolutePathToRelative(opfFolder, Item.AbsolutePath);
            var element = new XElement(Epub.PackageNs + "reference",
                                       new XAttribute("href", href),
                                       new XAttribute("type", TypeName)
                                       );

            if (Title != null)
            {
                element.Add(new XAttribute("title", Title));
            }
            return(element);
        }
Exemplo n.º 4
0
        public void RemoveImageLink(string absolutePath)
        {
            string relativePath = ZipUtils.AbsolutePathToRelative(AbsolutePath.GetZipPath(), absolutePath);
            var    doc          = RawBytes.ToXhtml();
            bool   changed      = false;

            foreach (var element in FindImageElements(doc))
            {
                var href = element.GetImageHref();
                if (relativePath == href)
                {
                    doc.RemoveImage(element);
                    changed = true;
                }
            }
            if (changed)
            {
                RawBytes = doc.ToSBytes();
            }
        }
Exemplo n.º 5
0
        public XElement ToNavPoint(ref int playOrder, string ncxFolder)
        {
            ++playOrder;
            var navPoint = new XElement(Epub.ncxNs + "navPoint",
                                        new XAttribute("id", "body" + playOrder.ToString("D4")),
                                        new XAttribute("playOrder", playOrder),
                                        new XElement(Epub.ncxNs + "navLabel",
                                                     new XElement(Epub.ncxNs + "text", Title)
                                                     ),
                                        new XElement(Epub.ncxNs + "content",
                                                     new XAttribute("src", ZipUtils.AbsolutePathToRelative(ncxFolder, ContentSrc) + Anchor)
                                                     )
                                        );

            foreach (var e in Children)
            {
                navPoint.Add(e.ToNavPoint(ref playOrder, ncxFolder));
            }
            return(navPoint);
        }