RDoc::Markdown
as described by the markdown syntax.
To choose Markdown
as your only default format see Saved Options at RDoc::Options
for instructions on setting up a .doc_options
file to store your project default.
Usage
Here is a brief example of using this parse to read a markdown file by hand.
data = File.read("README.md")
formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
html = RDoc::Markdown.parse(data).accept(formatter)
# do something with html
Extensions
The following markdown extensions are supported by the parser, but not all are used in RDoc
output by default.
RDoc
The RDoc
Markdown
parser has the following built-in behaviors that cannot be disabled.
Underscores embedded in words are never interpreted as emphasis. (While the markdown dingus emphasizes in-word underscores, neither the Markdown
syntax nor MarkdownTest mention this behavior.)
For HTML output, RDoc
always auto-links bare URLs.
Break on Newline
The break_on_newline
extension converts all newlines into hard line breaks as in Github Flavored Markdown. This extension is disabled by default.
CSS
The css
extension enables CSS blocks to be included in the output, but they are not used for any built-in RDoc
output format. This extension is disabled by default.
Example:
<style type="text/css">
h1 { font-size: 3em }
</style>
Definition Lists
The definition_lists
extension allows definition lists using the PHP Markdown Extra syntax, but only one label and definition are supported at this time. This extension is enabled by default.
Example:
cat
: A small furry mammal
that seems to sleep a lot
ant
: A little insect that is known
to enjoy picnics
Produces:
- cat
-
A small furry mammal that seems to sleep a lot
- ant
-
A little insect that is known to enjoy picnics
Strike
Example:
This is ~~striked~~.
Produces:
This is ~striked~.
Github
The github
extension enables a partial set of Github Flavored Markdown. This extension is enabled by default.
Supported github extensions include:
Fenced code blocks
Use ```
around a block of code instead of indenting it four spaces.
Syntax highlighting
Use ``` ruby
as the start of a code fence to add syntax highlighting. (Currently only ruby
syntax is supported).
HTML
Enables raw HTML to be included in the output. This extension is enabled by default.
Example:
<table>
...
</table>
Notes
The notes
extension enables footnote support. This extension is enabled by default.
Example:
Here is some text[^1] including an inline footnote ^[for short footnotes]
...
[^1]: With the footnote text down at the bottom
Produces:
Here is some text1 including an inline footnote 2
Limitations
-
Link titles are not used
-
Footnotes are collapsed into a single paragraph
Author
This markdown parser is a port to kpeg from peg-markdown by John MacFarlane.
It is used under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The port to kpeg was performed by Eric Hodel and Evan Phoenix
1 With the footnote text down at the bottom
2 for short footnotes
- CLASS RDoc::Markdown::MemoEntry
- CLASS RDoc::Markdown::ParseError
- CLASS RDoc::Markdown::RuleInfo
- B
- C
- D
- E
- G
- H
- L
- N
- O
- P
- R
- S
Constants
DEFAULT_EXTENSIONS | = | [ :definition_lists, :github, :html, :notes, :strike, ] |
Extensions enabled by default |
||
EXTENSIONS | = | [] |
Supported extensions |
Class Public methods
new(extensions = DEFAULT_EXTENSIONS, debug = false) Link
Creates a new markdown parser that enables the given extensions
.
# File ruby/lib/rdoc/markdown.rb, line 668 def initialize extensions = DEFAULT_EXTENSIONS, debug = false @debug = debug @formatter = RDoc::Markup::ToJoinedParagraph.new @extensions = extensions @references = nil @unlinked_references = nil @footnotes = nil @note_order = nil end
parse(markdown) Link
Parses the markdown
document into an RDoc::Document using the default extensions.
Instance Public methods
emphasis(text) Link
Wraps text
in emphasis for rdoc inline formatting
link_to(content, label = content, text = nil) Link
Finds a link reference for label
and creates a new link to it with content
as the link text. If label
was not encountered in the reference-gathering parser pass the label and content are reconstructed with the linking text
(usually whitespace).
# File ruby/lib/rdoc/markdown.rb, line 737 def link_to content, label = content, text = nil raise ParseError, 'enable notes extension' if content.start_with? '^' and label.equal? content if ref = @references[label] then "{#{content}}[#{ref}]" elsif label.equal? content then "[#{content}]#{text}" else "[#{content}]#{text}[#{label}]" end end
list_item_from(unparsed) Link
Creates an RDoc::Markup::ListItem by parsing the unparsed
content from the first parsing pass.
note(label) Link
Stores label
as a note and fills in previously unknown note references.
note_for(ref) Link
Creates a new link for the footnote reference
and adds the reference to the note order list for proper display at the end of the document.
orig_initialize(extensions = DEFAULT_EXTENSIONS, debug = false) Link
TODO remove when kpeg 0.10 is released
paragraph(parts) Link
Creates an RDoc::Markup::Paragraph from parts
and including extension-specific behavior
parse(markdown) Link
Parses markdown
into an RDoc::Document
# File ruby/lib/rdoc/markdown.rb, line 808 def parse markdown @references = {} @unlinked_references = {} markdown += "\n\n" setup_parser markdown, @debug peg_parse 'References' if notes? then @footnotes = {} setup_parser markdown, @debug peg_parse 'Notes' # using note_order on the first pass would be a bug @note_order = [] end setup_parser markdown, @debug peg_parse doc = result if notes? and not @footnotes.empty? then doc << RDoc::Markup::Rule.new(1) @note_order.each_with_index do |ref, index| label = index + 1 note = @footnotes[ref] or raise ParseError, "footnote [^#{ref}] not found" link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] " note.parts.unshift link doc << note end end doc.accept @formatter doc end
reference(label, link) Link
Stores label
as a reference to link
and fills in previously unknown link references.
strong(text) Link
Wraps text
in strong markup for rdoc inline formatting
Class Public methods
extension(name) Link
Creates extension methods for the name
extension to enable and disable the extension and to query if they are active.
Instance Public methods
break_on_newline Link
Converts all newlines into hard breaks
css Link
Allow style blocks
extension(name, enable) Link
Enables or disables the extension with name
extension?(name) Link
Is the extension name
enabled?
html Link
Allow HTML
notes Link
Enables the notes extension