Class: TreeHaver::Backends::Commonmarker::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_haver/backends/commonmarker.rb

Overview

Commonmarker parser wrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



122
123
124
# File 'lib/tree_haver/backends/commonmarker.rb', line 122

def initialize
  @language = nil
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



120
121
122
# File 'lib/tree_haver/backends/commonmarker.rb', line 120

def language
  @language
end

Instance Method Details

#parse(source) ⇒ Tree

Parse Markdown source code

Parameters:

  • source (String)

    Markdown source to parse

Returns:

  • (Tree)

    Parsed tree



130
131
132
133
134
135
136
137
# File 'lib/tree_haver/backends/commonmarker.rb', line 130

def parse(source)
  raise "Language not set" unless @language
  Commonmarker.available? or raise "Commonmarker not available"

  options = @language.options || {}
  doc = ::Commonmarker.parse(source, options: options)
  Tree.new(doc, source)
end

#parse_string(_old_tree, source) ⇒ Object

Alias for compatibility



140
141
142
# File 'lib/tree_haver/backends/commonmarker.rb', line 140

def parse_string(_old_tree, source)
  parse(source)
end