/// <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 Load(XNode xText) { subtext.Clear(); if (xText == null) { throw new ArgumentNullException("xText"); } switch (xText.NodeType) { case XmlNodeType.Text: XText textNode = (XText) xText; if (!string.IsNullOrEmpty(textNode.Value)) { Text = textNode.Value; style = TextStyles.Normal; } break; case XmlNodeType.Element: XElement xTextElement = (XElement)xText; if (xTextElement.HasElements) { Text = string.Empty; style = GetStyle(xTextElement.Name.LocalName); IEnumerable<XNode> childElements = xTextElement.Nodes(); foreach (var node in childElements) { if (node.NodeType == XmlNodeType.Element) { XElement element = (XElement) node; switch (element.Name.LocalName) { case InternalLinkItem.Fb2InternalLinkElementName: InternalLinkItem link = new InternalLinkItem(); try { link.Load(element); subtext.Add(link); } catch (Exception) { continue; } break; case InlineImageItem.Fb2InlineImageElementName: InlineImageItem image = new InlineImageItem(); try { image.Load(element); subtext.Add(image); } catch (Exception) { continue; } break; default: SimpleText text = new SimpleText(); try { text.Load(element); subtext.Add(text); } catch (Exception) { continue; } break; } } else { SimpleText text = new SimpleText(); try { text.Load(node); subtext.Add(text); } catch (Exception) { continue; } } } } else { style = GetStyle(xTextElement.Name.LocalName); Text = xTextElement.Value; //switch (xTextElement.Name.LocalName) //{ // case "strong": // Text = xTextElement.Value; // break; // case "emphasis": // Text = xTextElement.Value; // break; // case "code": // Text = xTextElement.Value; // break; // case "sub": // Text = xTextElement.Value; // break; // case "sup": // Text = xTextElement.Value; // break; // case "strikethrough": // Text = xTextElement.Value; // break; // default: // Text = xTextElement.Value; // break; //} } break; } }
/// <summary> /// Load element data from the node /// </summary> /// <param name="xStyle"></param> public void Load(XElement xStyle) { if (xStyle == null) { throw new ArgumentNullException("style"); } if (xStyle.Name.LocalName != StyleItemName) { throw new ArgumentException(string.Format("The element is of type {0} while StyleItem accepts only {1} types", xStyle.Name.LocalName, StyleItemName)); } Lang = null; XAttribute xLang = xStyle.Attribute(XNamespace.Xml + "lang"); if (xLang != null) { Lang = xLang.Value; } Name = string.Empty; XAttribute xName = xStyle.Attribute("name"); if (xName != null && xName.Value != null) { Name = xName.Value; } if (xStyle.HasElements) { IEnumerable <XNode> childElements = xStyle.Nodes(); foreach (var element in childElements) { if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element)) { XElement xElement = (XElement)element; if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName) { InlineImageItem image = new InlineImageItem(); try { image.Load(xElement); StyleData.Add(image); } catch (Exception) { } } else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName) { InternalLinkItem linkItem = new InternalLinkItem(); try { linkItem.Load(xElement); StyleData.Add(linkItem); } catch (Exception) { } } else if (xElement.Name.LocalName == StyleItemName) { StyleItem styleItem = new StyleItem(); try { styleItem.Load(xElement); StyleData.Add(styleItem); } catch (Exception) { } } } else { SimpleText text = new SimpleText(); try { text.Load(element); StyleData.Add(text); } catch (Exception) { } } } } else if (!string.IsNullOrEmpty(xStyle.Value)) { SimpleText text = new SimpleText(); text.Load(xStyle); StyleData.Add(text); } }
public void Load(XNode xText) { subtext.Clear(); if (xText == null) { throw new ArgumentNullException("xText"); } switch (xText.NodeType) { case XmlNodeType.Text: XText textNode = (XText)xText; if (!string.IsNullOrEmpty(textNode.Value)) { Text = textNode.Value; style = TextStyles.Normal; } break; case XmlNodeType.Element: XElement xTextElement = (XElement)xText; if (xTextElement.HasElements) { Text = string.Empty; style = GetStyle(xTextElement.Name.LocalName); IEnumerable <XNode> childElements = xTextElement.Nodes(); foreach (var node in childElements) { if (node.NodeType == XmlNodeType.Element) { XElement element = (XElement)node; switch (element.Name.LocalName) { case InternalLinkItem.Fb2InternalLinkElementName: InternalLinkItem link = new InternalLinkItem(); try { link.Load(element); subtext.Add(link); } catch (Exception) { continue; } break; case InlineImageItem.Fb2InlineImageElementName: InlineImageItem image = new InlineImageItem(); try { image.Load(element); subtext.Add(image); } catch (Exception) { continue; } break; default: SimpleText text = new SimpleText(); try { text.Load(element); subtext.Add(text); } catch (Exception) { continue; } break; } } else { SimpleText text = new SimpleText(); try { text.Load(node); subtext.Add(text); } catch (Exception) { continue; } } } } else { style = GetStyle(xTextElement.Name.LocalName); Text = xTextElement.Value; //switch (xTextElement.Name.LocalName) //{ // case "strong": // Text = xTextElement.Value; // break; // case "emphasis": // Text = xTextElement.Value; // break; // case "code": // Text = xTextElement.Value; // break; // case "sub": // Text = xTextElement.Value; // break; // case "sup": // Text = xTextElement.Value; // break; // case "strikethrough": // Text = xTextElement.Value; // break; // default: // Text = xTextElement.Value; // break; //} } break; } }
protected void LoadData(XElement xParagraph) { if (xParagraph.HasElements) { IEnumerable <XNode> childElements = xParagraph.Nodes(); foreach (var element in childElements) { if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element)) { XElement xElement = (XElement)element; if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName) { InlineImageItem image = new InlineImageItem(); try { image.Load(xElement); paragraphData.Add(image); } catch (Exception) { } } else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName) { InternalLinkItem linkItem = new InternalLinkItem(); try { linkItem.Load(xElement); paragraphData.Add(linkItem); } catch (Exception) { } } else if (xElement.Name.LocalName == StyleItem.StyleItemName) { StyleItem styleItem = new StyleItem(); try { styleItem.Load(xElement); paragraphData.Add(styleItem); } catch (Exception) { } } } else //if ( element.NodeType != XmlNodeType.Whitespace) { SimpleText text = new SimpleText(); try { text.Load(element); paragraphData.Add(text); } catch (Exception) { continue; } } } } else if (!string.IsNullOrEmpty(xParagraph.Value)) { SimpleText text = new SimpleText(); text.Load(xParagraph); paragraphData.Add(text); } XAttribute xID = xParagraph.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } XAttribute xStyle = xParagraph.Attribute("style"); if ((xStyle != null) && (xStyle.Value != null)) { Style = xStyle.Value; } Lang = null; XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }
protected void LoadData(XElement xParagraph) { if (xParagraph.HasElements) { IEnumerable<XNode> childElements = xParagraph.Nodes(); foreach (var element in childElements) { if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element)) { XElement xElement = (XElement) element; if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName) { InlineImageItem image = new InlineImageItem(); try { image.Load(xElement); paragraphData.Add(image); } catch (Exception) { } } else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName) { InternalLinkItem linkItem = new InternalLinkItem(); try { linkItem.Load(xElement); paragraphData.Add(linkItem); } catch (Exception) { } } } else //if ( element.NodeType != XmlNodeType.Whitespace) { SimpleText text = new SimpleText(); try { text.Load(element); paragraphData.Add(text); } catch (Exception) { continue; } } } } else if (!string.IsNullOrEmpty(xParagraph.Value)) { SimpleText text = new SimpleText(); text.Load(xParagraph); paragraphData.Add(text); } XAttribute xID = xParagraph.Attribute("id"); if ((xID != null) && (xID.Value != null)) { ID = xID.Value; } XAttribute xStyle = xParagraph.Attribute("style"); if ((xStyle != null) && (xStyle.Value != null)) { Style = xStyle.Value; } Lang = null; XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang"); if ((xLang != null) && (xLang.Value != null)) { Lang = xLang.Value; } }