Skip to content

Instantly share code, notes, and snippets.

@lyhcode
Created February 21, 2012 10:17
Show Gist options
  • Select an option

  • Save lyhcode/1875635 to your computer and use it in GitHub Desktop.

Select an option

Save lyhcode/1875635 to your computer and use it in GitHub Desktop.
Groovy output HTML with MarkupBuilder
import groovy.xml.MarkupBuilder
def sb = new StringWriter()
def html = new MarkupBuilder(sb)
html.doubleQuotes = true
html.expandEmptyElements = true
html.omitEmptyAttributes = false
html.omitNullAttributes = false
html.html {
head {
title ('Heading')
script (src: 'test.js', type: 'text/javascript')
}
body {
mkp.yieldUnescaped('<!--')
mkp.yield('<test>')
mkp.yieldUnescaped('-->')
ul {
for (def i=0;i<10;i++) {
li (i)
}
}
}
}
println sb.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment