### Home Classes Methods

### In Files

- lib/rdoc/markdown.rb

### Parent

Object

### Sections

- Extensions

### Namespace

- CLASS RDoc::Markdown::Literals
- CLASS RDoc::Markdown::MemoEntry
- CLASS RDoc::Markdown::ParseError
- CLASS RDoc::Markdown::RuleInfo

### Methods

- ::extension
- ::new
- ::parse
- #break_on_newline
- #css
- #definition_lists
- #emphasis
- #extension
- #extension?
- #github
- #html
- #link_to
- #list_item_from
- #note
- #note_for
- #notes
- #orig_initialize
- #paragraph
- #parse
- #peg_parse
- #reference
- #strong

### Files

- CONTRIBUTING.rdoc
- CVE-2013-0256.rdoc
- ExampleRDoc.rdoc
- LICENSE.rdoc
- Manifest.txt
- README.rdoc
- RI.rdoc
- Rakefile
- TODO.rdoc

### Class/Module Index

Quicksearch

- RDoc
- RDoc::Alias
- RDoc::AnonClass
- RDoc::AnyMethod
- RDoc::Attr
- RDoc::ClassModule
- RDoc::CodeObject
- RDoc::Comment
- RDoc::Constant
- RDoc::Context
- RDoc::Context::Section
- RDoc::CrossReference
- RDoc::ERBIO
- RDoc::ERBPartial
- RDoc::Encoding
- RDoc::Error
- RDoc::Extend
- RDoc::Gauntlet
- RDoc::Generator
- RDoc::Generator::Darkfish
- RDoc::Generator::JsonIndex
- RDoc::Generator::Markup
- RDoc::Generator::RI
- RDoc::GhostMethod
- RDoc::Include
- RDoc::Markdown
- RDoc::Markdown::Literals
- RDoc::Markup
- RDoc::Markup::AttrChanger
- RDoc::Markup::AttrSpan
- RDoc::Markup::AttributeManager
- RDoc::Markup::Attributes
- RDoc::Markup::BlankLine
- RDoc::Markup::BlockQuote
- RDoc::Markup::Document
- RDoc::Markup::Formatter
- RDoc::Markup::FormatterTestCase
- RDoc::Markup::HardBreak
- RDoc::Markup::Include
- RDoc::Markup::IndentedParagraph
- RDoc::Markup::List
- RDoc::Markup::ListItem
- RDoc::Markup::Paragraph
- RDoc::Markup::Parser
- RDoc::Markup::Parser::Error
- RDoc::Markup::Parser::ParseError
- RDoc::Markup::PreProcess
- RDoc::Markup::Raw
- RDoc::Markup::Rule
- RDoc::Markup::Special
- RDoc::Markup::TextFormatterTestCase
- RDoc::Markup::ToAnsi
- RDoc::Markup::ToBs
- RDoc::Markup::ToHtml
- RDoc::Markup::ToHtmlCrossref
- RDoc::Markup::ToHtmlSnippet
- RDoc::Markup::ToJoinedParagraph
- RDoc::Markup::ToLabel
- RDoc::Markup::ToMarkdown
- RDoc::Markup::ToRdoc
- RDoc::Markup::ToTableOfContents
- RDoc::Markup::ToTest
- RDoc::Markup::ToTtOnly
- RDoc::Markup::Verbatim
- RDoc::MetaMethod
- RDoc::MethodAttr
- RDoc::Mixin
- RDoc::NormalClass
- RDoc::NormalModule
- RDoc::Options
- RDoc::Parser
- RDoc::Parser::C
- RDoc::Parser::ChangeLog
- RDoc::Parser::Markdown
- RDoc::Parser::RD
- RDoc::Parser::Ruby
- RDoc::Parser::RubyTools
- RDoc::Parser::Simple
- RDoc::Parser::Text
- RDoc::RD
- RDoc::RD::BlockParser
- RDoc::RD::Inline
- RDoc::RD::InlineParser
- RDoc::RDoc
- RDoc::RI
- RDoc::RI::Driver
- RDoc::RI::Driver::Error
- RDoc::RI::Driver::NotFoundError
- RDoc::RI::Error
- RDoc::RI::Paths
- RDoc::Require
- RDoc::RubyLex
- RDoc::RubyLex::Error
- RDoc::RubyToken
- RDoc::RubygemsHook
- RDoc::Servlet
- RDoc::SingleClass
- RDoc::Stats
- RDoc::Stats::Normal
- RDoc::Stats::Quiet
- RDoc::Stats::Verbose
- RDoc::Store
- RDoc::Store::Error
- RDoc::Store::MissingFileError
- RDoc::Task
- RDoc::Task
- RDoc::TestCase
- RDoc::TokenStream
- RDoc::TomDoc
- RDoc::TopLevel
- Object

No matching classes.

# RDoc::Markdown

RDoc::Markdown as described by the [markdown syntax].

To choose Markdown as your only default format see RDoc::Options@Saved+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][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

### Github

The github extension enables a partial set of [Github Flavored Markdown] [GFM]. 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 text including an inline footnote ^[for short footnotes]

[^1]: With the footnote text down at the bottom

## 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

[dingus]: daringfireball.net/projects/markdown/dingus [GFM]: github.github.com/github-flavored-markdown/ [pegmarkdown]: github.com/jgm/peg-markdown [PHPE]: michelf.com/projects/php-markdown/extra/#def-list [syntax]: daringfireball.net/projects/markdown/syntax

### Public Class Methods

new(extensions = DEFAULT_EXTENSIONS, debug = false) click to toggle source

Creates a new markdown parser that enables the given `extensions`.

    # File lib/rdoc/markdown.rb, line 619
    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

Also aliased as: orig_initialize
parse(markdown) click to toggle source

Parses the `markdown` document into an RDoc::Document using the default extensions.

    # File lib/rdoc/markdown.rb, line 607
    def self.parse markdown
      parser = new

      parser.parse markdown
    end

### Public Instance Methods

emphasis(text) click to toggle source

Wraps `text` in emphasis for rdoc inline formatting

    # File lib/rdoc/markdown.rb, line 634
    def emphasis text
      if text =~ /\A[a-z\d.\/]+\z/ then
        "_#{text}_"
      else
        "<em>#{text}</em>"
      end
    end

link_to(content, label = content, text = nil) click to toggle source

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 lib/rdoc/markdown.rb, line 688
    def link_to content, label = content, text = nil
      raise '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) click to toggle source

Creates an RDoc::Markup::ListItem by parsing the `unparsed` content from the first parsing pass.

    # File lib/rdoc/markdown.rb, line 705
    def list_item_from unparsed
      parsed = inner_parse unparsed.join
      RDoc::Markup::ListItem.new nil, *parsed
    end

note(label) click to toggle source

Stores `label` as a note and fills in previously unknown note references.

    # File lib/rdoc/markdown.rb, line 713
    def note label
      #foottext = "rdoc-label:foottext-#{label}:footmark-#{label}"

      #ref.replace foottext if ref = @unlinked_notes.delete(label)

      @notes[label] = foottext

      #"{^1}[rdoc-label:footmark-#{label}:foottext-#{label}] "
    end

note_for(ref) click to toggle source

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.

    # File lib/rdoc/markdown.rb, line 727
    def note_for ref
      @note_order << ref

      label = @note_order.length

      "{*#{label}}[rdoc-label:foottext-#{label}:footmark-#{label}]"
    end

orig_initialize(extensions = DEFAULT_EXTENSIONS, debug = false) click to toggle source

TODO remove when kpeg 0.10 is released

Alias for: new
paragraph(parts) click to toggle source

Creates an RDoc::Markup::Paragraph from `parts` and including extension-specific behavior

    # File lib/rdoc/markdown.rb, line 744
    def paragraph parts
      parts = parts.map do |part|
        if "\n" == part then
          RDoc::Markup::HardBreak.new
        else
          part
        end
      end if break_on_newline?

      RDoc::Markup::Paragraph.new(*parts)
    end

parse(markdown) click to toggle source

Parses `markdown` into an RDoc::Document

    # File lib/rdoc/markdown.rb, line 759
    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]

          link = "{^#{label}}[rdoc-label:footmark-#{label}:foottext-#{label}] "
          note.parts.unshift link

          doc << note
        end
      end

      doc.accept @formatter

      doc
    end

Also aliased as: peg_parse
peg_parse(markdown) click to toggle source

The internal kpeg parse method

Alias for: parse
reference(label, link) click to toggle source

Stores `label` as a reference to `link` and fills in previously unknown link references.

    # File lib/rdoc/markdown.rb, line 806
    def reference label, link
      if ref = @unlinked_references.delete(label) then
        ref.replace link
      end

      @references[label] = link
    end

strong(text) click to toggle source

Wraps `text` in strong markup for rdoc inline formatting

    # File lib/rdoc/markdown.rb, line 817
    def strong text
      if text =~ /\A[a-z\d.\/-]+\z/ then
        "*#{text}*"
      else
        "<b>#{text}</b>"
      end
    end

## Extensions ↑ top

### Public Class Methods

extension(name) click to toggle source

Creates extension methods for the `name` extension to enable and disable the extension and to query if they are active.

    # File lib/rdoc/markdown.rb, line 559
    def self.extension name
      EXTENSIONS << name

      define_method "#{name}?" do
        extension? name
      end

      define_method "#{name}=" do |enable|
        extension name, enable
      end
    end

### Public Instance Methods

break_on_newline click to toggle source

Converts all newlines into hard breaks

    # File lib/rdoc/markdown.rb, line 574
    extension :break_on_newline

css click to toggle source

Allow style blocks

    # File lib/rdoc/markdown.rb, line 579
    extension :css

definition_lists click to toggle source

Allow PHP Markdown Extras style definition lists

    # File lib/rdoc/markdown.rb, line 584
    extension :definition_lists

extension(name, enable) click to toggle source

Enables or disables the extension with `name`

    # File lib/rdoc/markdown.rb, line 656
    def extension name, enable
      if enable then
        @extensions |= [name]
      else
        @extensions -= [name]
      end
    end

extension?(name) click to toggle source

Is the extension `name` enabled?

    # File lib/rdoc/markdown.rb, line 647
    def extension? name
      @extensions.include? name
    end

github click to toggle source

Allow Github Flavored Markdown

    # File lib/rdoc/markdown.rb, line 589
    extension :github

html click to toggle source

Allow HTML

    # File lib/rdoc/markdown.rb, line 594
    extension :html

notes click to toggle source

Enables the notes extension

    # File lib/rdoc/markdown.rb, line 599
    extension :notes

[Validate]

Generated with the Darkfish Rdoc Generator 2.