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
|
# File 'common/mixed_content_parser.rb', line 5
def self.parse(content, base_uri, opts = {} )
opts[:pretty_print] ||= false
return if content.nil?
content.strip!
content.chomp!
return '' if content.empty?
d = org.jsoup.Jsoup.parse("")
d.outputSettings.prettyPrint(opts[:pretty_print])
content.gsub!("\n\t", "\n\n")
content = content.split("\n\n").inject("") { |c, n| c << "<p>#{n}</p>" } if opts[:wrap_blocks]
whitelist = org.jsoup.safety.Whitelist.relaxed
.addTags("emph", "lb", "title", "unitdate")
.addAttributes("emph", "render")
.addAttributes("title", "render")
.addAttributes("unitdate", "render")
cleaned_content = org.jsoup.Jsoup.clean(content, base_uri, whitelist, d.outputSettings())
document = org.jsoup.Jsoup.parse(cleaned_content, base_uri, org.jsoup.parser.Parser.xmlParser())
document.outputSettings.escapeMode(Java::OrgJsoupNodes::Entities::EscapeMode.xhtml)
document.outputSettings.prettyPrint(opts[:pretty_print])
document.select("lb").tagName("br")
[ "emph", "title", "unitdate" ].each do |tag|
document.select(tag).each do |emph|
emph.tagName("span")
if emph.attr("render").empty?
emph.attr("class", "emph render-none")
elsif emph.attr("render") === "nonproport"
emph.attr("class", "emph render-#{emph.attr("render")}")
emph.tagName("code")
emph.removeAttr("render")
else
emph.attr("class", "emph render-#{emph.attr("render")}")
emph.removeAttr("render")
end
end
end
document.toString()
end
|