public void Parse_MatchedContentIsReplaced( [Frozen] IRenderShortcode renderShortcode, ShortcodeParser sut, IHtmlHelper helper ) { A.CallTo(() => renderShortcode.CanRender("test")).Returns(true); A.CallTo(() => renderShortcode.Render(helper, "test", A <Dictionary <string, string> > .Ignored)) .Returns("Updated text"); const string content = "[test]"; var result = sut.Parse(helper, content); result.ToString().Should().Be("Updated text"); }
public void Parse_GetsAttributesFromShortcode( [Frozen] IRenderShortcode renderShortcode, ShortcodeParser sut, IHtmlHelper helper ) { A.CallTo(() => renderShortcode.CanRender("test")).Returns(true); A.CallTo(() => renderShortcode.Render(helper, "test", A <Dictionary <string, string> > .That.Matches( dictionary => dictionary.ContainsKey("id") && dictionary["id"] == "123"))) .Returns("Updated text"); const string content = "[test id=\"123\"]"; var result = sut.Parse(helper, content); result.ToString().Should().Be("Updated text"); }
public void Parse_WithQuotes( [Frozen] IRenderShortcode renderShortcode, ShortcodeParser sut, IHtmlHelper helper ) { var content = "[test id=\"123\"] sdfs adfsdf sdaf sadf asdfsdaf sdf sdf more=(*&)(&knkjdhnf data]"; A.CallTo(() => renderShortcode.CanRender("test")).Returns(true); A.CallTo(() => renderShortcode.Render(helper, "test ", A <Dictionary <string, string> > .That.Matches( dictionary => dictionary.ContainsKey("id") && dictionary["id"] == "123" && !dictionary.ContainsKey("more") ))); var result = sut.Parse(helper, content); result.ToString().Should().Be(" sdfs adfsdf sdaf sadf asdfsdaf sdf sdf more=(*&)(&knkjdhnf data]"); }
public MvcHtmlString Parse(IHtmlHelper htmlHelper, string current) { if (string.IsNullOrWhiteSpace(current)) { return(MvcHtmlString.Empty); } current = ShortcodeMatcher.Replace(current, match => { var tagName = match.Groups[1].Value; if (!_renderShortcode.CanRender(tagName)) { return(string.Empty); } var matches = AttributeMatcher.Matches(match.Groups[2].Value); var attributes = matches.Cast <Match>().ToDictionary(m => m.Groups[1].Value, m => m.Groups[2].Value); return(_renderShortcode.Render(htmlHelper, tagName, attributes)); }); return(MvcHtmlString.Create(current)); }