public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => Array.Empty <TextSpanReplaceInfo>(), null); Assert.Equal(tree1, tree2); }
public Blog GetBlogFull(int id) { var blog = DB.Blog.First(x => x.Id == id); blog.Post = BBCode.ParsePost(blog.Post); return(blog); }
private void generateTopic() { string sql = "SELECT UserDetails.UName, UserDetails.ProfileID, UserDetails.USign, UserDetails.UType, ReplyDate, ReplyContent, ReplyID, ReplyStatus, UserDetails.Username FROM Reply LEFT JOIN UserDetails ON Reply.ReplyCreator = UserDetails.Username WHERE TopicID= @tid AND (ReplyStatus= @status OR ReplyStatus= @status2) ORDER BY ReplyDate"; SqlDataAdapter da = new SqlDataAdapter(sql, con); da.SelectCommand.Parameters.AddWithValue("@tid", Request.QueryString["title"].ToString()); da.SelectCommand.Parameters.AddWithValue("@status", "Active"); da.SelectCommand.Parameters.AddWithValue("@status2", "Deleted"); SqlConnectionStringBuilder cmdbuild = new SqlConnectionStringBuilder(); DataTable dt = new DataTable(); da.Fill(dt); con.Close(); int page = Convert.ToInt32(Request.QueryString["page"].ToString()); int startingrow = (page - 1) * rowToPrint; int endingrow = (page * rowToPrint); if (endingrow > dt.Rows.Count) { endingrow = dt.Rows.Count; } for (int i = startingrow; i < endingrow; i++) { string title = dt.Rows[i]["Username"].ToString(); //if (title.Equals(string.Empty)) //{ // title = dt.Rows[i]["Username"].ToString(); //} NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty); queryString["id"] = dt.Rows[i]["ProfileID"].ToString(); string imageurl = "ProfileImageHandler.ashx?" + queryString; string username = dt.Rows[i]["Username"].ToString(); string date = getDataTableDate(dt.Rows[i]["ReplyDate"]); string content = dt.Rows[i]["ReplyContent"].ToString(); string userType = dt.Rows[i]["UType"].ToString(); if (userType.Equals("User")) { userType = "Member"; } else if (userType.Equals("Moderator") || userType.Equals("Admin")) { userType = "Moderator"; } string userStatus = dt.Rows[i]["USign"].ToString(); string replyID = dt.Rows[i]["ReplyID"].ToString(); int replyStatus = dt.Rows[i]["ReplyStatus"].ToString().Equals("Active")?1:2; content = BBCode.ToHtml(content); generateReply(title, imageurl, date, content, userType, userStatus, replyID, replyStatus, username); //generateReply(title, imageurl, date, content); } int fullpageNumber = dt.Rows.Count / rowToPrint; int lastpageNumber = dt.Rows.Count % rowToPrint; if (lastpageNumber != 0) { fullpageNumber += 1; } generatePagination(page, fullpageNumber); }
protected void AssignmentRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { ApplicationDbContext dbContext = new ApplicationDbContext(); int assignmentId = int.Parse(e.CommandArgument.ToString()); Assignment assignment = dbContext.Assignments.Where(a => a.Id == assignmentId).FirstOrDefault(); AssignmentTitleLabel.Text = assignment.Title; try { AssignmentContentLabel.Text = BBCode.ToHtml(assignment.Content); } catch { AssignmentContentLabel.Text = "Some tags did not load correctly<br />" + assignment.Content; } Session["CurrentAssignment"] = assignment; SubmissionRepeater.DataBind(); GradeSubmissionView.DataBind(); HomePanel.Visible = false; AssignmentPanel.Visible = true; ActivePanelLabel.Text = "Assignments"; }
public void ReplaceTextSpans_ArbitraryTextSpans_NoCrash() { for (int i = 0; i < RandomValue.Int(100, 10); i++) { var tree1 = BBCodeTestUtil.GetAnyTree(); var chosenTexts = new List <string>(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => { var count = RandomValue.Int(3, 0); var indexes = new List <int>(); for (int i = 0; i < count; i++) { indexes.Add(RandomValue.Int(txt.Length, 0)); } indexes.Sort(); _output.WriteLine(string.Join(", ", indexes)); return (Enumerable.Range(0, count) .Select(i => { var maxIndex = i == count - 1 ? txt.Length : indexes[i + 1]; var text = RandomValue.String(); chosenTexts.Add(text); return new TextSpanReplaceInfo(indexes[i], RandomValue.Int(indexes[i] - maxIndex + 1, 0), new TextNode(text)); }) .ToArray()); }, null); var bbCode = tree2.ToBBCode(); if (!chosenTexts.All(s => bbCode.Contains(s))) { } Assert.All(chosenTexts, s => Assert.Contains(s, bbCode)); } }
// GET: wiki public async Task <IActionResult> Index(string title) { if (title == null) { return(Redirect(Config.GetUrl("glossary"))); } title = UtilityBLL.UppercaseFirst(UtilityBLL.ReplaceHyphinWithSpace(title)); var model = new WikiModelView(); model.isAllowed = true; var _lst = await WikiBLLC.Fetch_Record(_context, title); if (_lst.Count > 0) { model.Data = new JGN_Wiki() { term_complete = _lst[0].term_complete, description = BBCode.MakeHtml(WebUtility.HtmlDecode(_lst[0].description), true) }; } else { model.isAllowed = false; model.DetailMessage = SiteConfig.generalLocalizer["_no_records"].Value; } ViewBag.title = title; return(View(model)); }
public void ReplaceTextSpans_WhenNoModifications_TreeIsPreserved() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new TextSpanReplaceInfo[0], null); Assert.Same(tree1, tree2); }
public void ReplaceTextSpans_WhenEverythingIsConvertedToX_OutputContainsOnlyX_CheckedWithTreeWalk() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, txt.Length, new TextNode("x")), }, null); new TextAssertVisitor(str => Assert.True(str == "x")).Visit(tree2); }
public void ReplaceTextSpans_WhenEmptyModifications_TreeIsPreserved() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, 0, null), }, null); Assert.Equal(tree1.ToBBCode(), tree2.ToBBCode()); }
public void ReplaceTextSpans_WhenEverythingIsConvertedToX_OutputContainsOnlyX_CheckedWithContains() { var tree1 = BBCodeTestUtil.GetAnyTree(); var tree2 = BBCode.ReplaceTextSpans(tree1, txt => new[] { new TextSpanReplaceInfo(0, txt.Length, new TextNode("x")), }, null); Assert.True(!tree2.ToBBCode().Contains("a")); }
/// <summary> /// Formats the Last Post for the Topic Line /// </summary> /// <returns>Formatted Last Post Text</returns> protected string FormatLastPost() { string strReturn = ForumPage.GetText("no_posts"); DataRowView row = m_row; if (row["LastMessageID"].ToString().Length > 0) { string strMiniPost = ForumPage.GetThemeContents("ICONS", (DateTime.Parse(row["LastPosted"].ToString()) > Mession.LastVisit) ? "ICON_NEWEST" : "ICON_LATEST"); string strBy = String.Format(ForumPage.GetText("by"), String.Format("<a href=\"{0}\">{1}</a> <a title=\"{4}\" href=\"{3}\"><img border=0 src='{2}'></a>", OrionGlobals.resolveBase(string.Format("userinfo.aspx?id={0}", row["LastUserID"])), BBCode.EncodeHTML(row["LastUserName"].ToString()), strMiniPost, Forum.GetLink(Pages.posts, "m={0}#{0}", row["LastMessageID"]), ForumPage.GetText("GO_LAST_POST") )); strReturn = String.Format("{0}<br />{1}", ForumPage.FormatDateTimeTopic(Convert.ToDateTime(row["LastPosted"])), strBy); } return(strReturn); }
protected void LessonRepeater_ItemCommand(object source, RepeaterCommandEventArgs e) { ApplicationDbContext dbContext = new ApplicationDbContext(); int lessonId = int.Parse(e.CommandArgument.ToString()); Lesson lesson = dbContext.Lessons.Where(l => l.Id == lessonId).FirstOrDefault(); LessonTitleLabel.Text = lesson.Title; try { LessonContentLabel.Text = BBCode.ToHtml(lesson.Content); } catch { LessonContentLabel.Text = "Some tags did not load correctly<br />" + lesson.Content; } Session["CurrentLesson"] = lesson; //currentLesson = lesson; LessonAttachmentRepeater.DataBind(); HomePanel.Visible = false; LessonPanel.Visible = true; ActivePanelLabel.Text = "Lessons"; }
public void Escape_Unescape_Roundtrip([PexAssumeNotNull] string text) { var escaped = BBCode.EscapeText(text); var unescaped = BBCode.UnescapeText(escaped); Assert.AreEqual(text, unescaped); }
/// <summary> /// Send mails for a workflow /// </summary> /// <param name="email"></param> /// <param name="title"></param> /// <param name="subject"></param> /// <param name="body"></param> private void sendMail(eMail email, string title, string subject, string body) { BBCode bbc = new BBCode(); body = bbc.Transform(body); var listToParse = new List <eMail_KeyValuePair>(); listToParse.Add(new eMail_KeyValuePair() { key = "{title}", value = title }); listToParse.Add(new eMail_KeyValuePair() { key = "{subject}", value = subject }); listToParse.Add(new eMail_KeyValuePair() { key = "{website_name}", value = Configuration_BSO.GetCustomConfig("title") }); listToParse.Add(new eMail_KeyValuePair() { key = "{website_url}", value = Configuration_BSO.GetCustomConfig("url.application") }); listToParse.Add(new eMail_KeyValuePair() { key = "{body}", value = body }); email.Subject = subject; email.Body = email.ParseTemplate(Properties.Resources.template_NotifyWorkflow, listToParse); email.Send(); }
public CommentViewModel(MBlogModel.Comment comment) { Comment = BBCode.ToHtml(comment.CommentText); Commented = comment.Commented; EMail = comment.EMail; Name = comment.Name ?? "Anonymous"; }
protected void Page_Load(object sender, EventArgs e) { if (User == null) { YafBuildLink.Redirect(ForumPages.login, "ReturnUrl={0}", General.GetSafeRawUrl()); } // check if this feature is disabled if (!PageContext.BoardSettings.AllowPrivateMessages) { YafBuildLink.Redirect(ForumPages.info, "i=5"); } if (!IsPostBack) { if (String.IsNullOrEmpty(Request.QueryString ["pm"])) { YafBuildLink.AccessDenied(); } PageLinks.AddLink(PageContext.BoardSettings.Name, YafBuildLink.GetLink(ForumPages.forum)); PageLinks.AddLink(PageContext.PageUserName, YafBuildLink.GetLink(ForumPages.cp_profile)); // handle custom BBCode javascript or CSS... BBCode.RegisterCustomBBCodePageElements(Page, this.GetType()); BindData(); } }
public BBCodePanel(string bbcode) { BBCode parser = new BBCode(); Node root = parser.CreateNode("root"); this.Render(parser.ParseTree(bbcode.Replace("[*]", "[/*][*]").Replace("[/list]", "[/*][/list]").Replace("[list][/*]", "[list]"), root), this); }
private string GetPreviewPost(string post) { post = BBCode.ParsePost(post); var temp = post.Split("<br />", StringSplitOptions.RemoveEmptyEntries); return(temp[0] + "<br /><br />" + (temp.Count() > 1 ? temp[1] : "")); }
static void ReplaceTextSpans_ManualTestCases_TestCase(string bbCode, string expected, Func <string, IList <TextSpanReplaceInfo> > getTextSpansToReplace, Func <TagNode, bool> tagFilter) { var tree1 = BBCodeTestUtil.GetParserForTest(ErrorMode.Strict, false, BBTagClosingStyle.AutoCloseElement, false).ParseSyntaxTree(bbCode); var tree2 = BBCode.ReplaceTextSpans(tree1, getTextSpansToReplace ?? (txt => new TextSpanReplaceInfo[0]), tagFilter); Assert.Equal(expected, tree2.ToBBCode()); }
public void Escape_Unescape_Roundtrip(string text) { var escaped = BBCode.EscapeText(text); var unescaped = BBCode.UnescapeText(escaped); Assert.Equal(text, unescaped); }
string ParseNode(BBCodeNode node, BBCode code = null) { // Text only nodes doesn't need any parsing if (string.IsNullOrEmpty(node.TagName)) { string innerHtml = ParseNewLines(node.InnerContent); return(innerHtml); } if (code == null) { code = GetBBCodeForNode(node); } if (code == null) { string innerHtml = node.OpenTag; // If we find unknown bbcodes, try parsing their inner content html and display the raw outer bbcode so that the user know it's not parseable. if (node.Childs != null) { node.Childs.ForEach(childNode => innerHtml += ParseNode(childNode)); } else { // We also end up here if square brackets were used in other ways like quote, which shouldnt got destroyed: "He [mr xyz] said that..." // In this case, InnerContent is the content after the brackets and childs may be null. No childs exists. innerHtml += ParseNewLines(node.InnerContent); } // ParseNewLines() call is exceptional here. Regularly it's handled by GetNodeInnerContentHtml() return(innerHtml + node.CloseTag); } string html = ""; if (code.ParserFunc != null) { // From a parser function, we expect to handle the ENTIRE node. Only for this reason, the inner html is required and only provided here node.InnerHtml = GetNodeInnerContentHtml(node, code.NestedChild); html = code.ParserFunc(node); } else { string openTag = code.HtmlTag; if (!string.IsNullOrEmpty(code.ArgumentHtmlAttribute)) { // When theres no custom display text (e.g. [url]https://ecosia.org[/url]) we set the argument like in [url=https://ecosia.org]https://ecosia.org[/url] to have a unified link target if (code.BBCodeName == "url" && node.Argument == null) { node.Argument = node.InnerContent; } openTag = openTag.Replace(">", $" {code.ArgumentHtmlAttribute}=\"{node.Argument}\">"); } string closeTag = code.HtmlTag.Replace("<", "</"); html += openTag + GetNodeInnerContentHtml(node, code.NestedChild) + closeTag; } return(html); }
public void Escape_Parse_ToText_Roundtrip(string text) { var escaped = BBCode.EscapeText(text); var unescaped = GetSimpleParser().ParseSyntaxTree(escaped); var text2 = unescaped.ToText(); Assert.Equal(text, text2); }
private void BbCodeChanged(DependencyPropertyChangedEventArgs args) { Inlines.Clear(); if (args.NewValue == null) { return; } Inlines.Add(BBCode.ToInlines((SyntaxTreeNode)args.NewValue)); }
public void DefaultParserWellconfigured([PexAssumeNotNull] string input) { try { BBCode.ToHtml(input); } catch (BBCodeParsingException) { } }
public void DefaultParserWellconfigured() { try { BBCode.ToHtml(RandomValue.String()); } catch (BBCodeParsingException) { } }
public override bool IsValid(object value) { try { BBCode.ToHtml(value.ToString()); } catch (Exception) { return(false); } return(true); }
public ActionResult EditBBCode(int BBCodeID) { BBCode bbCode = _bbCodeRepository.Get(BBCodeID); BBCodeViewModel model = new BBCodeViewModel() { Tag = bbCode.Tag, Parse = bbCode.Parse, BBCodeID = bbCode.BBCodeID }; return(View(model)); }
/// <summary> /// Send mails for a workflow /// </summary> /// <param name="email"></param> /// <param name="title"></param> /// <param name="subject"></param> /// <param name="body"></param> private void sendMail(eMail email, string title, string subject, string body) { BBCode bbc = new BBCode(); body = bbc.Transform(body, true); var listToParse = new List <eMail_KeyValuePair>(); listToParse.Add(new eMail_KeyValuePair() { key = "{title}", value = title }); listToParse.Add(new eMail_KeyValuePair() { key = "{subject}", value = subject }); listToParse.Add(new eMail_KeyValuePair() { key = "{website_name}", value = Configuration_BSO.GetCustomConfig(ConfigType.global, "title") }); listToParse.Add(new eMail_KeyValuePair() { key = "{website_url}", value = Configuration_BSO.GetCustomConfig(ConfigType.global, "url.application") }); listToParse.Add(new eMail_KeyValuePair() { key = "{body}", value = body }); listToParse.Add(new eMail_KeyValuePair() { key = "{image_source}", value = Configuration_BSO.GetCustomConfig(ConfigType.global, "url.logo") }); listToParse.Add(new eMail_KeyValuePair() { key = "{datetime_label}", value = Label.Get("label.date-time", Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code")) }); listToParse.Add(new eMail_KeyValuePair() { key = "{date_format}", value = Label.Get("label.date-format", Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code")) }); listToParse.Add(new eMail_KeyValuePair() { key = "{timezone}", value = Label.Get("label.timezone", Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code")) }); listToParse.Add(new eMail_KeyValuePair() { key = "{reason}", value = Label.Get("workflow.reason", Configuration_BSO.GetCustomConfig(ConfigType.global, "language.iso.code")) }); email.Subject = subject; email.Body = email.ParseTemplate(Properties.Resources.template_NotifyWorkflow, listToParse); email.Send(); }
private void AddMessage(MessageViewModel message) { TextBlock.Document.Blocks.Add(new Paragraph(BBCode.ToInlines(message.Formatted, tag => { if (tag.Tag.Name != "user") { return(null); } return(new InlineUIContainer(userViewFactory(tag.ToText()))); })) { Margin = new Thickness(0, 0, 0, App.Current.Theme.FontSize / 3) }); //TODO backlog, new }
public ActionResult EditBBCode(BBCodeViewModel model) { if (IsModelValidAndPersistErrors()) { BBCode bbCode = _bbCodeRepository.Get(model.BBCodeID); TryUpdateModel(bbCode); _bbCodeRepository.Update(bbCode); SetSuccess("BB Code edited"); return(RedirectToAction("BBCodes")); } return(RedirectToSelf(new { BBCodeID = model.BBCodeID })); }