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> /// Converts empty line FB2 element /// </summary> /// <returns>XHTML representation</returns> public IHTMLItem Convert() { var el = new Paragraph(HTMLElementType.HTML5); el.Add(new SimpleHTML5Text(HTMLElementType.HTML5) { Text = "\u00A0" }); SetClassType(el, ElementStylesV3.EmptyLine); return el; }
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); }
/// <summary> /// Converts poemdate FB2 element /// </summary> /// <param name="poemDateItem">item to convert </param> /// <returns>XHTML representation</returns> public IHTMLItem Convert(DateItem poemDateItem) { if (poemDateItem == null) { throw new ArgumentNullException("poemDateItem"); } var date = new Paragraph(HTMLElementType.XHTML11); date.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = poemDateItem.Text }); SetClassType(date, ElementStylesV2.PoemDate); return date; }
private List<BaseXHTMLFileV2> SplitSimpleText(SimpleHTML5Text simpleEPubText) { var list = new List<BaseXHTMLFileV2>(); var newDoc = new BaseXHTMLFileV2 { PageTitle = PageTitle, NotPartOfNavigation = true, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder) }; newDoc.StyleFiles.AddRange(StyleFiles); newDoc.GuideRole = GuideRole; newDoc.NavigationParent = NavigationParent; newDoc.Content = new Div(Compatibility); var newParagraph = new Paragraph(Compatibility); newDoc.Content.Add(newParagraph); var newText = new SimpleHTML5Text(Compatibility) { Text = "" }; newParagraph.Add(newText); foreach (var word in simpleEPubText.Text.Split(' ')) { newText.Text += ' '; newText.Text += word; ulong itemSize = EstimateSize(newParagraph); if (itemSize >= MaxSize) { list.Add(newDoc); newDoc = new BaseXHTMLFileV2 { PageTitle = InternalPageTitle, NotPartOfNavigation = true, Type = SectionTypeEnum.Text, FileEPubInternalPath = EPubInternalPath.GetDefaultLocation(DefaultLocations.DefaultTextFolder), GuideRole = GuideRole, NavigationParent = NavigationParent, Content = new Div(Compatibility) }; newParagraph = new Paragraph(Compatibility); newDoc.Content.Add(newParagraph); newDoc.StyleFiles.AddRange(StyleFiles); newText = new SimpleHTML5Text(Compatibility) { Text = "" }; newParagraph.Add(newText); } } list.Add(newDoc); return list; }
private List<BaseXHTMLFileV2> SplitParagraph(Paragraph paragraph) { var list = new List<BaseXHTMLFileV2>(); foreach (var subElement in paragraph.SubElements()) { var newParagraph = new Paragraph(Compatibility); newParagraph.Add(subElement); ulong itemSize = EstimateSize(newParagraph); if (itemSize > MaxSize) { if (Content.SubElements() != null) { List<BaseXHTMLFileV2> subList = null; if (subElement.GetType() == typeof(SimpleHTML5Text)) { subList = SplitSimpleText(subElement as SimpleHTML5Text); } if (subList != null) { list.AddRange(subList); } } } else { Content.Add(newParagraph); } } return list; }
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> /// Creates block element based on paragraph type /// </summary> /// <param name="type"></param> /// <returns></returns> private static HTMLItem CreateBlock(ParagraphConvTargetEnumV3 type) { HTMLItem paragraph; switch (type) { case ParagraphConvTargetEnumV3.H1: paragraph = new H1(HTMLElementType.HTML5); break; case ParagraphConvTargetEnumV3.H2: paragraph = new H2(HTMLElementType.HTML5); break; case ParagraphConvTargetEnumV3.H3: paragraph = new H3(HTMLElementType.HTML5); break; case ParagraphConvTargetEnumV3.H4: paragraph = new H4(HTMLElementType.HTML5); break; case ParagraphConvTargetEnumV3.H5: paragraph = new H5(HTMLElementType.HTML5); break; case ParagraphConvTargetEnumV3.H6: paragraph = new H6(HTMLElementType.HTML5); break; default: // Paragraph or anything else paragraph = new Paragraph(HTMLElementType.HTML5); break; } return paragraph; }
private List<BaseXHTMLFileV3> SplitSimpleText(SimpleHTML5Text simpleEPubText) { var list = new List<BaseXHTMLFileV3>(); var newDoc = new BaseXHTMLFileV3 { PageTitle = InternalPageTitle, NotPartOfNavigation = true }; newDoc.StyleFiles.AddRange(StyleFiles); newDoc.GuideRole = GuideRole; newDoc.NavigationParent = NavigationParent; newDoc.Content = new Div(Compatibility); var newParagraph = new Paragraph(Compatibility); newDoc.Content.Add(newParagraph); var newText = new SimpleHTML5Text(Compatibility) { Text = "" }; newParagraph.Add(newText); foreach (var word in simpleEPubText.Text.Split(' ')) { newText.Text += ' '; newText.Text += word; ulong itemSize = EstimateSize(newParagraph); if (itemSize >= MaxSize) { list.Add(newDoc); newDoc = new BaseXHTMLFileV3 { PageTitle = PageTitle, NotPartOfNavigation = true }; newDoc.StyleFiles.AddRange(StyleFiles); newDoc.GuideRole = GuideRole; newDoc.NavigationParent = NavigationParent; newDoc.Content = new Div(Compatibility); newParagraph = new Paragraph(Compatibility); newDoc.Content.Add(newParagraph); newText = new SimpleHTML5Text(Compatibility) { Text = "" }; newParagraph.Add(newText); } } list.Add(newDoc); return list; }