HTML with Groovy MarkupBuilder, how do I elegantly mix tags and text?

When using Groovy MarkupBuilder, I have places where I need to output text to a document or call a function that outputs text to a document. I am currently using the undefined "text" tag for output. Is there a better way to write this code?

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(", ")
    }
  }
}
+3
source share
2 answers

In fact, it is recommended to use mkp.yield, for example,

src.p {
    mkp.yield 'Some element that has a '
    strong 'child element'
    mkp.yield ' which seems pretty basic.'
}

for creating

<p>Some element that has a <strong>child element</strong> which seems pretty basic.</p>
+8
source

Enable Method:

void text(n){
    builder.yield n
}

, (I) -, , . MarkupBuilder , , .

+2

Source: https://habr.com/ru/post/1696501/


All Articles