简体   繁体   English

Ruby Yard 文档:如何添加“逐字”(生成类似<pre>标签)

[英]Ruby Yard documentation: how to add a “verbatim” (to generate something like a <pre> tag)

I want a piece of code, like a hash, to display with fixed typeface on the resulting html.我想要一段代码,如哈希,在生成的 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?如何指示 yard(使用版本0.9.15的默认值)以便yard doc file.rb将生成,对于哈希示例,相当于在 markdown 格式中添加 4 个反斜杠,或 4 个起始空格到 stackoverflow,或html 中的<pre>标记,导致生成的 html 中的逐字/固定字体格式?

Expected output:预期输出:

One example of valid hash to this function is:
{
    :name => "Engelbert",
    :id  => 1345
}

EDIT编辑

> gem install redcarpet
> yard doc --markup-provider redcarpet --markup markdown - file.rb

Should wrap the contents of file.rb within a <pre> tag, producing this page .应该将file.rb的内容file.rb在一个<pre>标签中,生成这个页面


Use @example使用@example

Show an example snippet of code for an object.显示对象的示例代码片段。 The first line is an optional title.第一行是一个可选的标题。

# @example One example of valid hash to this function is:
#   {
#       :name => "Engelbert",
#       :id  => 1345
#   }
def f hash_param
  # ...
end

Maybe I don't get your question:也许我没有得到你的问题:

the equivalent of adding 4 backslashes to the markdown format, or 4 starting empty spaces to stackoverflow相当于在 markdown 格式中添加 4 个反斜杠,或者在 stackoverflow 中添加 4 个起始空格

If I use the 4 starting empty spaces in my code like this:如果我在代码中使用 4 个起始空格,如下所示:

=begin

One example of valid hash to this function is:
    {
        :name => "Engelbert",
        :id  => 1345
    }
=end
def f hash_param
  # ...
end

then I get然后我得到

在此处输入图片说明

But maybe you can also use @option :但也许你也可以使用@option

@param hash_param
@option hash_param [String] :name The name of...
@option hash_param [Integer] :id The id of...

and you get:你会得到:

在此处输入图片说明

Disclaimer: I used yard 0.9.26 for my examples.免责声明:我在示例中使用了 yard 0.9.26。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM