Module: TreeHaver::Backends::Markly

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

Overview

Note:

This backend only parses Markdown source code

Markly backend using the Markly gem (cmark-gfm C library)

This backend wraps Markly, a Ruby gem that provides bindings to cmark-gfm, GitHub’s fork of the CommonMark C library with extensions.

Examples:

Basic usage

parser = TreeHaver::Parser.new
parser.language = TreeHaver::Backends::Markly::Language.markdown(
  flags: Markly::DEFAULT,
  extensions: [:table, :strikethrough]
)
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)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tree_haver/backends/markly.rb', line 30

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

.capabilitiesHash{Symbol => Object}

Get capabilities supported by this backend

Returns:

  • (Hash{Symbol => Object})

    capability map



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/tree_haver/backends/markly.rb', line 54

def capabilities
  return {} unless available?
  {
    backend: :markly,
    query: false,
    bytes_field: false,       # Markly uses line/column
    incremental: false,
    pure_ruby: false,         # Uses C via FFI
    markdown_only: true,
    error_tolerant: true,     # Markdown is forgiving
    gfm_extensions: true,     # Supports GitHub Flavored Markdown
  }
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)



46
47
48
49
# File 'lib/tree_haver/backends/markly.rb', line 46

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