Created
April 30, 2011 05:24
-
-
Save osima/949449 to your computer and use it in GitHub Desktop.
Hello Radeox 3
This file contains hidden or 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.macro.parameter.* | |
| import org.radeox.regex.* | |
| import org.radeox.filter.MacroFilter | |
| class TextRenderEngine extends BaseRenderEngine{ | |
| TextRenderEngine(InitialRenderContext cont){ super(cont) } | |
| @Override | |
| protected void init() { | |
| if (null == fp) { | |
| fp = new FilterPipe(initialContext); | |
| // 1) | |
| fp.addFilter(new HeaderFilter()) | |
| // 2) | |
| RegexFilter mf = new org.radeox.filter.MacroFilter() | |
| fp.addFilter( mf ) | |
| def repository = mf.getMacroRepository() | |
| MacroLoader loader = new MacroLoader() | |
| loader.add(repository, new QuoteMacro() ) | |
| fp.init() | |
| } | |
| } | |
| } | |
| class HeaderFilter extends RegexTokenFilter { | |
| HeaderFilter() { super(/^#([^#]*$)/) } | |
| void handleMatch(StringBuffer buffer, MatchResult result, FilterContext context) { | |
| buffer << "h1. ${result.group(1).trim()}" | |
| } | |
| } | |
| class QuoteMacro extends BaseMacro { | |
| String getName() {"quote"} | |
| void execute(Writer writer, MacroParameter params) { | |
| //def option = params.get(0) | |
| def content = params.content | |
| writer << "bq. ${content}" | |
| writer << System.getProperty('line.separator') | |
| } | |
| } | |
| context = new BaseInitialRenderContext() | |
| //engine = new BaseRenderEngine() | |
| engine = new TextRenderEngine(context) | |
| content = ''' | |
| # hello radeox! | |
| {quote} | |
| hogehoge | |
| {quote} | |
| ''' | |
| println engine.render(content, context) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment