ruby-on-railsrubydocumentationyard

How to output HTML element names in Yard documentation


I'd like to include some HTML element names, like <label>, in my ruby class documentation generated by Yard. But it is not working. For example, the sentence

# Returns a <label> field...

Becomes, after processing by Yard

Return a field...

The <label> element is actually passing verbatim through Yard making it to the browser as raw HTML.

I tried using &lt;label&gt; instead, and that got escaped so I ended up with &lt;label&gt; in the resulting documentation.

Thanks!


Solution

  • Yard uses normal RDoc markup by default:

    By default, YARD is compatible with the same RDoc syntax most Ruby developers are already familiar with.

    And RDoc has this to say:

    Putting a backslash before inline markup stops it being interpreted, which is how I created the table above:

    _italic_::     \_word_ or \<em>text</em>
    *bold*::       \*word* or \<b>text</b>
    +typewriter+:: \+word+ or \<tt>text</tt>
    

    That suggests that this:

    # Returns a \<label> field...
    

    should work but that did nothing useful for me, just more of the same "pass it through to the HTML" nonsense. However, wrapping the <label> in RDoc's typewriter markup did produce something useful so try this:

    # Returns a +<label>+ field...