Javadoc 是否有与 等效的内容?
不幸的是,HTML 中没有 CDATA。
这很遗憾,因为它非常适合添加包含 XML 的 javadoc
注释,因此您不必转义 javadoc
注释。和 >,例如:
/**<![CDATA[ This parses <complexType name=""> ]]>*/
但是,javadoc
可以识别 CDATA 部分,并将其转换为 HTML。例如:
This parses <complexType name="">
或者它可以使用一些比 CDATA 更简单的语法。由于 javadoc
是可扩展的,因此可能有人添加了此功能;或者也许javadoc
已经把它埋在里面的某个地方......有人知道吗?
Unfortunately, there is no CDATA in HTML.
This is a pity, because it would be perfect for adding javadoc
comments that include XML, so you don't have to escape the < and >, for example:
/**<![CDATA[ This parses <complexType name=""> ]]>*/
However, it would be possible for javadoc
to recognize the CDATA section, and convert it to HTML for you. For example:
This parses <complexType name="">
Or it could use some simpler syntax than CDATA. Because javadoc
is extensible, it's possible someone has added this functionality; or maybe javadoc
already has it buried somewhere inside... Does anybody know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 JavaDoc 的
@code
标记:/** 这会解析 {@code} */
You can use JavaDoc's
@code
tag:/** This parses {@code <complexType name="">} */
扩展 @Fabian 的答案,我同时使用
使用 Eclipse 3.6.1 进行测试。
Extending @Fabian's answer, I use both
<pre>
and{@code ...}
. Here an example with XML as source code:<pre>
allows you to write code on multiple lines and preserve its structure.Tested with Eclipse 3.6.1.
关闭并重新打开大括号周围的
{@code}
标记,以使 ${dollar_sign_variables} 在 Eclipse 中正确呈现,尽管 错误 206319 和 bug 206345 并且不诉诸完整的 HTML 转义:在 Eclipse Indigo SR2 (3.7.2) 中呈现为
Close and reopen the
{@code}
tag around the braces to get ${dollar_sign_variables} to render correctly in eclipse despite bug 206319 and bug 206345 and without resorting to full HTML escaping:which renders in Eclipse Indigo SR2 (3.7.2) as
我尝试了很多解决方案,但没有一个能够满足我的需求。使用 pre + @code(或 @literal)标签通常会起作用:
问题是,如果 html 中有 ${dollar_sign_variables} 该怎么办? (如果您的文档使用依赖 Maven 过滤的 xml 示例,则这种情况很常见)。假设你有 ${ITEM_INDEX_TO_LOGICAL},Eclipse 会像这样渲染它:
最终,我别无选择,只能坚持 html 转义方法(你可以使用 这个) 让它正确渲染:
这个:
渲染如下:
不幸的是,这会让你陷入一个你无法真正理解的境地除非您呈现 Javadoc,否则“示例 xml”将被记录。幸运的是 eclipse 可以即时为你做这件事......
I have tried quite a few solutions, none of which were very satisfactory for my needs. Doing the pre + @code (or @literal) tags will usually work:
The trouble is, what if you have ${dollar_sign_variables} in your html? (and this is frequent if your documentation uses xml examples which rely on maven filtering). Say you have ${ITEM_INDEX_TO_LOGICAL}, Eclipse will render it like this:
Ultimately, I had no choice but to stick to the html-escaping method (you can use this one) to get it to render propertly:
This:
Renders like this:
This will unfortunately put you into a position where you can't really understand the 'example xml' being documented unless you render the Javadoc. Fortunately eclipse can do this for you on the fly...