require "isodoc" require_relative "metadata" require "fileutils" module IsoDoc module NIST class Xref < IsoDoc::Xref SECTIONS_XPATH = "//foreword | //introduction | //reviewnote | //executivesummary | //annex | "\ "//sections/clause | //bibliography/references | //acknowledgements | "\ "//bibliography/clause | //preface/clause".freeze def initial_anchor_names(d) d.xpath("//xmlns:boilerplate/child::* | //xmlns:preface/child::*").each do |c| preface_names(c) end @in_execsummary = true hierarchical_asset_names(d.xpath("//xmlns:executivesummary"), "ES") @in_execsummary = false clause_names(d, 0) middle_section_asset_names(d) termnote_anchor_names(d) termexample_anchor_names(d) end def back_anchor_names(docxml) docxml.xpath(ns("//annex")).each_with_index do |c, i| annex_names(c, (65 + i).chr.to_s) end docxml.xpath(ns("//bibliography/clause | "\ "//bibliography/references")).each do |b| preface_names(b) end docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref| reference_names(ref) end end def middle_section_asset_names(d) middle_sections = "//xmlns:preface/child::*[not(self::xmlns:executivesummary)] | "\ "//xmlns:sections/child::*" sequential_asset_names(d.xpath(middle_sections)) end def clause_names(docxml, sect_num) q = "//xmlns:sections/child::*" docxml.xpath(q).each_with_index do |c, i| section_names(c, (i + sect_num), 1) end end def annex_name_lbl(clause, num) l10n("#{@labels['annex']} #{num}") end def annex_name(annex, name, div) div.h1 **{ class: "Annex" } do |t| t << "#{anchor(annex['id'], :label)} — " t.b do |b| if @bibliographycount == 1 && annex.at(ns("./references")) b << "References" else name&.children&.each { |c2| parse(c2, b) } end end end end def hiersep "-" end def terms_parse(node, out) out.div **attr_code(id: node["id"]) do |div| node.at(ns("./title")) and clause_parse_title(node, div, node.at(ns("./title")), out) node.elements.each do |e| parse(e, div) unless %w{title source}.include? e.name end end end end end end