public void RenderMessages() { var sb = new StringBuilder(); var emojis = GameFacade.Emojis; for (int i = 0; i < Messages.Count; i++) { var elem = Messages.ElementAt(i); sb.Append("[color=lightgray]<"); var avatarColor = "[color=#" + elem.Color.R.ToString("x2") + elem.Color.G.ToString("x2") + elem.Color.B.ToString("x2") + "][s]"; var colorAfter = "[/s][/color]"; sb.Append(avatarColor + elem.User.Name + colorAfter); sb.Append(">:[/color] "); sb.Append(emojis.EmojiToBB(BBCodeParser.SanitizeBB(elem.MessageBody))); if (i != Messages.Count - 1) { sb.Append("\n"); } } HistoryTextEdit.CurrentText = sb.ToString(); HistoryTextEdit.ComputeDrawingCommands(); HistoryTextEdit.VerticalScrollPosition = Int32.MaxValue; }
// generates pure encoded HTML string static String GeneratePureHtml(CmdletObject cmdlet, IReadOnlyList <CmdletObject> cmdlets, StringBuilder SB, Boolean useSupports) { SB.Clear(); BBCodeParser rules = GetParser(ParserType.Enhanced); HtmlgenerateName(SB, cmdlet); HtmlGenerateSynopsis(rules, SB, cmdlets, cmdlet); HtmlGenerateSyntax(SB, cmdlet); HtmlGenerateDescription(rules, SB, cmdlets, cmdlet); HtmlGenerateParams(rules, SB, cmdlets, cmdlet); HtmlGenerateInputTypes(rules, SB, cmdlet); HtmlGenerateReturnTypes(rules, SB, cmdlet); HtmlGenerateNotes(rules, SB, cmdlet); HtmlGenerateExamples(rules, SB, cmdlet); HtmlGenerateRelatedLinks(rules, SB, cmdlets, cmdlet); if (useSupports) { HtmlGenerateSupports(cmdlet, ref SB); } if (!String.IsNullOrEmpty(cmdlet.ExtraFooter)) { SB.Append(cmdlet.ExtraFooter); } return(SB.ToString()); }
static void XmlGenerateReturnTypes(BBCodeParser bbRules, StringBuilder SB, CmdletObject cmdlet) { List <String> returnTypes = new List <String>(cmdlet.GeneralHelp.ReturnType.Split(new[] { ';' })); List <String> returnUrls = new List <String>(cmdlet.GeneralHelp.ReturnUrl.Split(new[] { ';' })); List <String> returnDescription = new List <String>(cmdlet.GeneralHelp.ReturnTypeDescription.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); SB.Append(" <command:returnValues>" + n); for (Int32 index = 0; index < returnTypes.Count; index++) { SB.Append(" <command:returnValue>"+ n); SB.Append(" <dev:type>"+ n); SB.Append(" <maml:name>"+ bbRules.ToHtml(returnTypes[index], true) + "</maml:name>" + n); try { SB.Append(" <maml:uri>"+ bbRules.ToHtml(returnUrls[index], true) + "</maml:uri>" + n); } catch { SB.Append(" <maml:uri />"+ n); } SB.Append(" <maml:description/>"+ n); SB.Append(" </dev:type>"+ n); SB.Append(" <maml:description>"+ n); try { SB.Append(generatePragraphs(returnDescription[index], bbRules, 4)); } catch { SB.Append("<maml:para />" + n); } SB.Append(" </maml:description>"+ n); SB.Append(" </command:returnValue>"+ n); } SB.Append(" </command:returnValues>" + n); }
/// <summary> /// Find formatting tags in the text and transform them into static tags. /// </summary> /// <param name="text">The text to be transformed.</param> /// <param name="replyRepository">An instance of IReplyRepository.</param> /// <param name="isModerator">True if the current user is a moderator.</param> /// <returns>A formatted string.</returns> public static string SimplifyComplexTags(string text, IReplyRepository replyRepository, bool isModerator) { var parser = new BBCodeParser(new[] { new BBTag("quote", "", "", true, true, content => { string reformattedQuote = string.Format(@"[quote]{0}[/quote]", content); if (content.IsLong()) { Reply reply = replyRepository.GetReply(content.ToLong()); if (reply != null) { if (!reply.IsModsOnly() || isModerator) { var author = reply.Topic.Board.Anonymous ? "Anon" : reply.Username; reformattedQuote = string.Format("[quote]Posted by: [transmit=USER]{0}[/transmit] on {1}\n\n{2}[/quote]", author, reply.PostedDate, reply.Body); } } } return(reformattedQuote); }), }); return(parser.ToHtml(text, false)); }
public void ShowCandidate(NhoodCandidate cand) { Avatar.AvatarId = cand.ID; NameLabel.Caption = cand.Name; MessageLabel.CurrentText = GameFacade.Emojis.EmojiToBB(BBCodeParser.SanitizeBB(cand.Message)); AvatarID = cand.ID; if (cand.TermNumber > 0) { SubtitleLabel.Caption = GameFacade.Strings.GetString("f118", "7", new string[] { GetOrdinal((int)cand.TermNumber + 1) }); //consecutive term } else if (cand.LastNhoodID != 0) { SubtitleLabel.Caption = GameFacade.Strings.GetString("f118", "8", new string[] { cand.LastNhoodName }); //ex-mayor } else { SubtitleLabel.Caption = GameFacade.Strings.GetString("f118", "6"); //newcomer } Rating.Visible = cand.Rating != uint.MaxValue; if (Rating.Visible) { Rating.LinkAvatar = cand.ID; Rating.DisplayStars = cand.Rating / 100f; if (Alignment) { Rating.X = (495 - 60) - (SubtitleLabel.CaptionStyle.MeasureString(SubtitleLabel.Caption).X + 7); } else { Rating.X = SubtitleLabel.CaptionStyle.MeasureString(SubtitleLabel.Caption).X + 81 + 7; } } }
private void Update() { if (!IsLoaded || !dirty) { return; } string bbcode = BBCode; Inlines.Clear(); if (!string.IsNullOrWhiteSpace(bbcode)) { Inline inline; try { BBCodeParser parser = new BBCodeParser(bbcode, this, BBCodeQuoteBackground) { Commands = LinkNavigator.Commands }; inline = parser.Parse(); } catch (Exception) { // parsing failed, display BBCode value as-is inline = new Run { Text = bbcode }; } Inlines.Add(inline); } dirty = false; }
/// <summary> /// Translates a string from bbCode to http /// </summary> /// <param name="inString"></param> /// <returns></returns> internal string Transform(string inString, bool keepAllChars = false) { //Set the tags that we are interested in translating var parser = new BBCodeParser(new[] { // a newline is automatically parsed when \n is encountered. Hence [p] is not necessary. new BBTag("b", "<b>", "</b>"), new BBTag("i", "<i>", "</i>"), new BBTag("u", "<u>", "</u>"), new BBTag("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href")), }); try { inString = parser.ToHtml(inString); if (inString.Contains("&#") && keepAllChars) { inString = BBcodeClean(inString); } } catch { throw new FormatException(); } return(inString); }
public MessageRepository( ApplicationDbContext dbContext, UserContext userContext, AccountRepository accountRepository, BoardRepository boardRepository, RoleRepository roleRepository, SmileyRepository smileyRepository, IHubContext<ForumHub> forumHub, IActionContextAccessor actionContextAccessor, IUrlHelperFactory urlHelperFactory, IImageStore imageStore, BBCodeParser bbcParser, GzipWebClient webClient, ImgurClient imgurClient, YouTubeClient youTubeClient, ILogger<MessageRepository> log ) { DbContext = dbContext; UserContext = userContext; AccountRepository = accountRepository; BoardRepository = boardRepository; RoleRepository = roleRepository; SmileyRepository = smileyRepository; ForumHub = forumHub; UrlHelper = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext); ImageStore = imageStore; BBCParser = bbcParser; WebClient = webClient; ImgurClient = imgurClient; YouTubeClient = youTubeClient; Log = log; }
// writer async public static Task XmlGenerateHelp(StringBuilder SB, IEnumerable <CmdletObject> cmdlets, ProgressBar pb, Boolean isOffline) { List <CmdletObject> cmdletsToProcess = isOffline ? new List <CmdletObject>(cmdlets) : new List <CmdletObject>(cmdlets.Where(x => x.GeneralHelp.Status != ItemStatus.Missing)); if (cmdletsToProcess.Count == 0) { return; } BBCodeParser bbrules = HtmlProcessor.GetParser(ParserType.Clear); Double duration = 0; if (pb != null) { duration = 100.0 / cmdletsToProcess.Count; } SB.Append("<helpItems schema=\"maml\">" + n); foreach (CmdletObject cmdlet in cmdletsToProcess) { await XmlGenerateBody(bbrules, SB, cmdlet); if (pb != null) { pb.Value += duration; } } SB.Append("</helpItems>"); }
private void Update() { if (!this.IsLoaded || !this.dirty) { return; } var bbcode = this.BBCode; this.Inlines.Clear(); if (!string.IsNullOrWhiteSpace(bbcode)) { Inline inline; try { var parser = new BBCodeParser(bbcode, this) { Commands = this.LinkNavigator.Commands }; inline = parser.Parse(); } catch (Exception) { // parsing failed, display BBCode value as-is inline = new Run { Text = bbcode }; } this.Inlines.Add(inline); } this.dirty = false; }
static void HtmlGenerateExamples(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.Append("<h2><strong>Examples</strong></h2>" + _nl); foreach (Example example in cmdlet.Examples) { String name = String.IsNullOrEmpty(example.Name) ? "unknown" : example.Name; SB.Append("<h3>" + SecurityElement.Escape(name) + "</h3>" + _nl); if (!String.IsNullOrEmpty(example.Cmd)) { String cmd; if (!example.Cmd.StartsWith("PS C:\\>")) { cmd = "PS C:\\> " + example.Cmd; } else { cmd = example.Cmd; } SB.Append("<pre style=\"margin-left: 40px;\">" + SecurityElement.Escape(cmd) + "</pre>" + _nl); } if (!String.IsNullOrEmpty(example.Output)) { SB.Append("<pre style=\"margin-left: 40px;\">" + SecurityElement.Escape(example.Output) + "</pre>" + _nl); } if (!String.IsNullOrEmpty(example.Description)) { String str = rules.ToHtml(example.Description); SB.Append("<p style=\"margin-left: 40px;\">" + str + "</p>" + _nl); } } }
public static string CSTReplaceString(string data, bool hasExpire) { var split = data.Substring(1).Split(';'); if (split.Length < (hasExpire ? 3 : 2)) { return(data); } var args = split.Skip((hasExpire)?3:2).Select(x => BBCodeParser.SanitizeBB(x)).ToArray(); if (hasExpire) { uint expire; if (uint.TryParse(split[0], out expire) && expire > 0) { var date = ClientEpoch.ToDate(expire); date = date.ToLocalTime(); var dateString = date.ToShortTimeString() + " " + date.ToShortDateString(); for (int i = 0; i < args.Length; i++) { if (args[i] == split[0]) { args[i] = dateString; } } } } int off = hasExpire ? 1 : 0; return(GameFacade.Strings.GetString(split[off], split[1 + off], args)); }
/// <summary> /// Создать <see cref="AdvertisePanel"/>. /// </summary> public AdvertisePanel() { InitializeComponent(); if (DesignerProperties.GetIsInDesignMode(this)) return; _client = ConfigManager.TryGetService<NotificationClient>() ?? new NotificationClient(); _client.NewsReceived += OnNewsReceived; var sizes = new[] { 10, 20, 30, 40, 50, 60, 70, 110, 120 }; _parser = new BBCodeParser(new[] { new BBTag("b", "<b>", "</b>"), new BBTag("i", "<span style=\"font-style:italic;\">", "</span>"), new BBTag("u", "<span style=\"text-decoration:underline;\">", "</span>"), new BBTag("center", "<div style=\"align:center;\">", "</div>"), new BBTag("size", "<span style=\"font-size:${fontSize}%;\">", "</div>", new BBAttribute("fontSize", "", c => sizes[c.AttributeValue.To<int>()].To<string>())), new BBTag("code", "<pre class=\"prettyprint\">", "</pre>"), new BBTag("img", "<img src=\"${content}\" />", "", false, true), new BBTag("quote", "<blockquote>", "</blockquote>"), new BBTag("list", "<ul>", "</ul>"), new BBTag("*", "<li>", "</li>", true, false), new BBTag("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href")), }); _timer = new DispatcherTimer(); _timer.Tick += OnTick; _timer.Interval = new TimeSpan(0, 1, 0); _timer.Start(); }
public void TextNodeHtmlTemplate() { var parserNull = new BBCodeParser(ErrorMode.Strict, null, new[] { new BBTag("b", "<b>", "</b>"), }); var parserEmpty = new BBCodeParser(ErrorMode.Strict, "", new[] { new BBTag("b", "<b>", "</b>"), }); var parserDiv = new BBCodeParser(ErrorMode.Strict, "<div>${content}</div>", new[] { new BBTag("b", "<b>", "</b>"), }); Assert.AreEqual(@"", parserNull.ToHtml(@"")); Assert.AreEqual(@"abc", parserNull.ToHtml(@"abc")); Assert.AreEqual(@"abc<b>def</b>", parserNull.ToHtml(@"abc[b]def[/b]")); Assert.AreEqual(@"", parserEmpty.ToHtml(@"")); Assert.AreEqual(@"", parserEmpty.ToHtml(@"abc")); Assert.AreEqual(@"<b></b>", parserEmpty.ToHtml(@"abc[b]def[/b]")); Assert.AreEqual(@"", parserDiv.ToHtml(@"")); Assert.AreEqual(@"<div>abc</div>", parserDiv.ToHtml(@"abc")); Assert.AreEqual(@"<div>abc</div><b><div>def</div></b>", parserDiv.ToHtml(@"abc[b]def[/b]")); }
/// <summary> /// Создать <see cref="AdvertisePanel"/>. /// </summary> public AdvertisePanel() { InitializeComponent(); if (DesignerProperties.GetIsInDesignMode(this)) { return; } _client = ConfigManager.TryGetService <NotificationClient>() ?? new NotificationClient(); _client.NewsReceived += OnNewsReceived; var sizes = new[] { 10, 20, 30, 40, 50, 60, 70, 110, 120 }; _parser = new BBCodeParser(new[] { new BBTag("b", "<b>", "</b>"), new BBTag("i", "<span style=\"font-style:italic;\">", "</span>"), new BBTag("u", "<span style=\"text-decoration:underline;\">", "</span>"), new BBTag("center", "<div style=\"align:center;\">", "</div>"), new BBTag("size", "<span style=\"font-size:${fontSize}%;\">", "</div>", new BBAttribute("fontSize", "", c => sizes[c.AttributeValue.To <int>()].To <string>())), new BBTag("code", "<pre class=\"prettyprint\">", "</pre>"), new BBTag("img", "<img src=\"${content}\" />", "", false, true), new BBTag("quote", "<blockquote>", "</blockquote>"), new BBTag("list", "<ul>", "</ul>"), new BBTag("*", "<li>", "</li>", true, false), new BBTag("url", "<a href=\"${href}\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href")), }); _timer = new DispatcherTimer(); _timer.Tick += OnTick; _timer.Interval = new TimeSpan(0, 1, 0); _timer.Start(); }
public MessageRepository( ApplicationDbContext dbContext, UserContext userContext, AccountRepository accountRepository, BoardRepository boardRepository, SmileyRepository smileyRepository, IImageStore imageStore, BBCodeParser bbcParser, GzipWebClient webClient, ImgurClient imgurClient, YouTubeClient youTubeClient, ILogger <MessageRepository> log ) { DbContext = dbContext; CurrentUser = userContext; AccountRepository = accountRepository; BoardRepository = boardRepository; SmileyRepository = smileyRepository; ImageStore = imageStore; BBCParser = bbcParser; WebClient = webClient; ImgurClient = imgurClient; YouTubeClient = youTubeClient; Log = log; }
private void ComputeText() { var msg = m_Options.Message; if (m_Options.AllowEmojis) { msg = GameFacade.Emojis.EmojiToBB(BBCodeParser.SanitizeBB(msg)); } else if (m_Options.AllowBB) { msg = GameFacade.Emojis.EmojiToBB(msg); } m_MessageText = TextRenderer.ComputeText(msg, new TextRendererOptions { Alignment = m_Options.Alignment, MaxWidth = m_Options.Width - 64, Position = new Microsoft.Xna.Framework.Vector2(32, 38), Scale = _Scale, TextStyle = m_TextStyle, WordWrap = true, TopLeftIconSpace = IconSpace, BBCode = m_Options.AllowEmojis || m_Options.AllowBB }, this); m_TextDirty = false; }
static void htmlGenerateExamples(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.AppendLine("<h2>Examples</h2>"); for (Int32 index = 0; index < cmdlet.Examples.Count; index++) { Example example = cmdlet.Examples[index]; String name = String.IsNullOrEmpty(example.Name) ? $"Example {index + 1}" : example.Name; SB.AppendLine($"<h3>{SecurityElement.Escape(name)}</h3>"); if (!String.IsNullOrEmpty(example.Cmd)) { String cmd = !example.Cmd.StartsWith("PS C:\\>") ? $"PS C:\\> {example.Cmd}" : example.Cmd; SB.AppendLine($"<pre style=\"margin-left: 40px;\">{SecurityElement.Escape(cmd)}</pre>"); } if (!String.IsNullOrEmpty(example.Output)) { SB.AppendLine($"<pre style=\"margin-left: 40px;\">{SecurityElement.Escape(example.Output)}</pre>"); } if (!String.IsNullOrEmpty(example.Description)) { String str = rules.ToHtml(example.Description); SB.AppendLine(addIndentedParagraphText(str)); } } }
static void htmlGenerateReturnTypes(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.Append("<h2>Outputs</h2>" + _nl); List <String> returnTypes = new List <String>(cmdlet.GeneralHelp.ReturnType.Split(';')); List <String> returnUrls = new List <String>(cmdlet.GeneralHelp.ReturnUrl.Split(';')); List <String> returnDescription = new List <String>(cmdlet.GeneralHelp.ReturnTypeDescription.Split(';')); for (Int32 index = 0; index < returnTypes.Count; index++) { if (index < returnUrls.Count) { SB.AppendLine(String.IsNullOrEmpty(returnUrls[index]) ? addIndentedParagraphText(rules.ToHtml(returnTypes[index])) : addIndentedParagraphText($"<a href=\"{returnUrls[index]}\">{rules.ToHtml(returnTypes[index])}</a>")); } else { SB.AppendLine(addIndentedParagraphText(rules.ToHtml(returnTypes[index]))); } if (index < returnDescription.Count) { SB.AppendLine($"<p style=\"margin-left: 80px;\">{rules.ToHtml(returnDescription[index])}</p>"); } } }
static void XmlGenerateCmdletDetail(BBCodeParser bbRules, StringBuilder SB, CmdletObject cmdlet) { SB.Append("<!--Generated by PS Cmdlet Help Editor-->" + n); SB.Append(" <command:details>" + n); SB.Append(" <command:name>"); SB.Append(SecurityElement.Escape(cmdlet.Name)); SB.Append("</command:name>" + n); // synopsis SB.Append(" <maml:description>"+ n); SB.Append(generatePragraphs(cmdlet.GeneralHelp.Synopsis, bbRules, 3)); SB.Append(" </maml:description>"+ n); // TODO copyrights SB.Append(" <maml:copyright>"+ n); SB.Append(" <maml:para />"+ n); //SB.Append(" <!--Add copy right info here.-->" + n); SB.Append(" </maml:copyright>"+ n); SB.Append(" <command:verb>"); SB.Append(SecurityElement.Escape(cmdlet.Verb)); SB.Append("</command:verb>" + n); SB.Append(" <command:noun>"); SB.Append(SecurityElement.Escape(cmdlet.Noun)); SB.Append("</command:noun>" + n); //dev version SB.Append(" <dev:version />"+ n); //End </commnd:details> SB.Append(" </command:details>" + n); //Add Cmdlet detailed description SB.Append(" <maml:description>" + n); SB.Append(generatePragraphs(cmdlet.GeneralHelp.Description, bbRules, 2)); SB.Append(" </maml:description>" + n); }
static void HtmlGenerateReturnTypes(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.Append("<h2><strong>Outputs</strong></h2>" + _nl); List <String> returnTypes = new List <String>(cmdlet.GeneralHelp.ReturnType.Split(';')); List <String> returnUrls = new List <String>(cmdlet.GeneralHelp.ReturnUrl.Split(';')); List <String> returnDescription = new List <String>(cmdlet.GeneralHelp.ReturnTypeDescription.Split(';')); for (Int32 index = 0; index < returnTypes.Count; index++) { if (index < returnUrls.Count) { if (String.IsNullOrEmpty(returnUrls[index])) { SB.Append("<p style=\"margin-left: 40px;\">" + rules.ToHtml(returnTypes[index]) + "</p>" + _nl); } else { SB.Append("<p style=\"margin-left: 40px;\"><a href=\"" + returnUrls[index] + "\">" + rules.ToHtml(returnTypes[index]) + "</a></p>" + _nl); } } else { SB.Append("<p style=\"margin-left: 40px;\">" + rules.ToHtml(returnTypes[index]) + "</p>" + _nl); } if (index < returnDescription.Count) { SB.Append("<p style=\"margin-left: 80px;\">" + rules.ToHtml(returnDescription[index]) + "</p>" + _nl); } } }
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 void TestParseDocuments(string inputFile, string outputFile) { var input = GetResource(inputFile); var parser = new BBCodeParser(); Assert.Equal(GetResource(outputFile), parser.ToHtml(input)); }
public void NewlineTrailingOpeningTagIsIgnored() { var parser = new BBCodeParser(ErrorMode.ErrorFree, null, new[] { new BBTag("code", "<pre>", "</pre>") }); var input = "[code]\nHere is some code[/code]"; var expected = "<pre>Here is some code</pre>"; // No newline after the opening PRE Assert.AreEqual(expected, parser.ToHtml(input)); }
public void TagContentTransformer() { var parser = new BBCodeParser(new[] { new BBTag("b", "<b>", "</b>", true, true, content => content.Trim()), }); Assert.AreEqual("<b>abc</b>", parser.ToHtml("[b] abc [/b]")); }
static void HtmlGenerateDescription(BBCodeParser rules, StringBuilder SB, IReadOnlyList <CmdletObject> cmdlets, CmdletObject cmdlet) { SB.Append("<h2><strong>Description</strong></h2>" + _nl); if (!String.IsNullOrEmpty(cmdlet.GeneralHelp.Description)) { String str = rules.ToHtml(GenerateHtmlLink(cmdlet.GeneralHelp.Description, cmdlets)); SB.Append("<p style=\"margin-left: 40px;\">" + str + "</p>" + _nl); } }
static void HtmlGenerateNotes(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.Append("<h2><strong>Notes</strong></h2>" + _nl); if (!String.IsNullOrEmpty(cmdlet.GeneralHelp.Notes)) { String str = rules.ToHtml(GenerateHtmlLink(cmdlet.GeneralHelp.Notes, null)); SB.Append("<p style=\"margin-left: 40px;\">" + str + "</p>" + _nl); } }
static void htmlGenerateNotes(BBCodeParser rules, StringBuilder SB, CmdletObject cmdlet) { SB.AppendLine("<h2>Notes</h2>"); if (!String.IsNullOrEmpty(cmdlet.GeneralHelp.Notes)) { String str = rules.ToHtml(generateHtmlLink(cmdlet.GeneralHelp.Notes, null)); SB.AppendLine(addIndentedParagraphText(str)); } }
static void XmlGenerateNotes(BBCodeParser bbRules, StringBuilder SB, CmdletObject cmdlet) { SB.Append(" <maml:alertSet>" + n); SB.Append(" <maml:title></maml:title>"+ n); SB.Append(" <maml:alert>"+ n); SB.Append(generatePragraphs(cmdlet.GeneralHelp.Notes, bbRules, 3)); SB.Append(" </maml:alert>"+ n); SB.Append(" </maml:alertSet>" + n); }
static void htmlGenerateDescription(BBCodeParser rules, StringBuilder SB, IReadOnlyList <CmdletObject> cmdlets, CmdletObject cmdlet) { SB.AppendLine("<h2>Description</h2>"); if (!String.IsNullOrEmpty(cmdlet.GeneralHelp.Description)) { String str = rules.ToHtml(generateHtmlLink(cmdlet.GeneralHelp.Description, cmdlets)); SB.AppendLine(addIndentedParagraphText(str)); } }
/// <summary> /// HTML encodes a string then parses BB codes. /// </summary> /// <param name="text">The string to HTML encode anad BB code parse</param> /// <returns></returns> public string ParseBBCodeText(string text) { var tags = _bbCodeRepository.Get().Select(GetTag).ToList(); var parser = new BBCodeParser(ErrorMode.ErrorFree, null, tags); var result = parser.ToHtml(text); result = result.Replace(Environment.NewLine, "<br />"); return(result); }