Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Jul 22, 2024
1 parent 7d9fde6 commit ef2e688
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
1 change: 1 addition & 0 deletions metanorma-plugin-lutaml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "timecop", "~> 0.9"
spec.add_development_dependency "vcr", "~> 5.0.0"
spec.add_development_dependency "webmock"
spec.add_development_dependency "xml-c14n"
end
Binary file not shown.
28 changes: 4 additions & 24 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require "metanorma-standoc"
require "rspec/matchers"
require "equivalent-xml"
require "xml-c14n"

Dir[File.expand_path("./support/**/**/*.rb", __dir__)].sort.each do |f|
require f
Expand Down Expand Up @@ -80,10 +81,12 @@ def strip_guid(xml)
xml
.gsub(%r{ id="_[^"]+"}, ' id="_"')
.gsub(%r{ target="_[^"]+"}, ' target="_"')
.gsub(%r{<fetched>[^<]+</fetched>}, "<fetched/>")
.gsub(%r{ schema-version="[^"]+"}, "")
end

def xml_string_content(xml)
strip_guid(xmlpp(Nokogiri::XML(xml).to_s))
strip_guid(Xml::C14n.format(Nokogiri::XML(xml).to_s))
end

def metanorma_process(input)
Expand All @@ -102,26 +105,3 @@ def strip_src(xml)
xml.gsub(/\ssrc="[^"]+"/, ' src="_"')
end

XSL = Nokogiri::XSLT(<<~XSL.freeze)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
XSL

def xmlpp(xml)
c = HTMLEntities.new
xml &&= xml.split(/(&\S+?;)/).map do |n|
if /^&\S+?;$/.match?(n)
c.encode(c.decode(n), :hexadecimal)
else n
end
end.join
XSL.transform(Nokogiri::XML(xml, &:noblanks))
.to_xml(indent: 2, encoding: "UTF-8")
.gsub(%r{<fetched>[^<]+</fetched>}, "<fetched/>")
.gsub(%r{ schema-version="[^"]+"}, "")
end

0 comments on commit ef2e688

Please sign in to comment.