Module: Markdpwn::Dpwn

Defined in:
lib/markdpwn/dpwn.rb

Overview

markdpwn is a clone of gfm (Git-Flavored Markdown).

Class Method Summary collapse

Class Method Details

.accepts?(options) ⇒ Boolean

Checks if some file should be formatted using Markdpwn.

Parameters:

  • options (Hash)

    file properties considered in the decision process

Options Hash (options):

  • :mime_type (String)

    the MIME type of the code file; e-mail attachments and git blobs have MIME types

  • :file_name (String)

    the name of the file containing the piece of code; meaningful for files in version control repositories, e-mail attachments, and code fetched from links

Returns:

  • (Boolean)

    true if the given file is suitable for Markdpwn, false otherwise


36
37
38
39
40
# File 'lib/markdpwn/dpwn.rb', line 36

def self.accepts?(options)
  return unless file_name = options[:file_name]
  ext = File.extname file_name
  ['.markdown', '.md'].include? ext
end

.render(text, options = {}) ⇒ String

Marks up text using markdpwn.

The caller is responsible for making sure that the text can be rendered using markdpwn.

Parameters:

  • text (String)

    the text to be formatted using Markdpwn

  • options (Hash) (defaults to: {})

    rendering options (currently ignored)

Returns:

  • (String)

    a HTML fragment containing the formatted text


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/markdpwn/dpwn.rb', line 15

def self.render(text, options = {})
  renderer = Markdpwn::RedCarpetRenderer.new
  md = Redcarpet::Markdown.new renderer,
      autolink: true,
      no_intra_emphasis: true,
      tables: true,
      fenced_code_blocks: true,
      strikethrough: true,
      space_after_headers: true
  md.render text
end