Class: MinimalMarkdown::Parser
- Inherits:
-
Object
- Object
- MinimalMarkdown::Parser
- Defined in:
- lib/minimal_markdown/parser.rb
Constant Summary collapse
- DEFAULT_PARSERS =
[ Parsers::UnorderedList, Parsers::Bold, Parsers::Italic, ]
- STYLES =
[:markdown, :slack]
Instance Attribute Summary collapse
-
#parsers ⇒ Object
readonly
Returns the value of attribute parsers.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text, style: :markdown, parsers: DEFAULT_PARSERS) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(text, style: :markdown, parsers: DEFAULT_PARSERS) ⇒ Parser
Returns a new instance of Parser.
13 14 15 16 17 18 19 |
# File 'lib/minimal_markdown/parser.rb', line 13 def initialize(text, style: :markdown, parsers: DEFAULT_PARSERS) raise ArgumentError, 'invalid style' unless STYLES.include?(style) @text = text @style = style @parsers = parsers end |
Instance Attribute Details
#parsers ⇒ Object (readonly)
Returns the value of attribute parsers.
11 12 13 |
# File 'lib/minimal_markdown/parser.rb', line 11 def parsers @parsers end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
11 12 13 |
# File 'lib/minimal_markdown/parser.rb', line 11 def text @text end |
Instance Method Details
#parse ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/minimal_markdown/parser.rb', line 21 def parse prepared_text = text.strip.gsub("\r", "") preline_parsers, postline_parsers = parsers.map { |parser| parser.new(@style) }.partition(&:multiline?) preline_tree = run_parsers(preline_parsers, [prepared_text]) postline_tree = convert_to_lines(preline_tree) run_parsers(postline_parsers, postline_tree) end |