gpt4 book ai didi

html - 在 Groovy 1.7 中使用包含混合内容的 HTML 构建器的正确语法是什么?

转载 作者:太空狗 更新时间:2023-10-29 15:33:46 25 4
gpt4 key购买 nike

关于Groovy example page有一个如何使用混合内容的 Groovy HTML 构建器的示例:

p [
"This is some",
b"mixed",
"text. For more see the",
ahref:'http://groovy.codehaus.org' ["Groovy"],
"project"
]

但这对我不起作用,我收到如下错误消息:

expecting ']', found 'mixed' @ line 33, column 23. b"mixed", ^ 1 error 

Groovy 示例页面声明:

[Note: the syntax in some of these examples is slightly out-dated. See chapter 8 of GINA in the mean-time until these examples are updated.]

因此,我怀疑 HTML 生成器的语法已经更改,但是我没有这本书,所以我无法检查,而且我似乎找不到任何与此在线工作相关的示例。有谁知道 Groovy 1.7 中的语法应该是怎样的,并且可以正常工作吗?

最佳答案

我发现该示例中的很多内容都已过时。混合 href 的语法和段落周围的 [] 对我不起作用。

对于混合内容,您需要使用特殊关键字“mkp.yield”。如果您不想转义,还有一个“mkp.yieldUnescaped”。您还可以使用 mkp 执行一些其他功能。

此示例确实有效并使用混合内容显示:

def builder = new groovy.xml.MarkupBuilder()
builder.html {
head {
title"XML encoding with Groovy"
}
body {
h1"XML encoding with Groovy"
p"this format can be used as an alternative markup to XML"

a(href:'http://groovy.codehaus.org', "Groovy")

p {
mkp.yield "This is some"
b"mixed"
mkp.yield " text. For more see the"
a(href:'http://groovy.codehaus.org', "Groovy")
mkp.yield "project"
}
p "some text"
}
}​

输出:

<html>
<head>
<title>XML encoding with Groovy</title>
</head>
<body>
<h1>XML encoding with Groovy</h1>
<p>this format can be used as an alternative markup to XML</p>
<a href='http://groovy.codehaus.org'>Groovy</a>
<p>This is some
<b>mixed</b> text. For more see the
<a href='http://groovy.codehaus.org'>Groovy</a>project
</p>
<p>some text</p>
</body>
</html>

关于html - 在 Groovy 1.7 中使用包含混合内容的 HTML 构建器的正确语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2482929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com