简体   繁体   中英

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. 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
}

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 .


Use @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

If I use the 4 starting empty spaces in my code like this:

=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 :

@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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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