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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/hiki2md.rb', line 5
def convert(lines)
@outputs = []
@in_plugin_block = false
@in_preformated_block = false
lines.split(/\n/).each do |line|
if @in_plugin_block
if line =~ /}}\z/
@in_plugin_block = false
end
next
end
if line =~ /\A{{/
next if line =~ /\A{{.+}}\z/
@in_plugin_block = true
end
if @in_preformated_block
if line =~ /\A>>>/
@in_preformated_block = false
@outputs << '```'
next
end
@outputs << line
next
end
if line =~ /\A<<<\z/
@in_preformated_block = true
@outputs << '```'
next
end
next if line =~ %r|\A//.*\z|
line.gsub! /\A[ \t]+/, ' '
line.gsub! /\A""/, '>'
line.gsub! /\[{2}([^\[\]\|]+?)\|([^\[\]\|]+?)\]{2}/, "[\\1](\\2)"
line.gsub! /\A[*]{3} ?/, ' - '
line.gsub! /\A[*]{2} ?/, ' - '
line.gsub! /\A[*] ?/ , '- '
line.gsub! /\A[#]{3} ?/ , ' 1. '
line.gsub! /\A[#]{2} ?/ , ' 1. '
line.gsub! /\A[#] ?/ , '1. '
line.gsub! /\A!{5} ?/ , '##### '
line.gsub! /\A!{4} ?/ , '#### '
line.gsub! /\A!{3} ?/ , '### '
line.gsub! /\A!{2} ?/ , '## '
line.gsub! /\A! ?/ , '# '
line.gsub! /'''(.+)'''/, "**\\1**"
line.gsub! /''(.+)''/, "*\\1*"
line.gsub! /\=\=(.+)\=\=/, "~~\\1~~"
line.gsub! /\[{2}([^\[\]\|]+?)\]{2}/, "![](\\1)"
@outputs << line
end
@outputs.join("\n")
end
|