Class: MarkupParser::Markdown

Inherits:
Default
  • Object
show all
Defined in:
lib/markup_parser/markdown.rb

Constant Summary collapse

OPTIONS =

Selected Markdown Options

{
  autolink: true, #parse links even when they are not enclosed in `<>` characters. Autolinks for the http, https and ftp
             #protocols will be automatically detected. Email addresses are also handled, and http links without protocol, but
             #starting with `www.`
  no_intraemphasis: true, #will stop underscores within words from being treated as the start or end of emphasis blocks
                    #and will therefore stop Ruby method or variable names with underscores in them from triggering the emphasis
  lax_html_blocks: true,  #HTML blocks do not require to be surrounded by an empty line as in the Markdown standard.
  strikethrough: true, #parse strikethrough, PHP-Markdown style Two `~` characters mark the start of a strikethrough, e.g. `this is ~~good~~ bad`
  fenced_code_blocks: true, #renders fenced code (```) and (~~~)
  tables: true, #parse tables, PHP-Markdown style
}

Instance Attribute Summary

Attributes inherited from Default

#lexer_proc, #nokogiri_parser, #original_text

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Default

#initialize, #to_html

Constructor Details

This class inherits a constructor from MarkupParser::Default

Class Method Details

.html_parserObject

Only loads the Markdown parser once



17
18
19
# File 'lib/markup_parser/markdown.rb', line 17

def self.html_parser
  @@parser_with_code_blocks ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, OPTIONS)
end

.html_parser_with_code_lexerObject

Only loads the Markdown parser once



11
12
13
# File 'lib/markup_parser/markdown.rb', line 11

def self.html_parser_with_code_lexer
  @@html_parser_with_code_lexer ||= Redcarpet::Markdown.new(UvHtmlRender, OPTIONS)
end

Instance Method Details

#html_textObject

Returns the fully stylized HTML for this markdown text



39
40
41
# File 'lib/markup_parser/markdown.rb', line 39

def html_text
  @html_text ||= parser.render(@original_text)
end

#stylize_code_blocksObject

Sets the parser to include as code lexer



44
45
46
47
# File 'lib/markup_parser/markdown.rb', line 44

def stylize_code_blocks
  @parser = MarkupParser::Markdown.html_parser_with_code_lexer
  self
end