Module: MaRuKu::In::Markdown

Included in:
MDDocument
Defined in:
lib/amp-front/third_party/maruku.rb,
lib/amp-front/third_party/maruku/attributes.rb,
lib/amp-front/third_party/maruku/input/parse_doc.rb,
lib/amp-front/third_party/maruku/input/rubypants.rb,
lib/amp-front/third_party/maruku/input/charsource.rb,
lib/amp-front/third_party/maruku/input/extensions.rb,
lib/amp-front/third_party/maruku/input/linesource.rb,
lib/amp-front/third_party/maruku/input/html_helper.rb,
lib/amp-front/third_party/maruku/input/parse_block.rb,
lib/amp-front/third_party/maruku/input/parse_span_better.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



42
43
44
45
# File 'lib/amp-front/third_party/maruku/input/extensions.rb', line 42

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

.register_span_extension(args) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/amp-front/third_party/maruku/input/extensions.rb', line 32

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)


61
62
63
64
65
66
67
# File 'lib/amp-front/third_party/maruku/input/extensions.rb', line 61

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

#check_block_extensions(src, con, line) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/amp-front/third_party/maruku/input/extensions.rb', line 50

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

#check_span_extensions(src, con) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/amp-front/third_party/maruku/input/extensions.rb', line 20

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