Class: GithubToCanvasQuiz::MarkdownConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/github_to_canvas_quiz/markdown_converter.rb

Overview

Convert a string of Markdown to HTML using Redcarpet and Rouge.

Useage:

MarkdownConverter.new("# Hello\n\nWorld\n").to_html
# => "<h1>Hello</h1>\n\n<p>World</p>\n"

Constant Summary collapse

OPTIONS =
{
  tables: true,
  autolink: true,
  fenced_code_blocks: true,
  disable_indented_code_blocks: true,
  no_intra_emphasis: true
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markdown, options = {}) ⇒ MarkdownConverter

Returns a new instance of MarkdownConverter.

Parameters:

  • markdown (String)

    The markdown to be converted

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

    Overrides the defaults for the [Redcarpet](github.com/vmg/redcarpet) gem



28
29
30
31
# File 'lib/github_to_canvas_quiz/markdown_converter.rb', line 28

def initialize(markdown, options = {})
  @options = OPTIONS.merge(options)
  @markdown = markdown
end

Instance Attribute Details

#markdownObject (readonly)

Returns the value of attribute markdown.



16
17
18
# File 'lib/github_to_canvas_quiz/markdown_converter.rb', line 16

def markdown
  @markdown
end

#optionsObject (readonly)

Returns the value of attribute options.



16
17
18
# File 'lib/github_to_canvas_quiz/markdown_converter.rb', line 16

def options
  @options
end

Instance Method Details

#to_htmlString

Returns the markdown converted to HTML.

Returns:

  • (String)

    the markdown converted to HTML



34
35
36
# File 'lib/github_to_canvas_quiz/markdown_converter.rb', line 34

def to_html
  Redcarpet::Markdown.new(renderer, options).render(markdown)
end