Module: TreeHaver::Backends::Commonmarker

Defined in:
lib/tree_haver/backends/commonmarker.rb

Overview

Note:

This backend only parses Markdown source code

Commonmarker backend using the Commonmarker gem (comrak Rust parser)

This backend wraps Commonmarker, a Ruby gem that provides bindings to comrak, a fast CommonMark-compliant Markdown parser written in Rust.

Examples:

Basic usage

parser = TreeHaver::Parser.new
parser.language = TreeHaver::Backends::Commonmarker::Language.markdown
tree = parser.parse(markdown_source)
root = tree.root_node
puts root.type  # => "document"

See Also:

Defined Under Namespace

Classes: Language, Node, Parser, Point, Tree

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tree_haver/backends/commonmarker.rb', line 27

def available?
  return @loaded if @load_attempted
  @load_attempted = true
  begin
    require "commonmarker"
    @loaded = true
  rescue LoadError
    @loaded = false
  end
  @loaded
end

.capabilitiesHash{Symbol => Object}

Get capabilities supported by this backend

Returns:

  • (Hash{Symbol => Object})

    capability map



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tree_haver/backends/commonmarker.rb', line 51

def capabilities
  return {} unless available?
  {
    backend: :commonmarker,
    query: false,
    bytes_field: false,       # Commonmarker uses line/column
    incremental: false,
    pure_ruby: false,         # Uses Rust via FFI
    markdown_only: true,
    error_tolerant: true,     # Markdown is forgiving
  }
end

.reset!void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Reset the load state (primarily for testing)



43
44
45
46
# File 'lib/tree_haver/backends/commonmarker.rb', line 43

def reset!
  @load_attempted = false
  @loaded = false
end