Skip to content

Instantly share code, notes, and snippets.

@osima
Created February 10, 2011 14:29
Show Gist options
  • Select an option

  • Save osima/820595 to your computer and use it in GitHub Desktop.

Select an option

Save osima/820595 to your computer and use it in GitHub Desktop.
add anchor macro before h4 line.
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