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
|
# File 'lib/inline_fn.rb', line 9
def inline_fn(str, style = :pandoc)
ref_start = ''
text = str
counter = 0
until ref_start.nil?
counter += 1
cite = "[^#{counter}]"
ref = "[^#{counter}]:"
ref_start = text.index(ref)
break if ref_start.nil?
next_ref = "[^#{counter + 1}]:"
ref_end = text.index(next_ref).nil? ? -1 : text.index(next_ref) - 2
offset = counter.to_s.length + 5
note = case style
when :mmd
"[^#{text[ref_start + offset..ref_end].strip}]"
else
"^[#{text[ref_start + offset..ref_end].strip}]"
end
text = text.gsub(cite, note)
end
if counter >= 1
case style
when :mmd
text = text.gsub(/\n\s*\[\^/, "\n[^")
cut_point = text.index("\n[^")
else
text = text.gsub(/\n\s*\^\[/, "\n^[")
cut_point = text.index("\n^")
end
text = text[0, cut_point]
end
text
end
|