/// <summary> /// Converts FB2 epigraph element /// </summary> /// <param name="epigraphItem"></param> /// <param name="epigraphConverterParams"></param> /// <returns>XHTML representation</returns> public Div Convert(EpigraphItem epigraphItem, EpigraphConverterParamsV3 epigraphConverterParams) { if (epigraphItem == null) { throw new ArgumentNullException("epigraphItem"); } var content = new Div(HTMLElementType.HTML5); foreach (var element in epigraphItem.EpigraphData) { if (element is ParagraphItem) { var paragraphConverter = new ParagraphConverterV3(); content.Add(paragraphConverter.Convert(element as ParagraphItem, new ParagraphConverterParamsV3 { ResultType = ParagraphConvTargetEnumV3.Paragraph, Settings = epigraphConverterParams.Settings, StartSection = false })); } if (element is PoemItem) { var poemConverter = new PoemConverterV3(); content.Add(poemConverter.Convert(element as PoemItem, new PoemConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings } )); } if (element is CiteItem) { var citationConverter = new CitationConverterV3(); content.Add(citationConverter.Convert(element as CiteItem, new CitationConverterParamsV3 { Level = epigraphConverterParams.Level + 1, Settings = epigraphConverterParams.Settings })); } if (element is EmptyLineItem) { var emptyLineConverter = new EmptyLineConverterV3(); content.Add(emptyLineConverter.Convert()); } } foreach (var author in epigraphItem.TextAuthors) { var epigraphAuthorConverter = new EpigraphAuthorConverterV3(); content.Add(epigraphAuthorConverter.Convert(author as TextAuthorItem, new EpigraphAuthorConverterParamsV3 { Settings = epigraphConverterParams.Settings })); } SetClassType(content, ElementStylesV3.EpigraphMain); content.GlobalAttributes.ID.Value = epigraphConverterParams.Settings.ReferencesManager.AddIdUsed(epigraphItem.ID, content); return(content); }
internal void Load(XElement xPoem) { if (xPoem == null) { throw new ArgumentNullException("xPoem"); } if (xPoem.Name.LocalName != Fb2PoemElementName) { throw new ArgumentException("Element of wrong type passed", "xPoem"); } Title = null; Date = null; epigraphs.Clear(); content.Clear(); authors.Clear(); IEnumerable<XElement> xElements = xPoem.Elements(); foreach (var xElement in xElements) { if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName)) { StanzaItem stanza = new StanzaItem(); try { stanza.Load(xElement); content.Add(stanza); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName)) { SubTitleItem subtitle = new SubTitleItem(); try { subtitle.Load(xElement); content.Add(subtitle); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title { Title = new TitleItem(); Title.Load(xElement); } else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName)) { EpigraphItem epigraphItem = new EpigraphItem(); try { epigraphItem.Load(xElement); epigraphs.Add(epigraphItem); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName)) { TextAuthorItem author = new TextAuthorItem(); try { author.Load(xElement); authors.Add(author); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date { Date = new DateItem(); try { Date.Load(xElement); } catch (Exception) { continue; } } } XAttribute xID = xPoem.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } Lang = null; XAttribute xLang = xPoem.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }
internal void Load(XElement xPoem) { if (xPoem == null) { throw new ArgumentNullException("xPoem"); } if (xPoem.Name.LocalName != Fb2PoemElementName) { throw new ArgumentException("Element of wrong type passed", "xPoem"); } Title = null; Date = null; epigraphs.Clear(); content.Clear(); authors.Clear(); IEnumerable <XElement> xElements = xPoem.Elements(); foreach (var xElement in xElements) { if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName)) { StanzaItem stanza = new StanzaItem(); try { stanza.Load(xElement); content.Add(stanza); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName)) { SubTitleItem subtitle = new SubTitleItem(); try { subtitle.Load(xElement); content.Add(subtitle); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title { Title = new TitleItem(); Title.Load(xElement); } else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName)) { EpigraphItem epigraphItem = new EpigraphItem(); try { epigraphItem.Load(xElement); epigraphs.Add(epigraphItem); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName)) { TextAuthorItem author = new TextAuthorItem(); try { author.Load(xElement); authors.Add(author); } catch (Exception) { continue; } } else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date { Date = new DateItem(); try { Date.Load(xElement); } catch (Exception) { continue; } } } XAttribute xID = xPoem.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } Lang = null; XAttribute xLang = xPoem.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }