Welcome to Butterfly

Butterfly is a markup transformer I wrote because I didn’t really like the syntax of MarkDown. It was originally written in C# and ported to JavaScript.

A summary of the syntax is here. A live demo is down below.


Technical Details

One major difference between Butterfly and other markup transformers is that Butterfly does not allow syntax errors. This is completely intentional, and, in my opinion, the right way of doing things. So if a scope isn’t closed an error will be raised.

Another difference is that it doesn’t exclusively use regular expressions to handle the parsing. This makes it a little bit slower (particularly for large blobs of markup), but ultimately much more modular. For example, if you don’t like using underscores to denote bold text, you can implement your own StrongStrategy and inject it into the parser with minimal fuss. Here is an example taken straight from the unit tests:

//use ?? instead of __ to denote bold text
public abstract class CustomStrongStrategy : InlineStrategy {
	protected Type Type { get { return ScopeTypeCache.Strong; } }

public class CustomOpenStrongStrategy : CustomStrongStrategy {
	public CustomOpenStrongStrategy() {
		AddSatisfier(new OpenNonNestableInlineScopeSatisfier(Type));

	protected override void DoExecute(ParseContext context) {
		OpenScope(new StrongScope(), context);

public class CustomCloseStrongStrategy : CustomStrongStrategy {
	public CustomCloseStrongStrategy() {
		AddSatisfier(new CurrentScopeMustMatchSatisfier(Type));

	protected override void DoExecute(ParseContext context) {

//now, inject it into the parser
var parser = new ButterflyParser()
	.LoadDefaultStrategies(new DefaultParseStrategyFactory())
Console.WriteLine(parser.ParseAndReturn("??bold??")); //<p><strong>bold</strong></p>

Live Demo

This demo uses the JavaScript version of Butterfly to perform client-side rendering as you type.

Elapsed time: