require"metanorma-standoc"require_relative"./validate_style.rb"require_relative"./validate_requirements.rb"require_relative"./validate_section.rb"require_relative"./validate_title.rb"require"nokogiri"require"jing"require"iev"moduleAsciidoctormoduleISOclassConverter<Standoc::Converter# ISO/IEC DIR 2, 22.3.2defonlychild_clause_validate(root)root.xpath(Standoc::Utils::SUBCLAUSE_XPATH).eachdo|c|nextunlessc.xpath("../clause").size==1title=c.at("./title")location=c["id"]||c.text[0..60]+"..."location+=":#{title.text}"ifc["id"]&&!title.nil?@log.add("Style",nil,"#{location}: subclause is only child")endenddefisosubgroup_validate(root)root.xpath("//technical-committee/@type").eachdo|t|unless%w{TC PC JTC JPC}.include?t.text@log.add("Document Attributes",nil,"invalid technical committee type #{t}")endendroot.xpath("//subcommittee/@type").eachdo|t|unless%w{SC JSC}.include?t.text@log.add("Document Attributes",nil,"invalid subcommittee type #{t}")endendend# ISO/IEC DIR 2, 15.5.3defsee_xrefs_validate(root)root.xpath("//xref").eachdo|t|# does not deal with preceding text marked uppreceding=t.at("./preceding-sibling::text()[last()]")nextunless!preceding.nil?&&/\b(see| refer to)\s*$/mi.match(preceding)(target=root.at("//*[@id = '#{t['target']}']"))||nextiftarget&.at("./ancestor-or-self::*[@obligation = 'normative']")@log.add("Style",t,"'see #{t['target']}' is pointing to a normative section")endendend# ISO/IEC DIR 2, 15.5.3defsee_erefs_validate(root)root.xpath("//eref").eachdo|t|preceding=t.at("./preceding-sibling::text()[last()]")nextunless!preceding.nil?&&/\b(see|refer to)\s*$/mi.match(preceding)unlesstarget=root.at("//*[@id = '#{t['bibitemid']}']")@log.add("Bibliography",t,"'#{t} is not pointing to a real reference")nextendiftarget.at("./ancestor::references[@normative = 'true']")@log.add("Style",t,"'see #{t}' is pointing to a normative reference")endendend# ISO/IEC DIR 2, 10.4deflocality_erefs_validate(root)root.xpath("//eref[descendant::locality]").eachdo|t|if/^(ISO|IEC)/.matcht["citeas"]unless/:[ ]?(\d+{4}|–)$/.matcht["citeas"]@log.add("Style",t,"undated reference #{t['citeas']} should not contain "\"specific elements")endendendenddeftermdef_warn(text,re,t,term,msg)re.match(text)&&@log.add("Style",t,"#{term}: #{msg}")end# ISO/IEC DIR 2, 16.5.6deftermdef_style(xmldoc)xmldoc.xpath("//term").eachdo|t|para=t.at("./definition")||returnterm=t.at("./preferred").texttermdef_warn(para.text,/^(the|a)\b/i,t,term,"term definition starts with article")termdef_warn(para.text,/\.$/i,t,term,"term definition ends with period")endcited_term_style(xmldoc)end# ISO/IEC DIR 2, 16.5.10defcited_term_style(xmldoc)xmldoc.xpath("//term//xref").eachdo|x|nextunlessxmldoc.at("//term[@id = '#{x['target']}']")x&.previous&.text==" ("andx&.previous&.previous&.name=="em"orstyle_warning(x,"term citation not preceded with italicised term",x.parent.text)endenddefdoctype_validate(xmldoc)doctype=xmldoc&.at("//bibdata/ext/doctype")&.text%w(international-standard technical-specification technical-report
publicly-available-specification international-workshop-agreement
guide amendment technical-corrigendum).include?doctypeor@log.add("Document Attributes",nil,"#{doctype} is not a recognised document type")enddefscript_validate(xmldoc)script=xmldoc&.at("//bibdata/script")&.textscript=="Latn"or@log.add("Document Attributes",nil,"#{script} is not a recognised script")enddefstage_validate(xmldoc)stage=xmldoc&.at("//bibdata/status/stage")&.text%w(00 10 20 30 40 50 60 90 95).include?stageor@log.add("Document Attributes",nil,"#{stage} is not a recognised stage")enddefsubstage_validate(xmldoc)substage=xmldoc&.at("//bibdata/status/substage")&.textorreturn%w(00 20 60 90 92 93 98 99).include?substageor@log.add("Document Attributes",nil,"#{substage} is not a recognised substage")enddefiteration_validate(xmldoc)iteration=xmldoc&.at("//bibdata/status/iteration")&.textorreturn/^\d+/.match(iteration)or@log.add("Document Attributes",nil,"#{iteration} is not a recognised iteration")enddefbibdata_validate(doc)doctype_validate(doc)script_validate(doc)stage_validate(doc)substage_validate(doc)iteration_validate(doc)enddefcontent_validate(doc)supertitle_validate(doc.root)isosubgroup_validate(doc.root)onlychild_clause_validate(doc.root)termdef_style(doc.root)iev_validate(doc.root)see_xrefs_validate(doc.root)see_erefs_validate(doc.root)locality_erefs_validate(doc.root)bibdata_validate(doc.root)bibitem_validate(doc.root)enddefbibitem_validate(xmldoc)xmldoc.xpath("//bibitem[date/on = '–']").eachdo|b|b.at("./note[@type = 'ISO DATE']")or@log.add("Style",b,"Reference #{b&.at("./@id")&.text} does not have an "\"associated footnote indicating unpublished status")endenddefvalidate(doc)content_validate(doc)doctype=doc&.at("//bibdata/ext/doctype")&.textschema=casedoctypewhen"amendment","technical-corrigendum"# @amd"isostandard-amd.rng"else"isostandard.rng"endschema_validate(formattedstr_strip(doc.dup),File.join(File.dirname(__FILE__),schema))endendendend