Skip to content

Instantly share code, notes, and snippets.

@osima
Created June 11, 2010 00:25
Show Gist options
  • Save osima/433858 to your computer and use it in GitHub Desktop.
Save osima/433858 to your computer and use it in GitHub Desktop.
MacroProcessor.groovyの利用例その1
//
// MacroProcessor.groovyの利用例
//
// マクロをどう処理するかを記述
def proc( macroText ){
def mp = new MacroProcessor( macroText )
'<span aid:cstyle="' + mp.key + '">' + mp.value + '</span>'
}
//
// テスト用本文
//
def text = """
これは{bold:本体のみ}の
提供になります。
"""
//
// マクロ部分を置き換えるためのコード
//
def sb = ''<<''
def m = MacroProcessor.PAT.matcher(text);
def pointer = 0
def result = m.find()
while( result ){
sb << text.substring( pointer, m.start() )
def macroText = text.substring( m.start(),m.end() )
sb << proc( macroText )
pointer = m.end()
result = m.find()
}
sb << text.substring(pointer)
println sb.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment