This document is the comprehensive reference for Markdown support in RDoc. It covers all syntax, extensions, and formatting options available.
For Ruby-specific features that require actual code (like cross-reference targets and directives that only work in Ruby comments), see RDoc::Example.
- Examples show Markdown syntax.
- Rendered output is shown in blockquotes where helpful.
Markdown documents consist of various block types:
- Paragraphs: ordinary text blocks.
- Headings: section titles.
- Code Blocks: verbatim text with syntax highlighting.
- Blockquotes: quoted passages.
- Lists: bullet, numbered, and definition lists.
- Tables: tabular data.
- Horizontal Rules: visual separators.
A paragraph is one or more consecutive lines of text, separated from other blocks by blank lines.
Example:
This is the first paragraph. It can span
multiple lines.
This is the second paragraph.Single newlines within a paragraph become spaces in the output.
Use # characters at the start of a line. Levels 1-6 are supported:
# Heading Level 1
## Heading Level 2
### Heading Level 3
#### Heading Level 4
##### Heading Level 5
###### Heading Level 6Optional closing # characters are allowed:
## Heading ##Underline text with = for level 1 or - for level 2:
Heading Level 1
===============
Heading Level 2
---------------Indent code by 4 spaces or 1 tab:
This is a paragraph.
def hello
puts "world"
end
This is another paragraph.Use triple backticks with an optional language identifier:
```ruby
def hello
puts "world"
end
```
Supported languages for syntax highlighting: ruby (and rb alias) with server-side
highlighting, and c, bash/sh/shell/console with client-side JavaScript highlighting.
Other info strings are accepted and added as a CSS class but receive no highlighting.
Prefix lines with >:
> This is a blockquote.
> It can span multiple lines.
>
> Multiple paragraphs are supported.Blockquotes can contain other elements:
> ## Heading inside blockquote
>
> - List item 1
> - List item 2
>
> Code inside blockquote:
>
> def example
> :ok
> endNested blockquotes:
> Outer quote
>
> > Nested quoteUse *, +, or - followed by a space:
* Item 1
* Item 2
* Item 3Or:
- Item 1
- Item 2
- Item 3Use digits followed by . and a space:
1. First item
2. Second item
3. Third itemThe actual numbers don't matter; they're renumbered in output:
1. First
1. Second
1. ThirdIndent with 4 spaces to nest:
* Item 1
* Nested item A
* Nested item B
* Item 2
1. Numbered nested
2. Also numberedUse a term on one line, then : followed by the definition:
term
: Definition of the term.
cat
: A small furry mammal.
ant
: A little insect.Multiple definitions for one term:
apple
: A fruit
: A technology companyCreate tables with pipes and dashes:
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |Use colons to specify alignment:
| Left | Center | Right |
|:---------|:--------:|---------:|
| Left | Center | Right |
| aligned | aligned | aligned |:---or---for left alignment (default):---:for center alignment---:for right alignment
Tables support inline formatting in cells:
| Feature | Syntax |
|-------------|-----------------|
| **Bold** | `**text**` |
| *Italic* | `*text*` |
| `Code` | `` `text` `` |Use three or more -, *, or _ on a line by themselves:
---
* * *
___Inline text can be formatted with various markup:
- Italic: emphasized text.
- Bold: strong emphasis.
- Bold and Italic: combined emphasis.
- Strikethrough: deleted text.
- Inline Code: monospace text.
Use single asterisks or underscores:
This is *italic* text.
This is _also italic_ text.This is italic text. This is also italic text.
Note: Underscores within words are not interpreted as emphasis:
foo_bar_baz remains plain textUse double asterisks or underscores:
This is **bold** text.
This is __also bold__ text.This is bold text. This is also bold text.
Use triple asterisks or underscores:
This is ***bold and italic*** text.
This is ___also bold and italic___ text.This is bold and italic text. This is also bold and italic text.
Use double tildes:
This is ~~strikethrough~~ text.This is
strikethroughtext.
Use backticks:
Use the `puts` method.Use the
putsmethod.
For code containing backticks, use multiple backticks:
Use `` `backticks` `` in code.Use
`backticks`in code.
[Link text](https://example.com)With optional title (title is parsed but not used in RDoc output):
[Link text](https://example.com "Title")Define a reference, then use it:
[Link text][ref]
[ref]: https://example.comImplicit reference (link text matches reference):
[Example][]
[Example]: https://example.comURLs and emails in angle brackets become links:
<https://example.com>
<user@example.com>Link to RDoc-documented classes, modules, and methods:
[RDoc module](rdoc-ref:RDoc)
[Options class](rdoc-ref:RDoc::Options)
[document method](rdoc-ref:RDoc::RDoc#document)See rdoc.rdoc for complete cross-reference documentation.
Basic image syntax:
Image as a link:
[](https://example.com)RDoc supports GitHub-style anchor links. You can link to any heading using its anchor, which is the heading text converted to lowercase with spaces replaced by hyphens and special characters removed.
For example:
When multiple headings produce the same anchor, RDoc appends -1, -2, etc.
to subsequent duplicates, matching GitHub's behavior.
Add a footnote reference in text, then define it:
Here is some text[^1] with a footnote[^note].
[^1]: This is the first footnote.
[^note]: This is another footnote.Create footnotes inline:
Here is text ^[with an inline footnote].Footnotes are collected and rendered at the bottom of the section, separated by a horizontal rule.
Raw HTML blocks are preserved:
<div class="note">
<p>This is HTML content.</p>
</div>Supported block-level tags include: <address>, <blockquote>, <div>,
<fieldset>, <form>, <h1>-<h6>, <ol>, <p>, <pre>, <table>, <ul>.
Inline HTML is also preserved:
This has <b>bold</b> and <em>emphasized</em> HTML.Use backslash to escape special characters:
\*not italic\*
\`not code\`
\[not a link\]
\# not a headingEscapable characters: ` \ : | * _ { } [ ] ( ) # + . ! > < -
Named, decimal, and hexadecimal entities are supported:
© — π
A AEnd a line with two or more spaces for a hard line break:
Line one
Line twoRDoc directives work in Markdown files within Ruby comments.
Use the :markup: markdown directive to specify Markdown format.
# :markup: markdown
# This class uses **Markdown** for documentation.
#
# ## Features
#
# - Bold with `**text**`
# - Italic with `*text*`
class MyClass
endCommon directives (same as RDoc markup):
:nodoc:- Suppress documentation:doc:- Force documentation:stopdoc:/:startdoc:- Start/stop documentation parsing:call-seq:- Custom calling sequence:section:- Create documentation sections
See rdoc.rdoc for complete directive documentation.
| Feature | RDoc Markup | Markdown |
|---|---|---|
| Headings | = Heading |
# Heading |
| Bold | *word* |
**word** |
| Italic | _word_ |
*word* |
| Monospace | +word+ or `word` |
`word` |
| Links | {text}[url] |
[text](url) |
| Code blocks | Indent beyond margin | Indent 4 spaces or fence |
| Block quotes | >>> |
> |
| Tables | Not supported | Supported |
| Strikethrough | <del>text</del> |
~~text~~ |
| Footnotes | Not supported | [^1] |
-
Link titles are parsed but not used - The title in
[text](url "title")is ignored. -
Underscores in words -
foo_baris never italicized; emphasis requires whitespace boundaries. -
Footnotes are collapsed - Multiple paragraphs in a footnote become a single paragraph.
-
Syntax highlighting - Only
ruby/rb(server-side) andc,bash/sh/shell/console(client-side) receive syntax highlighting. Other info strings are accepted but not highlighted. -
Fenced code blocks - Only triple backticks are supported. Tilde fences (
~~~) are not supported as they conflict with strikethrough syntax. Four or more backticks for nesting are also not supported. -
Auto-linking - RDoc automatically links class and method names in output, even without explicit link syntax.
This section compares RDoc's Markdown implementation with the GitHub Flavored Markdown Spec (Version 0.29-gfm, 2019-04-06).
| Feature | GFM | RDoc | Notes |
|---|---|---|---|
ATX Headings (#) |
✅ | ✅ | Both support levels 1-6, optional closing # |
| Setext Headings | ✅ | ✅ | = for H1, - for H2 |
| Paragraphs | ✅ | ✅ | Full match |
| Indented Code Blocks | ✅ | ✅ | 4 spaces or 1 tab |
| Fenced Code (backticks) | ✅ 3+ | RDoc doesn't support 4+ backticks for nesting | |
| Fenced Code (tildes) | ✅ ~~~ |
❌ | Conflicts with strikethrough syntax |
| Info strings (language) | ✅ any | ruby/rb, c, and bash/sh/shell/console highlighted; others accepted as CSS class |
|
| Blockquotes | ✅ | ✅ | Full match, nested supported |
| Lazy Continuation | ✅ | Continuation text is included in blockquote but line break is lost (becomes a space) | |
| Bullet Lists | ✅ | ✅ | *, +, - supported |
| Ordered Lists | ✅ . ) |
. only |
RDoc doesn't support ) delimiter; numbers are always renumbered from 1 |
| Nested Lists | ✅ | ✅ | 4-space indentation |
| Tables | ✅ | ✅ | Full alignment support |
| Thematic Breaks | ✅ | ✅ | ---, ***, ___ |
| HTML Blocks | ✅ 7 types | See below |
GFM defines 7 types of HTML blocks:
| Type | Description | GFM | RDoc | Notes |
|---|---|---|---|---|
| 1 | <script>, <pre> |
✅ | ✅ | |
| 1 | <style> |
✅ | ❌ | Available via css extension (disabled by default) |
| 2 | HTML comments <!-- --> |
✅ | ✅ | |
| 3 | Processing instructions <? ?> |
✅ | ❌ | |
| 4 | Declarations <!DOCTYPE> |
✅ | ❌ | |
| 5 | CDATA <![CDATA[ ]]> |
✅ | ❌ | |
| 6 | Block-level tags | ✅ | ||
| 7 | Any complete open/close tag | ✅ | ❌ |
RDoc uses a whitelist of block-level tags defined in
lib/rdoc/markdown.kpeg
(see HtmlBlockInTags). HTML5 semantic elements like <article>, <section>,
<nav>, <header>, <footer> are not supported.
| Feature | GFM | RDoc | Notes |
|---|---|---|---|
Emphasis *text* _text_ |
✅ | Intraword emphasis not supported (see Notes) | |
Strong **text** __text__ |
✅ | ✅ | Full match |
Combined ***text*** |
✅ | ✅ | Full match |
| Code spans | ✅ | ✅ | Multiple backticks supported |
| Inline links | ✅ | ✅ | Full match |
| Reference links | ✅ | ✅ | Full match |
| Link titles | ✅ | Parsed but not rendered | |
| Images | ✅ | ✅ | Full match |
Autolinks <url> |
✅ | ✅ | Full match |
| Hard line breaks | ✅ | 2+ trailing spaces only; backslash \ at EOL not supported |
|
| Backslash escapes | ✅ | Subset of GFM's escapable characters (e.g., ~ not escapable) |
|
| HTML entities | ✅ | ✅ | Named, decimal, hex |
| Inline HTML | ✅ | <b> converted to <strong>, <i> to <em>; <strong> itself is escaped |
| Feature | GFM | RDoc | Notes |
|---|---|---|---|
Strikethrough ~~text~~ |
✅ | ✅ | Full match |
Task Lists [ ] [x] |
✅ | ❌ | Not supported |
| Extended Autolinks | ✅ | See below | |
| Disallowed Raw HTML | ✅ | ❌ | No security filtering |
GFM automatically converts certain text patterns into links without requiring
angle brackets (<>). RDoc also auto-links URLs and www. prefixes through
its cross-reference system, but the behavior differs from GFM.
GFM recognizes these patterns:
www.example.com— text starting withwww.followed by a valid domainhttps://example.com— URLs starting withhttp://orhttps://user@example.com— valid email addresses
RDoc auto-links www. prefixes and http:///https:// URLs similarly to GFM.
However, bare email addresses like user@example.com are not auto-linked;
use <user@example.com> instead.