Module: Markly::Merge::Backend

Defined in:
lib/markly/merge/backend.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 = Markly::Merge::Backend::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, 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)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/markly/merge/backend.rb', line 30

def available?
  return @loaded if @load_attempted # rubocop:disable ThreadSafety/ClassInstanceVariable
  @load_attempted = true # rubocop:disable ThreadSafety/ClassInstanceVariable
  begin
    require "markly"
    @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



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/markly/merge/backend.rb', line 56

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)



48
49
50
51
# File 'lib/markly/merge/backend.rb', line 48

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