Span RenderBlockContent(InlineCollection inlines, ListContext list, XElement e, int blockType) { if (inlines.LastInline != null && inlines.LastInline is LineBreak == false) { inlines.AppendLineWithMargin(); } if (blockType == BLOCK_ITEM) { PopulateListNumber(inlines, list); } else { ParagraphCount++; } var span = new Span(); if (_isCode > 0) { span.FontFamily = GetCodeFont(); } if (blockType == BLOCK_TITLE) { span.FontWeight = System.Windows.FontWeights.Bold; } inlines.Add(span); InternalRender(e, span.Inlines, list); if (blockType != BLOCK_ITEM && e.NextNode != null && IsInlineElementName((e.NextNode as XElement)?.Name.LocalName) == false) { inlines.Add(new LineBreak()); } return(span); }
void RenderBlockContent(InlineCollection inlines, ListContext list, XElement e, int blockType) { if (inlines.FirstInline != null) { inlines.AppendLineWithMargin(); } if (blockType == BLOCK_ITEM) { PopulateListNumber(inlines, list); } InternalRender(e, inlines, list); if (inlines.FirstInline == null) { inlines.Add(new LineBreak()); } }
void InternalRender(XContainer content, InlineCollection inlines, ListContext list) { foreach (var item in content.Nodes()) { switch (item.NodeType) { case XmlNodeType.Element: var e = item as XElement; switch (e.Name.LocalName) { case "list": list = list == null ? new ListContext(e.Attribute("type")?.Value) : new ListContext(e.Attribute("type")?.Value, list); InternalRender(e, inlines, list); list = list.Parent; break; case "para": var isOnlyChildOfItem = list != null && e.Parent.Name == "item" && e.Parent.FirstNode == e.Parent.LastNode && e.Parent.FirstNode == item; if (isOnlyChildOfItem) { ParagraphCount++; } else if (inlines.FirstInline != null) { inlines.AppendLineWithMargin(); ParagraphCount++; } InternalRender(e, inlines, list); if (inlines.FirstInline == null && isOnlyChildOfItem == false) { inlines.Add(new LineBreak()); } break; case "listheader": case "code": RenderBlockContent(inlines, list, e, BLOCK_OTHER); break; case "item": RenderBlockContent(inlines, list, e, BLOCK_ITEM); break; case "see": var see = e.Attribute("cref"); if (see != null) { RenderXmlDocSymbol(see.Value, inlines, SymbolKind.Alias); } else if ((see = e.Attribute("langword")) != null) { RenderXmlDocSymbol(see.Value, inlines, SymbolKind.DynamicType); } break; case "paramref": var paramName = e.Attribute("name"); if (paramName != null) { RenderXmlDocSymbol(paramName.Value, inlines, SymbolKind.Parameter); } break; case "typeparamref": var typeParamName = e.Attribute("name"); if (typeParamName != null) { RenderXmlDocSymbol(typeParamName.Value, inlines, SymbolKind.TypeParameter); } break; case "c": StyleInner(e, inlines, new Bold() { Background = ThemeHelper.ToolWindowBackgroundBrush, Foreground = ThemeHelper.ToolWindowTextBrush }); break; case "b": StyleInner(e, inlines, new Bold()); break; case "i": StyleInner(e, inlines, new Italic()); break; case "u": StyleInner(e, inlines, new Underline()); break; //case "list": //case "description": default: InternalRender(e, inlines, list); break; } break; case XmlNodeType.Text: string t = (item as XText).Value; var parentName = item.Parent.Name.LocalName; if (parentName != "code") { var previous = (item.PreviousNode as XElement)?.Name?.LocalName; if (previous == null || IsInlineElementName(previous) == false) { t = item.NextNode == null?t.Trim() : t.TrimStart(); } else if (item.NextNode == null) { t = t.TrimEnd(); } t = _FixWhitespaces.Replace(t.Replace('\n', ' '), " "); } if (t.Length > 0) { inlines.Add(new Run(t)); } break; case XmlNodeType.CDATA: inlines.Add(new Run((item as XText).Value)); break; case XmlNodeType.EntityReference: case XmlNodeType.Entity: inlines.Add(new Run(item.ToString())); break; } } var lastNode = content.LastNode; if (lastNode != null && (lastNode.NodeType != XmlNodeType.Element || ((XElement)lastNode).Name != "para") && (lastNode.PreviousNode as XElement)?.Name == "para") { ParagraphCount++; } }
void InternalRender(XContainer content, InlineCollection inlines, ListContext list) { foreach (var item in content.Nodes()) { switch (item.NodeType) { case XmlNodeType.Element: var e = item as XElement; switch (e.Name.LocalName) { case "list": list = list == null ? new ListContext(e.Attribute("type")?.Value) : new ListContext(e.Attribute("type")?.Value, list); InternalRender(e, inlines, list); list = list.Parent; break; case "para": var isOnlyChildOfItem = list != null && e.Parent.Name == "item" && e.Parent.FirstNode == e.Parent.LastNode && e.Parent.FirstNode == item; if (isOnlyChildOfItem) { ParagraphCount++; } else if (inlines.LastInline != null && inlines.LastInline is LineBreak == false) { inlines.AppendLineWithMargin(); ParagraphCount++; } InternalRender(e, inlines, list); if (inlines.FirstInline == null && isOnlyChildOfItem == false) { inlines.Add(new LineBreak()); } break; case "listheader": RenderBlockContent(inlines, list, e, BLOCK_OTHER); break; case "h1": RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 5; break; case "h2": RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 3; break; case "h3": RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 2; break; case "h4": RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 1; break; case "h5": RenderBlockContent(inlines, list, e, BLOCK_TITLE).FontSize = ThemeHelper.ToolTipFontSize + 0.5; break; case "h6": RenderBlockContent(inlines, list, e, BLOCK_TITLE); break; case "code": ++_isCode; var span = RenderBlockContent(inlines, list, e, BLOCK_OTHER); span.FontFamily = GetCodeFont(); span.Background = ThemeHelper.ToolWindowBackgroundBrush; span.Foreground = ThemeHelper.ToolWindowTextBrush; --_isCode; break; case "item": RenderBlockContent(inlines, list, e, BLOCK_ITEM); break; case "see": case "seealso": RenderSee(inlines, e); break; case "paramref": RenderParamRef(inlines, e); break; case "typeparamref": RenderTypeParamRef(inlines, e); break; case "c": case "tt": ++_isCode; StyleInner(e, inlines, new Span() { FontFamily = GetCodeFont(), Background = ThemeHelper.ToolWindowBackgroundBrush, Foreground = ThemeHelper.ToolWindowTextBrush }); --_isCode; break; case "b": case "strong": case "term": StyleInner(e, inlines, new Bold()); break; case "i": case "em": StyleInner(e, inlines, new Italic()); break; case "u": StyleInner(e, inlines, new Underline()); break; case "a": var a = e.Attribute("href"); if (a != null && IsUrl(a)) { CreateLink(inlines, e, a); } else { goto case "u"; } break; case "br": inlines.Add(new LineBreak()); break; case "hr": inlines.AddRange(new Inline[] { new LineBreak(), new InlineUIContainer(new Border { Height = 1, Background = ThemeHelper.DocumentTextBrush, Margin = WpfHelper.MiddleVerticalMargin, Opacity = 0.5 }.Bind(FrameworkElement.WidthProperty, new Binding { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(ThemedTipText), 1), Path = new PropertyPath("ActualWidth") })), new LineBreak() }); break; //case "list": //case "description": default: InternalRender(e, inlines, list); break; } break; case XmlNodeType.Text: string t = ((XText)item).Value; if (_isCode == 0) { var previous = (item.PreviousNode as XElement)?.Name?.LocalName; if (previous == null || IsInlineElementName(previous) == false) { t = item.NextNode == null?t.Trim() : t.TrimStart(); } else if (item.NextNode == null) { t = t.TrimEnd(); } if (t.Length == 0) { break; } t = _FixWhitespaces.Replace(t.Replace('\n', ' '), " "); } else { t = t.Replace("\n ", "\n"); } if (t.Length > 0) { inlines.Add(new Run(t)); } break; case XmlNodeType.CDATA: inlines.Add(_isCode == 0 ? new Run(((XText)item).Value) : new Run(((XText)item).Value.Replace("\n ", "\n").TrimEnd())); break; case XmlNodeType.EntityReference: case XmlNodeType.Entity: inlines.Add(new Run(item.ToString())); break; } } var lastNode = content.LastNode; if (lastNode != null && (lastNode.NodeType != XmlNodeType.Element || ((XElement)lastNode).Name != "para") && IsInlineElementName((lastNode.PreviousNode as XElement)?.Name.LocalName) == false) { ParagraphCount++; } }