public override void GenerateBody() { base.GenerateBody(); Div page = new Div(Compatibility); page.GlobalAttributes.Class.Value = "about"; H1 heading = new H1(Compatibility); heading.Add(new SimpleHTML5Text(Compatibility) { Text = "About" }); page.Add(heading); foreach (var text in AboutTexts) { var p1 = new Paragraph(Compatibility); var text1 = new SimpleHTML5Text(Compatibility) {Text = text}; p1.Add(text1); page.Add(p1); } foreach (var text in AboutLinks) { var p1 = new Paragraph(Compatibility); var anch = new Anchor(Compatibility); anch.HRef.Value = text; anch.GlobalAttributes.Title.Value = text; var text3 = new SimpleHTML5Text(Compatibility) {Text = text}; anch.Add(text3); p1.Add(anch); page.Add(p1); } BodyElement.Add(page); }
private void AddContent() { var pageData = new Div(Compatibility); var heading = new H1(Compatibility); heading.Add(new SimpleHTML5Text(Compatibility) { Text = "Converter use license" }); pageData.Add(heading); var p1 = new Paragraph(Compatibility); p1.Add(new SimpleHTML5Text(Compatibility) { Text = "This file was generated by Lord KiRon's FB2EPUB converter." }); p1.Add(new SimpleHTML5Text(Compatibility) { Text = "(This book might contain copyrighted material, author of the converter bears no responsibility for it's usage)" }); pageData.Add(p1); var anch = new Anchor(Compatibility); p1 = new Paragraph(Compatibility); anch.Add(new SimpleHTML5Text(Compatibility) { Text = @"http://www.fb2epub.net" }); anch.HRef.Value = @"http://www.fb2epub.net"; p1.Add(anch); pageData.Add(p1); anch = new Anchor(Compatibility); p1 = new Paragraph(Compatibility); anch.Add(new SimpleHTML5Text(Compatibility) { Text = @"https://code.google.com/p/fb2epub/" }); anch.HRef.Value = @"https://code.google.com/p/fb2epub/"; p1.Add(anch); pageData.Add(p1); Content = pageData; }
/// <summary> /// Convert FB2 "notes" and "comments" and other "additional" sections /// </summary> /// <param name="linkSectionItem">item to convert</param> /// <param name="linkSectionConverterParams"></param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(SectionItem linkSectionItem,LinkSectionConverterParamsV2 linkSectionConverterParams) { if (linkSectionItem == null) { throw new ArgumentNullException("linkSectionItem"); } var content = new Div(HTMLElementType.XHTML11); var a = new Anchor(HTMLElementType.XHTML11); var titleConverter = new TitleConverterV2(); foreach (var item in titleConverter.Convert(linkSectionItem.Title,new TitleConverterParamsV2{Settings = linkSectionConverterParams.Settings,TitleLevel = 2}).SubElements()) { content.Add(item); } string newId = linkSectionConverterParams.Settings.ReferencesManager.EnsureGoodId(linkSectionItem.ID); a.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = newId }); a.HRef.Value = string.Format("{0}_back", newId); if (((string)a.HRef.Value).StartsWith("_back") == false) { SetClassType(a, ElementStylesV2.NoteAnchor); linkSectionConverterParams.Settings.ReferencesManager.AddBackReference((string)a.HRef.Value, a); //content.Add(a); } SetClassType(content, ElementStylesV2.NoteSection); return content; }
/// <summary> /// Convert FB2 internal link /// </summary> /// <param name="internalLinkItem">item to convert</param> /// <param name="compatibility"></param> /// <param name="internalLinkConverterParams"></param> /// <returns>XHTML representation</returns> public List<IHTMLItem> Convert(InternalLinkItem internalLinkItem, InternalLinkConverterParamsV2 internalLinkConverterParams) { if (internalLinkItem == null) { throw new ArgumentNullException("internalLinkItem"); } var list = new List<IHTMLItem>(); if (!string.IsNullOrEmpty(internalLinkItem.HRef) && internalLinkItem.HRef != "#") { var anchor = new Anchor(HTMLElementType.XHTML11); bool internalLink = false; if (!ReferencesUtils.IsExternalLink(internalLinkItem.HRef)) { if (internalLinkItem.HRef.StartsWith("#")) { internalLinkItem.HRef = internalLinkItem.HRef.Substring(1); } internalLinkItem.HRef = internalLinkConverterParams.Settings.ReferencesManager.EnsureGoodId(internalLinkItem.HRef); internalLink = true; } anchor.HRef.Value = internalLinkItem.HRef; if (internalLink) { internalLinkConverterParams.Settings.ReferencesManager.AddReference(internalLinkItem.HRef, anchor); } if (internalLinkItem.LinkText != null) { var tempConverter = new SimpleTextElementConverterV2(); foreach (var s in tempConverter.Convert(internalLinkItem.LinkText, new SimpleTextElementConverterParamsV2 { Settings = internalLinkConverterParams.Settings, NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop } )) { s.Parent = anchor; anchor.Add(s); } } list.Add(anchor); return list; } var converter = new SimpleTextElementConverterV2(); return converter.Convert(internalLinkItem.LinkText, new SimpleTextElementConverterParamsV2 { Settings = internalLinkConverterParams.Settings, NeedToInsertDrop = internalLinkConverterParams.NeedToInsertDrop }); }
public void AddBackReference(string reference, Anchor anchor) { if (!ReferencesUtils.IsExternalLink(reference)) // we count only "internal" references (no need for http://... ) { reference = EnsureGoodReference(reference); // make sure that reference name is valid according to HTML rules List<Anchor> list; if (!_references.ContainsKey(reference)) // if this a first time we see "jump" to this ID { list = new List<Anchor>(); //allocate new list of referenced objects _references.Add(reference, list); // add list to dictionary } else // if we already have at least one reference to this ID { list = _references[reference]; // find this ID in references dictionarry } list.Add(anchor); } }
public HTMLItem Convert(FB2File fb2File, ConverterOptionsV3 settings) { if (fb2File == null) { throw new ArgumentNullException("fb2File"); } var info = new Div(HTMLElementType.HTML5); var header = new H3(HTMLElementType.HTML5); header.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "FB2 document info" }); info.Add(header); if (fb2File.DocumentInfo != null) { if (!string.IsNullOrEmpty(fb2File.DocumentInfo.ID)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document ID: {0}", fb2File.DocumentInfo.ID) }); info.Add(p); } if (fb2File.DocumentInfo.DocumentVersion.HasValue) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document version: {0}", fb2File.DocumentInfo.DocumentVersion) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentDate != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.DocumentDate.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Document creation date: {0}", fb2File.DocumentInfo.DocumentDate.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.ProgramUsed2Create != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.ProgramUsed2Create.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("Created using: {0} software", fb2File.DocumentInfo.ProgramUsed2Create.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.SourceOCR != null) && !string.IsNullOrEmpty(fb2File.DocumentInfo.SourceOCR.Text)) { var p = new Paragraph(HTMLElementType.HTML5); p.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = string.Format("OCR Source: {0}", fb2File.DocumentInfo.SourceOCR.Text) }); info.Add(p); } if ((fb2File.DocumentInfo.DocumentAuthors != null) && (fb2File.DocumentInfo.DocumentAuthors.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document authors :" }); info.Add(heading); var authors = new UnorderedList(HTMLElementType.HTML5); foreach (var author in fb2File.DocumentInfo.DocumentAuthors) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(author) }); authors.Add(li); } info.Add(authors); } if ((fb2File.DocumentInfo.DocumentPublishers != null) && (fb2File.DocumentInfo.DocumentPublishers.Count > 0)) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document publishers :" }); info.Add(heading); var publishers = new UnorderedList(HTMLElementType.HTML5); foreach (var publisher in fb2File.DocumentInfo.DocumentPublishers) { var li = new ListItem(HTMLElementType.HTML5); li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = DescriptionConverters.GetAuthorAsSting(publisher) }); publishers.Add(li); } info.Add(publishers); } if ((fb2File.DocumentInfo.SourceURLs != null) && (fb2File.DocumentInfo.SourceURLs.Any())) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Source URLs :" }); info.Add(heading); var urls = new UnorderedList(HTMLElementType.HTML5); foreach (var url in fb2File.DocumentInfo.SourceURLs) { var li = new ListItem(HTMLElementType.HTML5); if (ReferencesUtils.IsExternalLink(url)) { var link = new Anchor(HTMLElementType.HTML5); link.HRef.Value = url; link.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); li.Add(link); } else { li.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = url }); } urls.Add(li); } info.Add(urls); } if (fb2File.DocumentInfo.History != null) { var heading = new H4(HTMLElementType.HTML5); heading.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "Document history:" }); info.Add(heading); var annotationConverter = new AnnotationConverterV3(); info.Add(annotationConverter.Convert(fb2File.DocumentInfo.History, new AnnotationConverterParamsV3 { Level = 1, Settings = settings })); //Paragraph p = new Paragraph(); //p.Add(new SimpleHTML5Text() { Text = fb2File.DocumentInfo.History.ToString() }); //info.Add(p); } } // in case there is no elements - no need for a header if (info.SubElements().Count <= 1) { info.Remove(header); } SetClassType(info, ElementStylesV3.FB2Info); return info; }
/// <summary> /// Adds reference /// Used to add hyperlinks (anchors) from one part of the document to another /// </summary> /// <param name="reference">reference name (name of the link we going to "jump to" - href)</param> /// <param name="anchor">anchor element that contains the reference (place we "jump from")</param> public void AddReference(string reference, Anchor anchor) { if (!ReferencesUtils.IsExternalLink(reference)) // we count only "internal" references (no need for http://... ) { reference = EnsureGoodReference(reference); // make sure that reference name is valid according to HTML rules List<Anchor> list; if (!_references.ContainsKey(reference)) // if this a first time we see "jump" to this ID { list = new List<Anchor>(); //allocate new list of referenced objects _references.Add(reference, list); // add list to dictionary } else // if we already have at least one reference to this ID { list = _references[reference]; // find this ID in references dictionary } if (string.IsNullOrEmpty((string)anchor.GlobalAttributes.ID.Value)) // if anchor does not have ID already (FB2 link element does not have ID so this is just in case), we need this for backlinking { string backLink = string.Format("{0}_back", reference); // generate back link if (backLink.StartsWith("#")) // most references starts with # as part of the href linking, so we need to strip this character to get valid ID { backLink = backLink.Substring(1); } while (IsIdUsed(backLink)) { backLink += "x"; } anchor.GlobalAttributes.ID.Value = backLink; } anchor.GlobalAttributes.ID.Value = AddIdUsed((string)anchor.GlobalAttributes.ID.Value, anchor); list.Add(anchor); } }
private void RemapLinkSecionReference() { foreach (var anchor in _link.Value) { BaseXHTMLFileV2 anchorDocument = GetIDParentDocument(_structureManager, anchor); // get document containing anchor pointing to target ID if (anchorDocument == null) // if anchor not contained (not found) in any document { Logger.Log.Error(string.Format("Internal consistency error - anchor ({0}) for id ({1}) not contained (not found) in any document", anchor, _linkTargetItem)); continue; } string backlinkRef; if (anchorDocument == _linkTargetDocument) // if anchor (link) and target (id) located in same document { anchor.HRef.Value = GenerateLocalLinkReference(_idString);// update reference link for an anchor, local one (without file name) backlinkRef = GenerateLocalLinkReference(anchor.GlobalAttributes.ID.Value as string); // in case we going to insert backlin - create a local reference } else // if they are located in different documents { anchor.HRef.Value = GenerateFarLinkReference(_idString, _linkTargetDocument.FileName); // update reference link for an anchor, "far" one (with, pointing to another file name) backlinkRef = GenerateFarLinkReference(anchor.GlobalAttributes.ID.Value as string, anchorDocument.FileName); // in case we going to insert backlin - create a "far" reference } var backLinkAnchor = new Anchor(_linkParentContainer.HTMLStandard); backLinkAnchor.HRef.Value = backlinkRef; backLinkAnchor.GlobalAttributes.Class.Value = ElementStylesV2.NoteAnchor; _linkParentContainer.Add(new EmptyLine(_linkParentContainer.HTMLStandard)); _linkParentContainer.Add(backLinkAnchor); _linksCount++; backLinkAnchor.Add(new SimpleHTML5Text(backLinkAnchor.HTMLStandard) { Text = (_link.Value.Count > 1) ? string.Format("(<< back {0}) ", _linksCount) : string.Format("(<< back) ") }); } }
public void RemapAnchors(EPubFileV2 epubFile) { foreach (var link in _references) { if (!ReferencesUtils.IsExternalLink(link.Key)) { string idString = ReferencesUtils.GetIdFromLink(link.Key); BaseXHTMLFileV2 iDDocument = GetIDParentDocument(epubFile, _ids[idString]); if (iDDocument != null) { int count = 0; foreach (var anchor in link.Value) { BaseXHTMLFileV2 idDocument = GetIDParentDocument(epubFile, anchor); var referencedItem = _ids[(string)anchor.HRef.Value]; var newParent = DetectParentContainer(referencedItem); if (newParent == null) { continue; } var newAnchor = new Anchor(newParent.HTMLStandard); if (idDocument == iDDocument) { anchor.HRef.Value = string.Format("#{0}", idString); newAnchor.HRef.Value = string.Format("#{0}", anchor.GlobalAttributes.ID.Value); } else { anchor.HRef.Value = string.Format("{0}#{1}", iDDocument.FileName, idString); if (idDocument == null) { continue; } newAnchor.HRef.Value = string.Format("{0}#{1}", idDocument.FileName, anchor.GlobalAttributes.ID.Value); } if (iDDocument.Type == SectionTypeEnum.Links) // if it's FBE notes section { newAnchor.GlobalAttributes.Class.Value = ElementStylesV2.NoteAnchor; newParent.Add(new EmptyLine(newParent.HTMLStandard)); newParent.Add(newAnchor); count++; newAnchor.Add(new SimpleHTML5Text(newAnchor.HTMLStandard) { Text = (link.Value.Count > 1) ? string.Format("(<< back {0}) ", count) : string.Format("(<< back) ") }); } } } else { //throw new Exception("Internal consistency error - Used ID has to be in one of the book documents objects"); Logger.Log.Error("Internal consistency error - Used ID has to be in one of the book documents objects"); //continue; } } } }
private void GenerateSingleFootnote(Anchor anchor,string targetID) { BaseXHTMLFileV3 anchorDocument = GetItemParentDocument(anchor); // get document containing anchor pointing to target ID if (anchorDocument == null) // if anchor not contained (not found) in any document { Logger.Log.Error(string.Format("Internal consistency error - anchor ({0}) for id ({1}) not contained (not found) in any document", anchor, _linkTargetItem)); return; } if (anchorDocument is FB2NotesPageSectionFile) // if anchor in FB2 Notes section (meaning link from FB2 notes to FB2 notes) no need to do anything as we do not save notes files in this mode { return; } // update reference link for an anchor, local one (without file name) anchor.HRef.Value = GenerateLocalLinkReference(targetID); // mark anchor (link reference) as note reference to make it pop-up able EPubV3VocabularyStyles linkStyles = new EPubV3VocabularyStyles(); linkStyles.SetType(EpubV3Vocabulary.NoteRef); anchor.CustomAttributes.Add(linkStyles.GetAsCustomAttribute()); // add footnote object to the same document that contains link ,so the pop up point and pop up content will be in a same document var footnoteToAdd = CreateFootnoteItemFromTargetNoteItem(targetID); anchorDocument.AddFootNote(targetID, footnoteToAdd); // if footnote target ID already exist it will not add it }