module Asciidoctor module Ietf class Converter < ::Asciidoctor::Standoc::Converter def content_validate(doc) super image_validate(doc) workgroup_validate(doc) end def image_validate(doc) doc.xpath("//image").each do |i| next if i["mimetype"] == "image/svg+xml" warn "image #{i['src'][0, 40]} is not SVG!" end end def workgroup_validate(doc) return if @workgroups.empty? doc.xpath("//bibdata/ext/editorialgroup/workgroup").each do |wg| wg_norm = wg.text.sub(/ (Working|Research) Group$/, "") next if @workgroups.include?(wg_norm) warn "IETF: unrecognised working group #{wg.text}" end end def validate(doc) content_validate(doc) schema_validate(formattedstr_strip(doc.dup), File.join(File.dirname(__FILE__), "ietf.rng")) end def open_wg_cache(node) wgcache_name = "#{Dir.home}/.metanorma-ietf-workgroup-cache.json" node.attr("flush-caches") == "true" and FileUtils.rm wgcache_name, :force => true wg = [] if Pathname.new(wgcache_name).file? begin File.open(wgcache_name, "r") { |f| wg = JSON.parse(f.read) } rescue Exception => e STDERR.puts "Cache #{wgcache_name} is invalid, drop it" end end [wg, wgcache_name] end def cache_workgroup_ietf(wg, b) STDERR.puts "Reading workgroups from https://tools.ietf.org/wg/..." Kernel.open("https://tools.ietf.org/wg/") do |f| f.each_line do |line| line.scan(%r{