diff --git a/lib/isodoc/convert.rb b/lib/isodoc/convert.rb
index 5238c060..30e219e3 100644
--- a/lib/isodoc/convert.rb
+++ b/lib/isodoc/convert.rb
@@ -114,7 +114,7 @@ def preprocess_xslt(docxml)
docxml = Nokogiri::XSLT(x).transform(docxml)
end
docxml
- rescue
+ rescue ::Error => e
require "debug"; binding.b
end
diff --git a/lib/isodoc/presentation_function/bibdata.rb b/lib/isodoc/presentation_function/bibdata.rb
index bf1282aa..afda6351 100644
--- a/lib/isodoc/presentation_function/bibdata.rb
+++ b/lib/isodoc/presentation_function/bibdata.rb
@@ -17,7 +17,8 @@ def bibdata(docxml)
def extension_insert(docxml, path = [])
ins = docxml.at(ns("//metanorma-extension")) ||
- docxml.at(ns("//bibdata")).after("").next_element
+ docxml.at(ns("//bibdata"))&.after("")&.next_element ||
+ docxml.root.elements.first.before("").previous_element
path.each do |n|
ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
end
@@ -25,9 +26,39 @@ def extension_insert(docxml, path = [])
end
def preprocess_xslt_insert(docxml)
- content = preprocess_xslt_read or return
+ content = ""
+ p = passthrough_xslt and content += p
+ p = preprocess_xslt_read and content += File.read(p)
+ content.empty? and return
ins = extension_insert(docxml, %w(render))
- ins << File.read(content)
+ ins << content
+ end
+
+ def passthrough_xslt
+ @output_formats.nil? and return nil
+ @output_formats.empty? and return nil
+ @output_formats.each_key.with_object([]) do |k, m|
+ m << <<~XSLT
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ XSLT
+ end.join("\n")
end
# read in from file, but with `` wrapper
@@ -45,7 +76,7 @@ def toc_metadata(docxml)
ins << "#{@i18n.toc_tables}"
@tocfigures and
ins << "#{@i18n.toc_recommendations}" \
- ""
+ ""
end
def address_precompose(bib)
@@ -152,8 +183,8 @@ def i8n_name(hash, pref)
when Array
hash.reject { |a| blank?(a) }.each_with_object([])
.with_index do |(v1, g), i|
- i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
- end
+ i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
+ end
else [i18n_tag(pref, hash)]
end
end
diff --git a/lib/isodoc/presentation_function/inline.rb b/lib/isodoc/presentation_function/inline.rb
index 81723598..bde3d97c 100644
--- a/lib/isodoc/presentation_function/inline.rb
+++ b/lib/isodoc/presentation_function/inline.rb
@@ -111,14 +111,29 @@ def custom_charset(docxml)
end
end
+ def passthrough(docxml)
+ formats = @output_formats.keys
+ docxml.xpath(ns("//passthrough")).each do |p|
+ passthrough1(p, formats)
+ end
+ end
+
+ def passthrough1(elem, formats)
+ (elem["formats"] && !elem["formats"].empty?) or elem["formats"] = "all"
+ f = elem["formats"].split(",")
+ (f - formats).size == f.size or elem["formats"] = "all"
+ elem["formats"] == "all" and elem["formats"] = formats.join(",")
+ elem["formats"] = ",#{elem['formats']},"
+ end
+
private
def extract_custom_charsets(docxml)
docxml.xpath(ns("//presentation-metadata/custom-charset-font")).
each_with_object({}) do |x, m|
- kv = x.text.split(":", 2)
- m[kv[0]] = kv[1]
- end
+ kv = x.text.split(":", 2)
+ m[kv[0]] = kv[1]
+ end
end
def found_matching_variant_sibling(node)
diff --git a/lib/isodoc/presentation_xml_convert.rb b/lib/isodoc/presentation_xml_convert.rb
index faf7d2c1..67ae3032 100644
--- a/lib/isodoc/presentation_xml_convert.rb
+++ b/lib/isodoc/presentation_xml_convert.rb
@@ -89,6 +89,7 @@ def inline(docxml)
variant docxml
identifier docxml
date docxml
+ passthrough docxml
inline_format docxml
end
diff --git a/spec/isodoc/blocks_spec.rb b/spec/isodoc/blocks_spec.rb
index cbd2d1ac..377579df 100644
--- a/spec/isodoc/blocks_spec.rb
+++ b/spec/isodoc/blocks_spec.rb
@@ -1812,13 +1812,17 @@
it "processes passthrough with compatible format" do
FileUtils.rm_f "test.html"
- IsoDoc::HtmlConvert.new({}).convert("test", <<~INPUT, false)
+ input = <<~INPUT
-
+
<A>Hello</A>
INPUT
+ presxml = IsoDoc::PresentationXMLConvert
+ .new(presxml_options.merge(output_formats: { html: "html", rfc: "rfc" }))
+ .convert("test", input, true)
+ IsoDoc::HtmlConvert.new({}).convert("test", presxml, false)
expect(xmlpp(File.read("test.html")
.gsub(%r{^.*Foreword
}m, "")
.gsub(%r{.*}m, ""))).to be_equivalent_to xmlpp(<<~OUTPUT)
@@ -1832,14 +1836,17 @@
begin
input = <<~INPUT
-
+
<A>Hello
INPUT
+ presxml = IsoDoc::PresentationXMLConvert
+ .new(presxml_options.merge(output_formats: { html: "html", rfc: "rfc" }))
+ .convert("test", input, true)
expect do
IsoDoc::HtmlConvert.new({})
- .convert("test", input, false)
+ .convert("test", presxml, false)
end.to raise_error(SystemExit)
rescue SystemExit
end
@@ -1868,8 +1875,11 @@