/// <summary> /// Converts FB2 simple text /// ( simple text is normal text or text with one of the "styles") /// </summary> /// <param name="styletypeItem">item to convert</param> /// <param name="simpleTextElementConverterParams"></param> /// <returns></returns> public List <IHTMLItem> Convert(StyleType styletypeItem, SimpleTextElementConverterParamsV2 simpleTextElementConverterParams) { if (styletypeItem == null) { throw new ArgumentNullException("styletypeItem"); } var list = new List <IHTMLItem>(); if (styletypeItem is SimpleText) { var text = styletypeItem as SimpleText; switch (text.Style) { case FB2Library.Elements.TextStyles.Normal: if (text.HasChildren) { list.AddRange(text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))); } else { if (simpleTextElementConverterParams.NeedToInsertDrop && text.Text.Length > 0) { AddAsDrop(list, text); } else { list.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } } break; case FB2Library.Elements.TextStyles.Code: var code = new CodeText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var item in text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))) { code.Add(item); } } else { code.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(code); break; case FB2Library.Elements.TextStyles.Emphasis: var emph = new EmphasisedText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var item in text.Children.SelectMany(x => Convert(x, simpleTextElementConverterParams))) { emph.Add(item); } } else { emph.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(emph); break; case FB2Library.Elements.TextStyles.Strong: var str = new Strong(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { str.Add(item); } } } else { str.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(str); break; case FB2Library.Elements.TextStyles.Sub: var sub = new Sub(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { sub.Add(item); } } } else { sub.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(sub); break; case FB2Library.Elements.TextStyles.Sup: var sup = new Sup(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { sup.Add(item); } } } else { sup.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(sup); break; case FB2Library.Elements.TextStyles.Strikethrough: var strike = new DeletedText(HTMLElementType.XHTML11); if (text.HasChildren) { foreach (var child in text.Children) { foreach (var item in Convert(child, simpleTextElementConverterParams)) { strike.Add(item); } } } else { strike.Add(new SimpleHTML5Text(HTMLElementType.XHTML11) { Text = text.Text }); } list.Add(strike); break; } } else if (styletypeItem is InternalLinkItem) { var linkConverter = new InternalLinkConverterV2(); list.AddRange(linkConverter.Convert(styletypeItem as InternalLinkItem, new InternalLinkConverterParamsV2 { NeedToInsertDrop = simpleTextElementConverterParams.NeedToInsertDrop, Settings = simpleTextElementConverterParams.Settings, })); } else if (styletypeItem is InlineImageItem) { var inlineItem = styletypeItem as InlineImageItem; if (simpleTextElementConverterParams.Settings.Images.IsImageIdReal(inlineItem.HRef)) { var inlineImageConverter = new InlineImageConverterV2(); list.Add(inlineImageConverter.Convert(styletypeItem as InlineImageItem, new InlineImageConverterParamsV2 { Settings = simpleTextElementConverterParams.Settings })); simpleTextElementConverterParams.Settings.Images.ImageIdUsed(inlineItem.HRef); } } return(list); }
public bool ProcessElement(IElementProcessingState state, DeletedText deletedText) { state.CurrentVNode.Text += deletedText.Text; return(false); }