/// <summary> /// Converts FB2 section element /// </summary> /// <param name="sectionItem">item to convert</param> /// <returns>XHTML representation</returns> public List<IHTMLItem> Convert(SectionItem sectionItem) { if (sectionItem == null) { throw new ArgumentNullException("sectionItem"); } var resList = new List<IHTMLItem>(); Logger.Log.Debug("Converting section"); var content = new Div(HTMLElementType.HTML5); ulong documentSize = 0; _checker.MaxSizeLimit = Settings.MaxSize; SetClassType(content, string.Format(ElementStylesV3.SectionItemFormat, RecursionLevel)); content.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionItem.ID, content); if (sectionItem.Lang != null) { content.GlobalAttributes.Language.Value = sectionItem.Lang; } // Load Title if (sectionItem.Title != null) { IHTMLItem titleItem; if (!LinkSection) { var titleConverter = new TitleConverterV3(); titleItem = titleConverter.Convert(sectionItem.Title, new TitleConverterParamsV3 { Settings = Settings, TitleLevel = RecursionLevel + 1 }); } else { var linkSectionConverter = new LinkSectionConverterV3(); titleItem = linkSectionConverter.Convert(sectionItem, new LinkSectionConverterParamsV3 { Settings = Settings }); } if (titleItem != null) { documentSize = SplitBlockHTMLItem(titleItem,content,resList,documentSize); } } // Load epigraphs documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV3() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 {Settings = Settings, Level = RecursionLevel + 1})).Aggregate(documentSize, (current, epigraphItem) => SplitBlockHTMLItem(epigraphItem, content, resList, current)); // Load section image if (Settings.Images.HasRealImages()) { documentSize = sectionItem.SectionImages.Aggregate(documentSize, (current, sectionImage) => ConvertSectionImage(sectionImage, content, resList, current)); } // Load annotations if (sectionItem.Annotation != null) { var annotationConverter = new AnnotationConverterV3(); IHTMLItem annotationItem = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV3 { Level = RecursionLevel + 1, Settings = Settings }); documentSize = SplitBlockHTMLItem(annotationItem, content, resList, documentSize); } // Parse all elements only if section has no sub section if (sectionItem.SubSections.Count == 0) { bool startSection = true; sectionItem.Content.Aggregate(documentSize, (current, item) => ConvertSimpleSubItem(item, sectionItem, content, resList, ref startSection, current)); } resList.Add(content); return resList; }
/// <summary> /// Converts FB2 section element /// </summary> /// <param name="sectionItem">item to convert</param> /// <returns>XHTML representation</returns> public List <IHTMLItem> Convert(SectionItem sectionItem) { if (sectionItem == null) { throw new ArgumentNullException("sectionItem"); } var resList = new List <IHTMLItem>(); Logger.Log.Debug("Converting section"); var content = new Div(HTMLElementType.HTML5); ulong documentSize = 0; _checker.MaxSizeLimit = Settings.MaxSize; SetClassType(content, string.Format(ElementStylesV3.SectionItemFormat, RecursionLevel)); content.GlobalAttributes.ID.Value = Settings.ReferencesManager.AddIdUsed(sectionItem.ID, content); if (sectionItem.Lang != null) { content.GlobalAttributes.Language.Value = sectionItem.Lang; } // Load Title if (sectionItem.Title != null) { IHTMLItem titleItem; if (!LinkSection) { var titleConverter = new TitleConverterV3(); titleItem = titleConverter.Convert(sectionItem.Title, new TitleConverterParamsV3 { Settings = Settings, TitleLevel = RecursionLevel + 1 }); } else { var linkSectionConverter = new LinkSectionConverterV3(); titleItem = linkSectionConverter.Convert(sectionItem, new LinkSectionConverterParamsV3 { Settings = Settings }); } if (titleItem != null) { documentSize = SplitBlockHTMLItem(titleItem, content, resList, documentSize); } } // Load epigraphs documentSize = (from epigraph in sectionItem.Epigraphs let epigraphConverter = new EpigraphConverterV3() select epigraphConverter.Convert(epigraph, new EpigraphConverterParamsV3 { Settings = Settings, Level = RecursionLevel + 1 })).Aggregate(documentSize, (current, epigraphItem) => SplitBlockHTMLItem(epigraphItem, content, resList, current)); // Load section image if (Settings.Images.HasRealImages()) { documentSize = sectionItem.SectionImages.Aggregate(documentSize, (current, sectionImage) => ConvertSectionImage(sectionImage, content, resList, current)); } // Load annotations if (sectionItem.Annotation != null) { var annotationConverter = new AnnotationConverterV3(); IHTMLItem annotationItem = annotationConverter.Convert(sectionItem.Annotation, new AnnotationConverterParamsV3 { Level = RecursionLevel + 1, Settings = Settings }); documentSize = SplitBlockHTMLItem(annotationItem, content, resList, documentSize); } // Parse all elements only if section has no sub section if (sectionItem.SubSections.Count == 0) { bool startSection = true; sectionItem.Content.Aggregate(documentSize, (current, item) => ConvertSimpleSubItem(item, sectionItem, content, resList, ref startSection, current)); } resList.Add(content); return(resList); }