使用Groovy时MarkupBuilder,我需要将文本输出到文档中的位置,或者调用将文本输出到文档中的函数.目前,我正在使用未定义的标签"text"来进行输出.有没有更好的方法来编写这段代码?
li {
text("${type.getAlias()} blah blah ")
function1(type.getXYZ())
if (type instanceof Class1) {
text(" implements ")
ft.getList().each {
if (it == '') return
text(it)
if (!function2(type, it)) text(", ")
}
}
}
Run Code Online (Sandbox Code Playgroud)
实际上,现在推荐的方法是使用mkp.yield,例如,
src.p {
mkp.yield 'Some element that has a '
strong 'child element'
mkp.yield ' which seems pretty basic.'
}
Run Code Online (Sandbox Code Playgroud)
生产
<p>Some element that has a <strong>child element</strong> which seems pretty basic.</p>
Run Code Online (Sandbox Code Playgroud)