I want a piece of code, like a hash, to display with fixed typeface on the resulting html. Suppose this is the contents of my file:
=begin
One example of valid hash to this function is:
{
:name => "Engelbert",
:id => 1345
}
=end
def f hash_param
# ...
end
How to instruct yard (using the default of the version 0.9.15
) so a yard doc file.rb
will generate, for the hash example, the equivalent of adding 4 backslashes to the markdown format, or 4 starting empty spaces to stackoverflow, or the <pre>
tag in html, resulting in a verbatim/fixed typeface format in the resulting html?
Expected output:
One example of valid hash to this function is:
{
:name => "Engelbert",
:id => 1345
}
答案 0 :(得分:0)
> gem install redcarpet
> yard doc --markup-provider redcarpet --markup markdown - file.rb
应将file.rb
的内容包装在<pre>
标记中,并产生page。
使用@example
显示对象代码示例。第一行是可选标题。
# @example One example of valid hash to this function is:
# {
# :name => "Engelbert",
# :id => 1345
# }
def f hash_param
# ...
end
答案 1 :(得分:0)
也许我不明白你的问题:
<块引用>相当于在 markdown 格式中添加 4 个反斜杠,或者在 stackoverflow 中添加 4 个起始空格
如果我像这样在代码中使用 4 个起始空格:
=begin
One example of valid hash to this function is:
{
:name => "Engelbert",
:id => 1345
}
=end
def f hash_param
# ...
end
然后我得到
但也许你也可以使用 @option
:
@param hash_param
@option hash_param [String] :name The name of...
@option hash_param [Integer] :id The id of...
你会得到:
免责声明:我在示例中使用了 0.9.26 码。