Sha256: facc5e43bbe07281065ad8f5552b5567b78a43b76c6a3cee097b549cdc08fcd7

Contents?: true

Size: 1.95 KB

Versions: 2

Compression:

Stored size: 1.95 KB

Contents

require_relative "./terms"
require_relative "./blocks"
require_relative "./metadata"
require_relative "./front"
require_relative "./table"
require_relative "./inline"
require_relative "./reqt"
require_relative "./cleanup"
require_relative "./footnotes"
require_relative "./references"
require_relative "./section"

module IsoDoc::Ietf
  class RfcConvert < ::IsoDoc::Convert
    def convert1(docxml, filename, dir)
      anchor_names docxml
      info docxml, nil
      xml = noko do |xml|
        xml.rfc **attr_code(rfc_attributes(docxml)) do |html|
          make_link(html, docxml)
          make_front(html, docxml)
          make_middle(html, docxml)
          make_back(html, docxml)
        end
      end.join("\n").sub(/<!DOCTYPE[^>]+>\n/, "")
          set_pis(docxml, Nokogiri::XML(xml))
    end

    def metadata_init(lang, script, labels)
      @meta = Metadata.new(lang, script, labels)
    end

    def extract_delims(text)
      @openmathdelim = "$$"
      @closemathdelim = "$$"
      while %r{#{Regexp.escape(@openmathdelim)}}m.match(text) ||
          %r{#{Regexp.escape(@closemathdelim)}}m.match(text)
        @openmathdelim += "$"
        @closemathdelim += "$"
      end
      [@openmathdelim, @closemathdelim]
    end

    def error_parse(node, out)
      case node.name
      when "bcp14" then bcp14_parse(node, out)
      else
        text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
        out.t { |p| p << text }
      end
    end

    def postprocess(result, filename, dir)
      result = from_xhtml(cleanup(to_xhtml(result))).sub(/<!DOCTYPE[^>]+>\n/, "").
        sub(/(<rfc[^<]+? )lang="[^"]+"/, "\\1")
      File.open("#{filename}.rfc.xml", "w:UTF-8") { |f| f.write(result) }
      @files_to_delete.each { |f| FileUtils.rm_rf f }
    end

    def init_file(filename, debug)
      filename = filename.sub(/\.rfc\.xml$/, ".rfc")
      super
    end

    def initialize(options)
      super
      @xinclude = options[:use_xinclude] == "true"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metanorma-ietf-2.0.9 lib/isodoc/ietf/rfc_convert.rb
metanorma-ietf-2.0.8 lib/isodoc/ietf/rfc_convert.rb