This repository has been archived by the owner on May 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverters.rb
63 lines (55 loc) · 1.88 KB
/
converters.rb
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
60
61
62
63
require 'reverse_markdown'
module Converters
class StructuredMacro < ReverseMarkdown::Converters::Base
def convert(node, state={})
if node['ac:name'] == 'info'
status = node
.css('tr:last-child td:first-child parameter')
.select { |n| n['ac:name'] == 'title' }
.first
.content
notes = node.at_css('tr:last-child td:last-child').content
<<-EOF
---
status: "#{status}"
notes: "#{notes}"
---
EOF
else
""
end
rescue
""
end
end
class UserLink < ReverseMarkdown::Converters::Base
def convert(node, state={})
parser = ReverseMarkdown.config.instance_variable_get(:@inline_options)[:confluence_parser]
user = parser.by_id(node['ri:userkey'])
user.name
end
end
class Code < ReverseMarkdown::Converters::Base
def convert(node, state = {})
xml = node.to_s.gsub(%r{<inline-comment-marker ac:ref="(.*?)">}, '<inline-comment-marker>!!inline-comment-marker:\1!!</inline-comment-marker>')
node = Nokogiri::XML(xml)
"`#{node.text}`"
end
end
class InlineComment < ReverseMarkdown::Converters::Base
def convert(node, state={})
"!!inline-comment-marker:#{node['ac:ref']}!!" + treat_children(node, state)
end
end
class Emoticon < ReverseMarkdown::Converters::Base
def convert(node, state={})
":#{node['ac:name'].sub('-','')}:"
end
end
end
ReverseMarkdown::Converters.register "placeholder", ReverseMarkdown::Converters::Ignore.new
ReverseMarkdown::Converters.register "structured-macro", Converters::StructuredMacro.new
ReverseMarkdown::Converters.register "user", Converters::UserLink.new
ReverseMarkdown::Converters.register "inline-comment-marker", Converters::InlineComment.new
ReverseMarkdown::Converters.register "code", Converters::Code.new
ReverseMarkdown::Converters.register "emoticon", Converters::Emoticon.new