Sha256: 70e40cac61c63092f8b488682646056aafd5916f580e20cc8deac26e97703438

Contents?: true

Size: 1.96 KB

Versions: 10

Compression:

Stored size: 1.96 KB

Contents

require "asciidoctor"
require "asciidoctor/mpfd"
require "asciidoctor/standoc/converter"
require "isodoc/mpfd/html_convert"
require "isodoc/mpfd/word_convert"

module Asciidoctor
  module Mpfd

    # A {Converter} implementation that generates MPFD output, and a document
    # schema encapsulation of the document for validation
    #
    class Converter < Standoc::Converter

      def sections_cleanup(x)
        super
        x.xpath("//*[@inline-header]").each do |h|
          h.delete("inline-header")
        end
        x.xpath("//*[@guidance]").each do |h|
          c = h.previous_element || next
          c.add_child h.remove
        end
      end

      def sectiontype_streamline(ret)
        case ret
        when "glossary" then "terms and definitions"
        else
          super
        end
      end

      def term_def_title(_toplevel, node)
        return node.title
      end

      def move_sections_into_preface(x, preface)
        foreword = x.at("//foreword")
        preface.add_child foreword.remove if foreword
        introduction = x.at("//introduction")
        preface.add_child introduction.remove if introduction
        terms = x.at("//sections/clause[descendant::terms]") || x.at("//terms")
        preface.add_child terms.remove if terms
        move_clauses_into_preface(x, preface)
        acknowledgements = x.at("//acknowledgements")
        preface.add_child acknowledgements.remove if acknowledgements
      end

      def make_preface(x, s)
        if x.at("//foreword | //introduction | //terms | //acknowledgements |"\
            "//abstract[not(ancestor::bibitem)] | //clause[@preface]")
          preface = s.add_previous_sibling("<preface/>").first
          move_sections_into_preface(x, preface)
          make_abstract(x, s)
        end
      end

      def clause_parse(attrs, xml, node)
        attrs[:guidance] = true if node.role == "guidance"
        attrs[:container] = true if node.role == "container"
        super
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
metanorma-mpfd-0.3.22 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.21 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.20 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.19 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.18 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.17 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.16 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.15 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.14 lib/asciidoctor/mpfd/section.rb
metanorma-mpfd-0.3.13 lib/asciidoctor/mpfd/section.rb