public void Should_show_current_timestamp_with_different_format() { var parser = new ButterflyParser(); parser.LoadDefaultStrategies(new DefaultParseStrategyFactory()); parser.MacroFactory = new ActivatorFactory<IButterflyMacro>(new NamedTypeRegistry<IButterflyMacro>().RegisterType<TimestampMacro>("timestamp")); var text = parser.ParseAndReturn("[::timestamp|format=yyyy]"); AssertWithNoRegardForLineBreaks(text, string.Format("<p>{0}</p>", DateTime.UtcNow.Year)); }
public void Should_show_current_timestamp() { var parser = new ButterflyParser(); parser.LoadDefaultStrategies(new DefaultParseStrategyFactory()); parser.MacroFactory = new ActivatorFactory<IButterflyMacro>(new NamedTypeRegistry<IButterflyMacro>().RegisterType<TimestampMacro>("timestamp")); var text = parser.ParseAndReturn("[::timestamp]"); Assert.That(text, Is.StringMatching(@"<p>\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ</p>")); }
public void Should_update_input_with_macro_value() { var parser = new ButterflyParser(); parser.LoadDefaultStrategies(new DefaultParseStrategyFactory()); parser.MacroFactory = new ActivatorFactory<IButterflyMacro>(new NamedTypeRegistry<IButterflyMacro>().RegisterType<FooMacro>("foo")); var result = parser.Parse("[::foo] foo [::foo]"); var text = parser.FlushAndReturn(); Assert.That(result.Markup, Is.EqualTo("bar foo bar")); AssertWithNoRegardForLineBreaks(text, "<p>bar foo bar</p>"); }
public void Should_parse_markup_in_macros() { var parser = new ButterflyParser(); parser.LoadDefaultStrategies(new DefaultParseStrategyFactory()); parser.MacroFactory = new ActivatorFactory<IButterflyMacro>(new NamedTypeRegistry<IButterflyMacro>().RegisterType<BarMacro>("bar")); var result = parser.Parse("[::bar]"); var text = parser.FlushAndReturn(); Assert.That(result.Markup, Is.EqualTo("__bold__")); AssertWithNoRegardForLineBreaks(text, "<p><strong>bold</strong></p>"); }
public ActionResult Index(ParseModel model) { var parser = new ButterflyParser(); parser.LoadDefaultStrategies(new DefaultParseStrategyFactory()); parser.Analyzer = new HtmlAnalyzer(new StringWriter()); try { return Json(new { error = (string)null, html = parser.ParseAndReturn(model.MarkUp) }); } catch (Exception e) { return Json(new { error = e.Message, html = (string)null }); } }