The radeox is very useful for text-rendering.
Created
January 14, 2012 23:14
-
-
Save osima/1613311 to your computer and use it in GitHub Desktop.
code sketch for markdown-to-textile convert with radeox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment