is-kramdown-hooked 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kramdown_parser/kram_parser.rb +22 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2a3cd95aeb6e6688217305c0b8a77ffbfe6298a56acdf5b771f59089f147d6b5
|
|
4
|
+
data.tar.gz: ad0c0ebaf2f0c8adfa99bf1a25f4695b694e0b52a8741a4c50b3389b509c09a8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ef85eb63c1c59975699c0a2394b60cc86e4701eefba563c2231a59e9d01a3523b6248d8b62e9d848e5facde18d7e7cd7563e6c8a1729e19bbeb375eaf5695f44
|
|
7
|
+
data.tar.gz: 70991d03b7279a578341188d36fe2220a7042f8b44f711c6880da5f4ac009df46b85865ffa21e5295a1d3b1842971333965465e4f6e39a6a7e44ab1c8f88041c
|
|
@@ -8,9 +8,17 @@ class Kramdown::Parser::ISKram < Kramdown::Parser::Kramdown
|
|
|
8
8
|
def register_post_parse_hook &hook
|
|
9
9
|
@hooks ||= []
|
|
10
10
|
@hooks << hook
|
|
11
|
+
hook
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def unregister_post_parse_hook hook
|
|
15
|
+
if @hooks
|
|
16
|
+
@hooks.delete hook
|
|
17
|
+
end
|
|
11
18
|
end
|
|
12
19
|
|
|
13
20
|
def trigger_post_parse_hooks parser
|
|
21
|
+
return if @hooks.nil? || @hooks.empty?
|
|
14
22
|
@hooks.each do |hook|
|
|
15
23
|
hook.call parser
|
|
16
24
|
end
|
|
@@ -19,23 +27,32 @@ class Kramdown::Parser::ISKram < Kramdown::Parser::Kramdown
|
|
|
19
27
|
def register_ast_element_hook *elements, &hook
|
|
20
28
|
@element_hooks ||= []
|
|
21
29
|
@element_hooks << { elements: elements, hook: hook }
|
|
30
|
+
hook
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unregister_ast_element_hook hook
|
|
34
|
+
if @element_hooks
|
|
35
|
+
@element_hooks.delete_if { |rec| rec[:hook] == hook }
|
|
36
|
+
end
|
|
22
37
|
end
|
|
23
38
|
|
|
24
39
|
def trigger_ast_elements_hooks parser
|
|
25
40
|
return if @element_hooks.nil? || @element_hooks.empty?
|
|
26
|
-
traverse = lambda do |
|
|
27
|
-
elem
|
|
41
|
+
traverse = lambda do |path|
|
|
42
|
+
elem = path.last
|
|
43
|
+
pp elem
|
|
44
|
+
elem.children.each do |child|
|
|
28
45
|
handled = false
|
|
29
46
|
@element_hooks.each do |hook|
|
|
30
47
|
if hook[:elements].include?(child.type)
|
|
31
|
-
hooked = hook[:hook].call
|
|
48
|
+
hooked = hook[:hook].call path, child
|
|
32
49
|
handled ||= hooked
|
|
33
50
|
end
|
|
34
51
|
end
|
|
35
|
-
traverse.call child unless handled
|
|
52
|
+
traverse.call(path + [child]) unless handled
|
|
36
53
|
end
|
|
37
54
|
end
|
|
38
|
-
traverse.call
|
|
55
|
+
traverse.call([parser.root])
|
|
39
56
|
end
|
|
40
57
|
|
|
41
58
|
end
|