require "date" require "nokogiri" require "htmlentities" require "json" require "pathname" require "open-uri" require "pp" require "set" module Asciidoctor module Rfc::Common module Base def convert(node, transform = nil, opts = {}) transform ||= node.node_name opts.empty? ? (send transform, node) : (send transform, node, opts) end def document_ns_attributes(_doc) # ' xmlns="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its"' nil end def content(node) node.content end def skip(node, name = nil) warn %(asciidoctor: WARNING (#{current_location(node)}): converter missing for #{name || node.node_name} node in RFC backend) nil end # Syntax: # = Title # Author # :HEADER # # ABSTRACT # # NOTE: note # # @note (boilerplate is ignored) def preamble(node) result = [] # NOTE: *list is V3, verse is V2, paragraph is both abstractable_contexts = %i{paragraph dlist olist ulist verse open} abstract_blocks = node.blocks.take_while do |block| abstractable_contexts.include? block.context end remainder_blocks = node.blocks[abstract_blocks.length..-1] result << noko do |xml| if abstract_blocks.any? xml.abstract do |xml_abstract| xml_abstract << abstract_blocks.map(&:render).flatten.join("\n") end end xml << remainder_blocks.map(&:render).flatten.join("\n") end result << "" result end IETF_AREAS = ["art", "Applications and Real-Time", "gen", "General", "int", "Internet", "ops", "Operations and Management", "rtg", "Routing", "sec", "Security", "tsv", "Transport"].freeze # Syntax: # = Title # Author # :area x, y def area(node, xml) node.attr("area")&.split(/, ?/)&.each do |ar| if ar =~ / Area$/i warn %(asciidoctor: WARNING (#{current_location(node)}): stripping suffix "Area" from area #{ar}) ar = ar.gsub(/ Area$/i, "") end warn %(asciidoctor: WARNING (#{current_location(node)}): unrecognised area #{ar}) unless IETF_AREAS.include?(ar) xml.area { |a| a << ar } end end # Syntax: # = Title # Author # :workgroup x, y def workgroup(node, xml) workgroups = cache_workgroup(node) node.attr("workgroup")&.split(/, ?/)&.each do |wg| if wg =~ / (Working Group)$/i warn %(asciidoctor: WARNING (#{current_location(node)}): suffix "Working Group" will be stripped in published RFC from #{wg}) wg_norm = wg.gsub(/ Working Group$/i, "") end if wg =~ / (Research Group)$/i warn %(asciidoctor: WARNING (#{current_location(node)}): suffix "Research Group" will be stripped from working group #{wg}) wg_norm = wg.gsub(/ Research Group$/i, "") end warn %(asciidoctor: WARNING (#{current_location(node)}): unrecognised working group #{wg}) unless workgroups.include?(wg_norm) xml.workgroup { |w| w << wg } end end # Syntax: # = Title # Author # :keyword x, y def keyword(node, xml) node.attr("keyword")&.split(/, ?/)&.each do |kw| xml.keyword { |k| k << kw } end end def paragraph1(node) result = [] result1 = node.content if result1 =~ /^(|
|
    |