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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
require 'rubygems'
require 'maruku'
include MaRuKu::In::Markdown::BlockLevelParser
OpenDiv = /^\+\-\-/
CloseDiv = /^\=\-\-/
MaRuKu::In::Markdown::register_block_extension(
:regexp => OpenDiv,
:handler => lambda { |doc, src, context|
# Throw away the first line.
src.shift_line
# Read lines from src until one matches CloseDiv
lines = []
while src.cur_line && !(src.cur_line =~ CloseDiv)
lines.push src.shift_line
end
# Throw away this last line.
src.shift_line
# Parse lines as blocks.
content = "lines<flash>#{lines}</flash>"
context.push doc.md_html(content)
true
})
# RegInlineMath = /\${1}((?:[^\$]|\\\$)+)\$/
RegInlineMath = /!((?:[^!]|\\!)+)!/
# RegInlineMath = /!![^(!!)]+!!/
MaRuKu::In::Markdown::register_span_extension(
:chars => ?!,
:regexp => RegInlineMath,
:handler => lambda { |doc, src, con|
if m = src.read_regexp(RegInlineMath)
math = m.captures.compact.first
math = "<attachement>#{math}</attachement>"
con.push doc.md_html(math)
true
else
# puts "not math: #{src.cur_chars 10}"
false
end
}
)
markdown_string = <<EOF
+--
Div content
=--
视频文件:
!/path/to/file!
!/path/to/file!
EOF
doc = Maruku.new(markdown_string)
puts doc.to_html
# puts '\r\n=======================\r\n'
# puts doc.to_html_document |