Created
February 10, 2011 14:29
-
-
Save osima/820595 to your computer and use it in GitHub Desktop.
add anchor macro before h4 line.
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
| def inputf = new File(args[0]) | |
| def outputf = new File(args[1]) | |
| def text = inputf.getText('UTF-8') | |
| def w = outputf.newWriter('UTF-8') | |
| def num = 0 | |
| def anchorid = 'unknown' | |
| new StringReader(text).each{ line-> | |
| def m1 = (line =~ /^\{anchor:(.+?)\}/) | |
| if( m1.find() ){ | |
| anchorid = m1.group(1) | |
| num = 0 | |
| } | |
| def m2 = (line =~ /^h4\.\s+/) | |
| if( m2.find() ){ | |
| num = num+1 | |
| w.println "{anchor:${anchorid}-${num}}" | |
| } | |
| w.println line | |
| } | |
| w.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment