Module: PageHub::Markdown
- Defined in:
- lib/pagehub-markdown/markdown.rb,
lib/pagehub-markdown/processors/embedder.rb,
lib/pagehub-markdown/mutators/date_injector.rb,
lib/pagehub-markdown/processors/toc_generator.rb,
lib/pagehub-markdown/processors/pagehub_options.rb
Defined Under Namespace
Modules: Embedder, ToC
Classes: HTMLWithAlbino
Class Method Summary
collapse
Class Method Details
.add_mutator(m) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/pagehub-markdown/markdown.rb', line 24
def add_mutator(m)
unless m.respond_to?(:call)
raise "Mutator must be a callable object."
end
@@mutators << m
end
|
.add_processor(stage, p) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/pagehub-markdown/markdown.rb', line 5
def add_processor(stage, p)
Stages.each { |s| @@hooks[s] ||= [] }
unless Stages.include?(stage.to_sym)
raise "Invalid stage #{stage}. Allowed stages are #{Stages.join(', ')}"
end
unless p.respond_to?(:call)
raise "Processor must be a callable object."
end
if stage.is_a? Array
stage.each { |s| @@hooks[s] << p }
else
@@hooks[stage.to_sym] << p
end
end
|
(re)constructs the renderer with the given options, see PageHubOptions, RendererOptions, and RendererExtensions for accepted values
35
36
37
38
39
40
41
42
|
# File 'lib/pagehub-markdown/markdown.rb', line 35
def configure(ph_options = {}, options = {}, extensions = {})
@@options ||= PageHubOptions.dup
@@options.merge!(ph_options)
@@renderer = Redcarpet::Markdown.new(
HTMLWithAlbino.new(RendererOptions.merge(options)),
RendererExtensions.merge(extensions))
end
|
.mutate!(str) ⇒ Object
75
76
77
78
79
|
# File 'lib/pagehub-markdown/markdown.rb', line 75
def mutate!(str)
mutated = false
@@mutators.each { |m| mutated ||= m.call(str) }
mutated
end
|
.options ⇒ Object
48
49
50
|
# File 'lib/pagehub-markdown/markdown.rb', line 48
def options
@@options
end
|
.render(str) ⇒ Object
69
70
71
72
73
|
# File 'lib/pagehub-markdown/markdown.rb', line 69
def render(str)
str.dup.tap do |md|
render!(md)
end
end
|
.render!(str) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/pagehub-markdown/markdown.rb', line 52
def render!(str)
configure
@@hooks[:pre_render].each { |processor| processor.call(str) }
if @@options[:escape_scripts]
str.gsub!(%r{<([^>]*)script[^>]*>}, "<\\1script>")
end
str = @@renderer.render(str)
@@hooks[:post_render].each { |processor| processor.call(str) }
str
end
|
.reset_config ⇒ Object
44
45
46
|
# File 'lib/pagehub-markdown/markdown.rb', line 44
def reset_config()
@@options = PageHubOptions.dup
end
|