Class: Kramdown::Parser::ISKram
- Inherits:
-
Kramdown
- Object
- Kramdown
- Kramdown::Parser::ISKram
- Defined in:
- lib/kramdown_parser/kram_parser.rb
Class Method Summary collapse
- .register_ast_element_hook(*elements, &hook) ⇒ Object
- .register_post_parse_hook(&hook) ⇒ Object
- .trigger_ast_elements_hooks(parser) ⇒ Object
- .trigger_post_parse_hooks(parser) ⇒ Object
Instance Method Summary collapse
Class Method Details
.register_ast_element_hook(*elements, &hook) ⇒ Object
19 20 21 22 |
# File 'lib/kramdown_parser/kram_parser.rb', line 19 def register_ast_element_hook *elements, &hook @element_hooks ||= [] @element_hooks << { elements: elements, hook: hook } end |
.register_post_parse_hook(&hook) ⇒ Object
8 9 10 11 |
# File 'lib/kramdown_parser/kram_parser.rb', line 8 def register_post_parse_hook &hook @hooks ||= [] @hooks << hook end |
.trigger_ast_elements_hooks(parser) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/kramdown_parser/kram_parser.rb', line 24 def trigger_ast_elements_hooks parser return if @element_hooks.nil? || @element_hooks.empty? traverse = lambda do |elem| elem.children.each_with_index do |child, index| handled = false @element_hooks.each do |hook| if hook[:elements].include?(child.type) hooked = hook[:hook].call elem, child, index handled ||= hooked end end traverse.call child unless handled end end traverse.call parser.root end |
.trigger_post_parse_hooks(parser) ⇒ Object
13 14 15 16 17 |
# File 'lib/kramdown_parser/kram_parser.rb', line 13 def trigger_post_parse_hooks parser @hooks.each do |hook| hook.call parser end end |
Instance Method Details
#parse ⇒ Object
43 44 45 46 47 |
# File 'lib/kramdown_parser/kram_parser.rb', line 43 def parse super trigger_post_parse_hooks trigger_ast_elements_hooks end |