Class: Kramdown::Parser::GFM

Inherits:
Object
  • Object
show all
Defined in:
lib/bridgetown-core/kramdown/parser/gfm.rb

Constant Summary collapse

MARK_DELIMITER =
%r{(==|::)+}
MARK_MATCH =
%r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m

Instance Method Summary collapse

Constructor Details

#initialize(source, options) ⇒ GFM

Returns a new instance of GFM.



13
14
15
16
# File 'lib/bridgetown-core/kramdown/parser/gfm.rb', line 13

def initialize(source, options)
  _old_initialize(source, options)
  @span_parsers << :mark if @options[:mark_highlighting]
end

Instance Method Details

#_old_initializeObject

Monkey-patch GFM initializer to add our new mark parser



12
# File 'lib/bridgetown-core/kramdown/parser/gfm.rb', line 12

alias_method :_old_initialize, :initialize

#parse_markObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bridgetown-core/kramdown/parser/gfm.rb', line 18

def parse_mark
  line_number = @src.current_line_number

  @src.pos += @src.matched_size
  el = Element.new(:html_element, "mark", {}, category: :span, line: line_number)
  @tree.children << el

  env = save_env
  reset_env(src: Kramdown::Utils::StringScanner.new(@src.matched[2..-3], line_number),
            text_type: :text)
  parse_spans(el)
  restore_env(env)

  el
end