/
html_block.cr
43 lines (35 loc) · 1.15 KB
/
html_block.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Markd::Rule
struct HTMLBlock
include Rule
def match(parser : Lexer, container : Node)
if !parser.indented && char_at(parser) == '<'
text = slice(parser)
block_type_size = Rule::HTML_BLOCK_OPEN.size - 1
Rule::HTML_BLOCK_OPEN.each_with_index do |regex, index|
if (text.match(regex) &&
(index < block_type_size || !container.type.paragraph?))
parser.close_unmatched_blocks
# We don't adjust parser.offset;
# spaces are part of the HTML block:
node = parser.add_child(Node::Type::HTMLBlock, parser.offset)
node.data["html_block_type"] = index
return MatchValue::Leaf
end
end
end
MatchValue::None
end
def continue(parser : Lexer, container : Node)
(parser.blank && [5, 6].includes?(container.data["html_block_type"])) ? ContinueStatus::Stop : ContinueStatus::Continue
end
def token(parser : Lexer, container : Node)
container.text = container.text.gsub(/(\n *)+$/, "")
end
def can_contain?(type)
false
end
def accepts_lines?
true
end
end
end