public TagNode(BBTag tag, IEnumerable<SyntaxTreeNode> subNodes) : base(subNodes) { if (tag == null) throw new ArgumentNullException("tag"); Tag = tag; AttributeValues = new Dictionary<BBAttribute, string>(); }
public PostViewModel() { PostsCollection = new ObservableCollection <PostModel>(); //To remove the ;01238918 garbage Func <IAttributeRenderingContext, string> fixUpFunction = (x) => { return(x.AttributeValue == null ? "" : x.AttributeValue.Split(';')[0]); }; Func <IAttributeRenderingContext, string> videoStuff = (x) => { return(x.AttributeValue == null ? "" : x.AttributeValue.Split(';')[0]); }; //Image display settings. BBTag img, t; if (Settings.DisplayImages) { img = new BBTag("img", "<img src=\"${content}\" />", "", false, true); t = new BBTag("t", "<img src=\"${content}\" />", "", false, true); } else { img = new BBTag("img", "<a href=\"${content}\">${content}</a>", "", false, true); t = new BBTag("t", "", "<a href=\"${content}\">${content}</a>", false, true); } _parser = new BBCodeParser(new[] { new BBTag("b", "<b>", "</b>"), new BBTag("h2", "<h2>", "</h2>"), //Doesn't appear to work: new BBTag("del", "<span style='text-decoration:line-through'>", "</span>"), new BBTag("i", "<span style=\"font-style:italic;\">", "</span>"), new BBTag("u", "<span style=\"text-decoration:underline;\">", "</span>"), new BBTag("editline", "<span style=\"text-decoration:underline;\">Edited on ", "</span>"), new BBTag("highlight", "<span style=\"color: #417394;background: #FFEB90 none repeat-x;\">", "</span>"), //new BBTag("code", "<pre class=\"prettyprint\">", "</pre>"), img, t, //Highlights that it's a quote with color... new BBTag("quote", "<p style=\"color: #417394;\"><b>${user}</b><br/>", "</p>", new BBAttribute("user", "", fixUpFunction, HtmlEncodingMode.UnsafeDontEncode), new BBAttribute("user", "user")), new BBTag("list", "<ul>", "</ul>"), new BBTag("*", "<li>", "</li>", true, false), //fix urls: http://bbcode.codeplex.com/workitem/9530 new BBTag("url", "<a href=\"${href}\" rel=\"nofollow\">", "</a>", new BBAttribute("href", "", GetUrlTagHrefAttributeValue), new BBAttribute("href", "href", GetUrlTagHrefAttributeValue)), new BBTag("video", "<a href=\"${content}\">", "Youtube Video</a>", true, false, new BBAttribute("href", "", videoStuff), new BBAttribute("href", "href")), new BBTag("media", "<a href=\"${content}\">${content}</a>", "", false, true), new BBTag("hd", "<a href=\"${content}\">${content}</a>", "", false, true), //what else...? }); }
public TagNode(BBTag tag, IEnumerable <SyntaxTreeNode> subNodes) : base(subNodes) { if (tag == null) { throw new ArgumentNullException("tag"); } Tag = tag; AttributeValues = new Dictionary <BBAttribute, string>(); }
public static string BBCodeToHtml(string rawString, BBTag bbTag) { if (string.IsNullOrEmpty(rawString)) { return(rawString); } return(HtmlUtility.BBCodeToHtml(rawString, new System.Collections.Generic.List <BBTag> { bbTag })); }
/// <summary> /// 将内容中的BBCode转换为对应的Html标签 /// </summary> /// <param name="rawString">需要处理的字符串</param> /// <param name="bbTag">bbTag实体</param> /// <param name="htmlEncode">是否进行htmlEncode</param> /// <include file='BBCodeToHtml.xml' path='doc/members/member[@name="M:Tunynet.Utilities.HtmlUtility.BBCodeToHtml"]/example'/> public static string BBCodeToHtml(string rawString, BBTag bbTag, bool htmlEncode = false) { if (string.IsNullOrEmpty(rawString)) { return(rawString); } return(BBCodeToHtml(rawString, new List <BBTag>() { bbTag }, htmlEncode)); }
public TagNode(BBTag tag, IList <SyntaxTreeNode> subNodes, IDictionary <BBAttribute, string> attributeValues = null) : base(subNodes) { tag.ThrowIfNull(nameof(tag)); Tag = tag; if (attributeValues is null) { AttributeValues = new Dictionary <BBAttribute, string>(); } else { AttributeValues = new Dictionary <BBAttribute, string>(attributeValues); } }
public TagNode(BBTag tag) : this(tag, null) { }
/// <summary> /// Initialize a new instance. /// </summary> /// <param name="tag"></param> /// <param name="subNodes">Can be null.</param> /// <exception cref="ArgumentNullException"></exception> public TagNode(BBTag tag, IEnumerable <SyntaxTreeNode> subNodes) : base(subNodes) { Tag = tag ?? throw new ArgumentNullException(nameof(tag)); AttributeValues = new Dictionary <BBAttribute, string>(); }
public PostConverter() { #region Parser Func <IAttributeRenderingContext, string> fixUpFunction = (x) => { return(x.AttributeValue == null ? "" : x.AttributeValue.Split(';')[0]); }; Func <IAttributeRenderingContext, string> videoStuff = (x) => { return(x.AttributeValue == null ? "" : x.AttributeValue.Split(';')[0]); }; Func <string, string> urlStuff = (x) => { // Can't have inline... how should I fix this? if (!x.Contains("InlineUIContainer") && !x.Contains("Hyperlink") && !x.Contains("LineBreak")) { return("<Hyperlink NavigateUri=\"" + x + "\" TargetName=\"_blank\">" + x + "</Hyperlink>"); } else if (x.Contains("InlineUIContainer")) { return("<Hyperlink NavigateUri=\"" + x.Split('"')[1] + "\" TargetName=\"_blank\">Embedded URL</Hyperlink><LineBreak/>" + "<InlineUIContainer><Image Source=\"" + x.Split('"')[1] + "\" /></InlineUIContainer>"); } else if (x.Contains("Hyperlink")) { return("<Hyperlink NavigateUri=\"" + x.Split('"')[1] + "\" TargetName=\"_blank\">Embedded URL</Hyperlink><LineBreak/>" + "<Hyperlink NavigateUri=\"" + x.Split('"')[1] + "\" TargetName=\"_blank\">" + x.Split('"')[1] + "</Hyperlink><LineBreak/>"); } else { return("URL</Hyperlink>"); } }; var endRTB = "</Paragraph></RichTextBox>"; var openRTB = "<RichTextBox IsReadOnly=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ><Paragraph>"; //Image display settings. BBTag img, t, imgT; if (Settings.DisplayImages) { /*<Image> * <Image.Source> * <BitmapImage UriSource="{Binding ImgUrl}" CreateOptions="BackgroundCreation"/> * </Image.Source> * </Image>*/ img = new BBTag("img", "<InlineUIContainer><Image Source=\"${content}\" Width=\"Auto\" MaxWidth=\"480\" /></InlineUIContainer>", "", false, true); t = new BBTag("t", "<InlineUIContainer><Image Source=\"${content}\" MaxWidth=\"150\" /></InlineUIContainer>", "", false, true); imgT = new BBTag("img_thumb", "<InlineUIContainer><Image Source=\"${content}\" MaxWidth=\"150\" /></InlineUIContainer>", "", false, true); } else { /* Doesn't work if img was within a hyperlink... */ img = new BBTag("img", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">${content}</Hyperlink><LineBreak/>", "", false, true); t = new BBTag("t", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">${content}</Hyperlink><LineBreak/>", "", false, true); imgT = new BBTag("img_thumb", "", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">${content}</Hyperlink><LineBreak/>", false, true); } var quote = endRTB + "<RichTextBox Padding=\"3,0,0,0\" Margin=\"15,0,0,0\" Background=\"#aaccee\" Foreground=\"#0055aa\" BorderBrush=\"#aaccee\" BorderThickness=\"2\" IsReadOnly=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ><Paragraph>${user} posted:</Paragraph></RichTextBox>" + "<RichTextBox Padding=\"4,0,3,3\" Margin=\"15,0,0,0\" Background=\"#bbddff\" Foreground=\"Black\" BorderBrush=\"#aaccee\" BorderThickness=\"2\" IsReadOnly=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ><Paragraph>"; var endQuote = endRTB + openRTB; if ((Settings.CurrentTheme == Settings.Theme.Dark) || (Settings.CurrentTheme == Settings.Theme.System && !App.IsLightTheme)) { // also helps with long posts... quote = endRTB + "<RichTextBox Padding=\"3,0,0,0\" Margin=\"15,0,0,0\" Background=\"#444444\" Foreground=\"White\" BorderBrush=\"#444444\" BorderThickness=\"2\" IsReadOnly=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ><Paragraph>${user} posted:</Paragraph></RichTextBox>" + "<RichTextBox Padding=\"4,0,3,3\" Margin=\"15,0,0,0\" Background=\"#686868\" Foreground=\"White\" BorderBrush=\"#444444\" BorderThickness=\"2\" IsReadOnly=\"True\" xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" ><Paragraph>"; } _parser = new BBCodeParser(new[] { //fix urls: http://bbcode.codeplex.com/workitem/9530 new BBTag("url", "", "", true, true, urlStuff, new BBAttribute("href", "", GetUrlTagHrefAttributeValue), new BBAttribute("href", "href", GetUrlTagHrefAttributeValue)), new BBTag("b", "<Bold>", "</Bold>"), new BBTag("h2", "<Span FontSize=\"32\">", "</Span>"), //Doesn't appear to work: /*new BBTag("del", "<span style='text-decoration:line-through'>", "</span>"), */ new BBTag("i", "<Italic>", "</Italic>"), new BBTag("u", "<Underline>", "</Underline>"), new BBTag("editline", "<Underline>Edited on ", "</Underline>"), new BBTag("highlight", "<Span Foreground=\"#417394\">", "</Span>"), //new BBTag("code", "<pre class=\"prettyprint\">", "</pre>"), img, t, imgT, //Highlights that it's a quote with color... new BBTag("quote", quote, endQuote, new BBAttribute("user", "", fixUpFunction, HtmlEncodingMode.UnsafeDontEncode), new BBAttribute("user", "user")), //new BBTag("quote", "<Span Foreground=\"#417394\"><Bold>${user}</Bold><LineBreak/>", "</Span><LineBreak/>", new BBAttribute("user", "", fixUpFunction, HtmlEncodingMode.UnsafeDontEncode), new BBAttribute("user", "user")), /*new BBTag("list", "<ul>", "</ul>"), * new BBTag("*", "<li>", "</li>", true, false), */ new BBTag("video", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">", "</Hyperlink>", true, false, new BBAttribute("href", "", videoFuck), new BBAttribute("href", "href")), new BBTag("media", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">${content}</Hyperlink>", "", false, true), new BBTag("hd", "<Hyperlink NavigateUri=\"${content}\" TargetName=\"_blank\">${content}</Hyperlink>", "", false, true), //what else...? }); #endregion }