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.



146
147
148
# File 'lib/tree_haver/backends/commonmarker.rb', line 146

def initialize
  @language = nil
end

Instance Attribute Details

#languageObject

Returns the value of attribute language.



144
145
146
# File 'lib/tree_haver/backends/commonmarker.rb', line 144

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



154
155
156
157
158
159
160
161
# File 'lib/tree_haver/backends/commonmarker.rb', line 154

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



164
165
166
# File 'lib/tree_haver/backends/commonmarker.rb', line 164

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