Class: TreeHaver::Backends::Commonmarker::Language

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

Overview

Commonmarker language wrapper

Commonmarker only parses Markdown. This class exists for API compatibility.

Examples:

language = TreeHaver::Backends::Commonmarker::Language.markdown
parser.language = language

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = :markdown, options: {}) ⇒ Language

Create a new Commonmarker language instance

Parameters:

  • name (Symbol) (defaults to: :markdown)

    Language name (should be :markdown)

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

    Commonmarker parse options



91
92
93
94
95
# File 'lib/tree_haver/backends/commonmarker.rb', line 91

def initialize(name = :markdown, options: {})
  @name = name.to_sym
  @backend = :commonmarker
  @options = options
end

Instance Attribute Details

#backendSymbol (readonly)

The backend this language is for

Returns:

  • (Symbol)


81
82
83
# File 'lib/tree_haver/backends/commonmarker.rb', line 81

def backend
  @backend
end

#nameSymbol (readonly)

The language name (always :markdown for Commonmarker)

Returns:

  • (Symbol)


77
78
79
# File 'lib/tree_haver/backends/commonmarker.rb', line 77

def name
  @name
end

#optionsHash (readonly)

Commonmarker parse options

Returns:

  • (Hash)


85
86
87
# File 'lib/tree_haver/backends/commonmarker.rb', line 85

def options
  @options
end

Class Method Details

.markdown(options: {}) ⇒ Language

Create a Markdown language instance

Parameters:

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

    Commonmarker parse options

Returns:



102
103
104
# File 'lib/tree_haver/backends/commonmarker.rb', line 102

def markdown(options: {})
  new(:markdown, options: options)
end

Instance Method Details

#<=>(other) ⇒ Object

Comparison for sorting/equality



108
109
110
111
# File 'lib/tree_haver/backends/commonmarker.rb', line 108

def <=>(other)
  return unless other.is_a?(Language)
  name <=> other.name
end

#inspectObject



113
114
115
# File 'lib/tree_haver/backends/commonmarker.rb', line 113

def inspect
  "#<TreeHaver::Backends::Commonmarker::Language name=#{name} options=#{options}>"
end