Module: MaRuKu::In::Markdown

Included in:
MDDocument
Defined in:
lib/maruku.rb,
lib/maruku/input/extensions.rb,
lib/maruku/input/parse_block.rb

Defined Under Namespace

Modules: BlockLevelParser, SpanLevelParser Classes: SpanExtension

Constant Summary collapse

SpanExtensionsTrigger =

Hash Fixnum -> name

{}
SpanExtensions =

Hash String -> Extension

{}
BlockExtensions =

Hash Regexp -> Block

{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_block_extension(args) ⇒ Object


41
42
43
44
# File 'lib/maruku/input/extensions.rb', line 41

def self.register_block_extension(args)
  regexp = args[:regexp]
  BlockExtensions[regexp] = (args[:handler] || raise("No blocks passed"))
end

.register_span_extension(args) ⇒ Object


31
32
33
34
35
36
37
38
39
# File 'lib/maruku/input/extensions.rb', line 31

def self.register_span_extension(args)
  e = SpanExtension.new
  e.chars = [*args[:chars]]
  e.regexp = args[:regexp]
  e.block = args[:handler] || raise("No blocks passed")
  e.chars.each do |c|
    (SpanExtensionsTrigger[c] ||= []).push e
  end
end

Instance Method Details

#any_matching_block_extension?(line) ⇒ Boolean

Returns:

  • (Boolean)

60
61
62
63
64
65
66
# File 'lib/maruku/input/extensions.rb', line 60

def any_matching_block_extension?(line)
  BlockExtensions.each_key do |reg|
    m = reg.match(line)
    return m if m
  end
  false
end

#check_block_extensions(src, con, line) ⇒ Object


49
50
51
52
53
54
55
56
57
58
# File 'lib/maruku/input/extensions.rb', line 49

def check_block_extensions(src, con, line)
  BlockExtensions.each do |reg, block|
    if reg.match(line)
      block = BlockExtensions[reg]
      accepted =  block.call(doc, src, con)
      return true if accepted
    end
  end
  false # not special
end

#check_span_extensions(src, con) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/maruku/input/extensions.rb', line 18

def check_span_extensions(src, con)
  c = src.cur_char
  if extensions = SpanExtensionsTrigger[c]
    extensions.each do |e|
      if e.regexp && src.next_matches(e.regexp)
        return true if e.block.call(doc, src, con)
      end
    end
  end

  false # not special
end