Skip to content

Instantly share code, notes, and snippets.

@osima
Created January 14, 2012 23:14
Show Gist options
  • Save osima/1613311 to your computer and use it in GitHub Desktop.
Save osima/1613311 to your computer and use it in GitHub Desktop.
code sketch for markdown-to-textile convert with radeox
@Grab(group='radeox', module='radeox', version='1.0-b2')
import org.radeox.api.engine.context.InitialRenderContext
import org.radeox.engine.*
import org.radeox.engine.context.*
import org.radeox.filter.*
import org.radeox.filter.context.*
import org.radeox.filter.regex.*
import org.radeox.macro.*
import org.radeox.regex.*
class TextRenderEngine extends BaseRenderEngine{
TextRenderEngine(InitialRenderContext cont){ super(cont) }
@Override
protected void init() {
if (null == fp) {
fp = new FilterPipe(initialContext);
fp.addFilter(new HeaderFilter())
fp.init();
}
}
}
class HeaderFilter extends RegexTokenFilter {
HeaderFilter() { super(/^#([^#]*$)/) }
void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) {
buffer << "h1. ${result.group(1).trim()}"
}
}
context = new BaseInitialRenderContext()
engine = new TextRenderEngine(context)
content = '''
# Hello Radeox!
The radeox is very useful for text-rendering.
'''
println engine.render(content, context)

Hello Radeox!

The radeox is very useful for text-rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment