Class: MetaCommit::Extension::MarkdownSupport::Parsers::Markdown

Inherits:
Contracts::Parser
  • Object
show all
Defined in:
lib/meta_commit_markdown_support/parsers/markdown.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.supported_file_extensionsArray<String>

Returns supported extensions.

Returns:

  • (Array<String>)

    supported extensions



6
7
8
# File 'lib/meta_commit_markdown_support/parsers/markdown.rb', line 6

def self.supported_file_extensions
  %w(.markdown .mdown .mkdn .md .mkd .mdwn .mdtxt .mdtext .Rmd)
end

.supports_syntax?(source_code) ⇒ Boolean

Parameters:

  • source_code (String)

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/meta_commit_markdown_support/parsers/markdown.rb', line 12

def self.supports_syntax?(source_code)
  begin
    document = CommonMarker.render_doc(source_code)
    !document.nil?
  rescue Encoding::UndefinedConversionError => e
    return false
  end
end

Instance Method Details

#parse(source_code) ⇒ MetaCommit::Contracts::Ast

Parameters:

  • source_code (String)

Returns:

  • (MetaCommit::Contracts::Ast)


23
24
25
26
# File 'lib/meta_commit_markdown_support/parsers/markdown.rb', line 23

def parse(source_code)
  document = CommonMarker.render_doc(source_code)
  MetaCommit::Extension::MarkdownSupport::Models::Ast.new(document)
end