lib/metanorma/collection_fileprocess.rb in metanorma-1.5.6 vs lib/metanorma/collection_fileprocess.rb in metanorma-1.5.7
- old
+ new
@@ -13,12 +13,14 @@
# @param path [String] path to collection
# @return [Hash{String=>Hash}]
def read_files(path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
files = {}
@xml.xpath(ns("//docref")).each do |d|
- identifier = d.at(ns("./identifier")).children.to_xml
- files[identifier] = file_entry(d, identifier, path)
+ orig_id = d.at(ns("./identifier"))
+ identifier = @c.decode(@isodoc
+ .docid_prefix(orig_id["type"], orig_id.children.to_xml))
+ files[identifier] = file_entry(d, orig_id.children.to_xml, path)
if files[identifier][:attachment]
files[identifier][:bibdata] = Metanorma::Document
.attachment_bibitem(identifier).root
else
file, _filename = targetfile(files[identifier], read: true)
@@ -93,10 +95,11 @@
end
# rel_path is the source file address, determined relative to the YAML.
# out_path is the destination file address, with any references outside
# the working directory (../../...) truncated
+ # identifier is the id with only spaces, no nbsp
def file_entry(ref, identifier, _path)
out = ref["attachment"] ? ref["fileref"] : File.basename(ref["fileref"])
ret = if ref["fileref"]
{ type: "fileref", ref: @documents[identifier].file,
rel_path: ref["fileref"], out_path: out }
@@ -119,9 +122,18 @@
def add_document_suffix(identifier, doc)
document_suffix = Metanorma::Utils::to_ncname(identifier)
Metanorma::Utils::anchor_attributes.each do |(tag_name, attribute_name)|
add_suffix_to_attributes(doc, document_suffix, tag_name, attribute_name)
+ end
+ url_in_css_styles(doc, document_suffix)
+ end
+
+ # update relative URLs, url(#...), in CSS in @style attrs (including SVG)
+ def url_in_css_styles(doc, document_suffix)
+ doc.xpath("//*[@style]").each do |s|
+ s["style"] = s["style"]
+ .gsub(%r{url\(#([^)]+)\)}, "url(#\\1_#{document_suffix})")
end
end
# return file contents + output filename for each file in the collection,
# given a docref entry