Module: Commonmarker::Merge::Backend

Defined in:
lib/commonmarker/merge/backend.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 = Commonmarker::Merge::Backend::Language.markdown
tree = parser.parse(markdown_source)
root = tree.root_node
puts root.type  # => "document"

See Also:

Defined Under Namespace

Classes: Language, Node, Parser, Tree

Constant Summary collapse

Point =

Alias Point to the base class for compatibility

TreeHaver::Base::Point

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/commonmarker/merge/backend.rb', line 27

def available?
  return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable
  @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable
  begin
    require "commonmarker"
    @loaded = true # rubocop:disable ThreadSafety/ClassInstanceVariable
  rescue LoadError
    @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable
  rescue StandardError
    @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable
  end
  @loaded # rubocop:disable ThreadSafety/ClassInstanceVariable
end

.capabilitiesHash{Symbol => Object}

Get capabilities supported by this backend

Returns:

  • (Hash{Symbol => Object})

    capability map



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/commonmarker/merge/backend.rb', line 53

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)



45
46
47
48
# File 'lib/commonmarker/merge/backend.rb', line 45

def reset!
  @load_attempted = false # rubocop:disable ThreadSafety/ClassInstanceVariable
  @loaded = false # rubocop:disable ThreadSafety/ClassInstanceVariable
end