require "spec_helper" RSpec.describe IsoDoc do it "processes section split HTML" do FileUtils.rm_f "test.xml" FileUtils.rm_f "test.html.yaml" FileUtils.rm_rf "test_collection" FileUtils.rm_rf "test_files" input = <<~INPUT ISO Title ISO 1 abstract introduction Clause 4 Introduction

HE

SHE

A B
P
Clause 4.2

admonition

<strong>Annex</strong><br/>(informative) Annex A.1 Annex A.1a Annex Bibliography Normative References R1Hello Bibliography Bibliography Subsection
INPUT mock_render IsoDoc::HtmlConvert.new({ sectionsplit: "true" }) .convert("test", input, true) expect(File.exist?("test_collection/index.html")).to be true expect(File.exist?("test_collection/test.0.html")).to be true expect(File.exist?("test_collection/test.1.html")).to be true expect(File.exist?("test_collection/test.2.html")).to be true expect(File.exist?("test_collection/test.3.html")).to be false expect(File.exist?("test_collection/test.4.html")).to be true expect(File.exist?("test_collection/test.5.html")).to be true expect(File.exist?("test_collection/test.6.html")).to be true expect(File.exist?("test_collection/test.7.html")).to be true expect(File.exist?("test_collection/test.8.html")).to be false expect(File.exist?("test_files/cover.html")).to be true expect(File.exist?("test_files/test.0.xml")).to be true expect(File.exist?("test_files/test.1.xml")).to be true expect(File.exist?("test_files/test.2.xml")).to be true expect(File.exist?("test_files/test.3.xml")).to be true expect(File.exist?("test_files/test.4.xml")).to be true expect(File.exist?("test_files/test.5.xml")).to be true expect(File.exist?("test_files/test.6.xml")).to be true expect(File.exist?("test_files/test.7.xml")).to be true expect(File.exist?("test_files/test.8.xml")).to be false expect(File.exist?("test_files/test.html.yaml")).to be true m = /type="([^"]+)"/.match(File.read("test_files/test.0.xml")) file2 = Nokogiri::XML(File.read("test_files/test.2.xml")) expect(xmlpp(file2 .at("//xmlns:eref[@bibitemid = '#{m[1]}_A']").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT) HEA OUTPUT expect(xmlpp(file2 .at("//xmlns:eref[@bibitemid = '#{m[1]}_R1']").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT) SHE#{m[1]}_R1 OUTPUT expect(xmlpp(file2 .at("//xmlns:bibitem[@id = '#{m[1]}_R1']").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT) #{m[1]}/R1 OUTPUT expect(xmlpp(file2 .at("//xmlns:bibitem[@id = '#{m[1]}_A']").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT) #{m[1]}/A OUTPUT expect(xmlpp(file2 .at("//xmlns:svgmap[1]").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT)
A B #{m[1]}_R1
AB
OUTPUT expect(xmlpp(file2 .at("//xmlns:svgmap[2]").to_xml)) .to be_equivalent_to xmlpp(<<~OUTPUT)
P
P
OUTPUT expect(File.read("test_files/test.html.yaml")).to be_equivalent_to <<~OUTPUT --- directives: - presentation-xml - bare-after-first bibdata: title: type: title-main language: en content: ISO Title type: collection docid: type: ISO id: ISO 1 manifest: level: collection title: Collection docref: - fileref: test.3.xml identifier: "[Untitled]" - fileref: test.0.xml identifier: abstract - fileref: test.1.xml identifier: introduction - fileref: test.6.xml identifier: Normative References - fileref: test.2.xml identifier: Clause 4 - fileref: test.4.xml identifier: Annex (informative) - fileref: test.5.xml identifier: "[Untitled]" - fileref: test.7.xml identifier: Bibliography OUTPUT end private def mock_render original_add = ::Metanorma::CollectionRenderer.method(:render) allow(::Metanorma::CollectionRenderer) .to receive(:render) do |col, opts| original_add.call(col, opts.merge(compile: { no_install_fonts: true })) end end end