From 044f6348957f702a5569003a2ac7bc2d2b6b81dc Mon Sep 17 00:00:00 2001
From: Nick Nicholas This is one callout This is another callout This is yet another callout This is one callout This is another callout This is yet another callout Key This is one callout This is another callout This is yet another callout Figure 1
"
- callout = node.at(ns("//callout[@target='#{node['id']}']"))
- div << "<#{callout.text}> "
- div << "#{node.children&.text&.strip}"
- node.at("./following-sibling::*[local-name() = 'annotation']") and
- div << "
"
- @annotation = false
+ parse(dl, div)
+ # @annotation = false
end
end
diff --git a/lib/isodoc/html_function/html.rb b/lib/isodoc/html_function/html.rb
index 9e2d775f..78cef941 100644
--- a/lib/isodoc/html_function/html.rb
+++ b/lib/isodoc/html_function/html.rb
@@ -96,6 +96,7 @@ def sourcecode_parse(node, out)
out.send tag, **attr do |div|
sourcecode_parse1(node, div)
end
+ annotation_parse(node, out)
sourcecode_name_parse(node, out, name)
end
diff --git a/lib/isodoc/presentation_function/sourcecode.rb b/lib/isodoc/presentation_function/sourcecode.rb
index e2782f86..47f0108c 100644
--- a/lib/isodoc/presentation_function/sourcecode.rb
+++ b/lib/isodoc/presentation_function/sourcecode.rb
@@ -28,9 +28,16 @@ def sourcehighlighter
{ formatter: f, formatter_line: f1 }
end
+ def callouts(elem)
+ elem.xpath(ns(".//callout")).each do |c|
+ @callouts[c["target"]] = c.children.to_xml
+ end
+ end
+
def sourcecode(docxml)
sourcehighlighter_css(docxml)
@highlighter = sourcehighlighter
+ @callouts = {}
docxml.xpath(ns("//sourcecode")).each do |f|
sourcecode1(f)
end
@@ -39,6 +46,21 @@ def sourcecode(docxml)
def sourcecode1(elem)
source_highlight(elem)
source_label(elem)
+ callouts(elem)
+ annotations(elem)
+ end
+
+ def annotations(elem)
+ elem.at(ns("./annotation")) or return
+ ret = ""
+ elem.xpath(ns("./annotation")).each do |a|
+ a.remove
+ ret += <<~OUT
+
"
end
def source_highlight(elem)
@@ -64,7 +86,7 @@ def source_remove_markup(elem)
def source_remove_annotations(ret, elem)
ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
- m << { xml: c.remove.to_xml, line: c.line - elem.line }
+ m << { xml: c.remove, line: c.line - elem.line }
end
ret
end
@@ -84,7 +106,7 @@ def source_restore_callouts(code, callouts)
text = to_xml(code)
text.split(/[\n\r]/).each_with_index do |c, i|
while !callouts.empty? && callouts[0][:line] == i
- c.sub!(/\s+$/, " #{callouts[0][:xml]} ")
+ c.sub!(/\s+$/, " #{reinsert_callout(callouts[0][:xml])} ")
callouts.shift
end
end.join("\n")
@@ -94,12 +116,16 @@ def source_restore_callouts_table(table, callouts)
table.xpath(".//td[@class = 'rouge-code']/sourcecode")
.each_with_index do |c, i|
while !callouts.empty? && callouts[0][:line] == i
- c << " #{callouts[0][:xml]} "
+ c << " #{reinsert_callout(callouts[0][:xml])} "
callouts.shift
end
end
end
+ def reinsert_callout(xml)
+ "#{to_xml(xml)}"
+ end
+
def sourcecode_table_to_elem(elem, tokens)
r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
r.xpath(".//td[@class = 'rouge-code']/pre").each do |pre|
diff --git a/spec/isodoc/sourcecode_spec.rb b/spec/isodoc/sourcecode_spec.rb
index 66671622..bf6aaffd 100644
--- a/spec/isodoc/sourcecode_spec.rb
+++ b/spec/isodoc/sourcecode_spec.rb
@@ -516,10 +516,10 @@
Foreword
- puts "Hello, world." <1> <2>
+
%w{a b c}.each do |x|
puts x <3>
endputs "Hello, world." <1> <2>
+
%w{a b c}.each do |x|
puts x <3>
end
+
+
puts "Hello, world." <1><2>
%w{a b c}.each do |x|
puts x <3>
end
puts "Hello, world." <1> <2>
%w{a b c}.each do |x|
puts x <3>
end
Key
+
+ + 1 + + |
+
+ This is one callout + |
+
+ + 2 + + |
+
+ This is another callout + |
+
+ + 3 + + |
+
+ This is yet another callout + |
+
Figure 1
@@ -640,15 +698,21 @@ -
This is one callout
-This is another callout
-This is yet another callout
-This is one callout
+This is another callout
+This is yet another callout
+1
puts "Hello, world." <1> <2>-
2
%w{a b c}.each do |x|
3
puts x <3>
4
end
2
%w{a b c}.each do |x|
3
puts x <3>
4
end
Key
+This is one callout
+This is another callout
+This is yet another callout
+Figure 1
@@ -700,10 +783,42 @@puts "Hello, world." <1> <2>
2
%w{a b c}.each do |x|
3
puts x <3>
4
end
Key
+
+ + 1 + + |
+
+ This is one callout + |
+
+ + 2 + + |
+
+ This is another callout + |
+
+ + 3 + + |
+
+ This is yet another callout + |
+
Figure 1
@@ -762,12 +877,12 @@
This is one callout
-This is one callout
+