Adopting the Metanorma toolchain for publications



The easiest way to adopt Metanorma is via Simple Adoption, which allows you to supply stylesheets and HTML files for styling.

To customise behaviour further than Simple Adoption, you need to create a custom gem:

  • Clone the correct base gem: we recommend using the metanorma-rsd gem, which has the added advantage of allowing you to use the config file.

  • Either:

    • Directly use the configuration YAML file as documented for Simple Adoption; metanorma-rsd has already renamed metanorma.yml.example to metanorma.yml; or

    • Change the root tag and namespace to a namespace specific to your organization’s document standard (XML_ROOT_TAG and XML_NAMESPACE located in …​/lib/asciidoctor/{flavour}/converter.rb)

  • Change any references to rsd or RSD in the gem to your organization’s document standard.

  • Change the styling of the document outputs (located in …​/lib/isodoc/{flavour}/html).

  • Customise any code you need to inherited from the gem’s parents.


The toolchains currently available proceed in two steps:

  1. map an input markup language (currently AsciiDoc only) into Metanorma Standoc XML; and

  2. map Metanorma Standoc XML into various output formats (currently Word doc, HTML, PDF via HTML).

Running the metanorma CLI tool involves a third step, of exposing the capabilities available in the first two in a consistent format.

These two steps are represented as three separate modules, which are included in the same gem; for the Generic gem, they are Asciidoctor::Generic, Isodoc::Generic, and Metanorma::Generic.

Your adaptation of the toolchain will need to instantiate these three modules. The connection between the two first steps is taken care of in the toolchain, and metanorma explicitly invokes the two steps, feeding the XML output of the first step as input into the second. The metanorma-sample gem outputs both Word and HTML; you can choose to output only Word, or only HTML, and you can choose to generate PDF as well.

The modules involve classes which rely on inheritance from other classes; the current gems use Asciidoctor::{Standoc, ISO, Generic}::Converter, Isodoc::{Metadata, HtmlConvert, WordConvert}, and Metanorma::Processor as their base classes. This allows the standards-specific classes to be quite succinct, as most of their behaviour is inherited from other classes; but it also means that you need to be familiar with the underlying gems, in order to do most customization.

In the case of Asciidoctor::X classes, the changes you will need to make involve the intermediate XML representation of your document, which is built up through Nokogiri Builder; e.g. adding different enums, or adding new elements. The adaptations in Asciidoctor::Generic::Converter are limited (and are almost all to do with reading in properties from a config file), and most projects can take them across as is.

The customizations needed for Metanorma::Sample::Processor are minor, and involve invoking methods specific to the gem for document generation.

The customizations needed for Isodoc::Sample are more extensive. Three base classes are involved:

  • Isodoc::Metadata processes the metadata about the document stored in //bibdata. This information typically ends up in the document title page, as opposed to the document body. For that reason, metadata is extracted into a Hash, which is passed to document output (title page, Word header) via the Liquid template language. See Metadata and Predefined text for more information.

  • Isodoc::HtmlConvert converts Metanorma Standoc XML to HTML.

  • Isodoc::PDFConvert converts Metanorma Standoc XML to HTML.

  • Isodoc::WordConvert converts Metanorma Standoc XML to Word HTML; the html2doc gem then converts this to a .doc document.

The Isodoc::HtmlConvert and Isodoc::WordConvert are expected to be near-identical, since any rendering differences between the two are addressed in the HTML CSS stylesheet. The Isodoc::HtmlConvert and Isodoc::WordConvert overlap substantially, as both use variants of HTML. However there is no reason not to make substantially different rendering choices in the HTML and Word branches of the code.

Asciidoctor::Standoc customization examples

In the following snippets, the parameter node represents the current node of the AsciiDoc document, and xml represents the Nokogiri Builder node of the XML output.

  • The predefined text representation of the document’s author, publisher and copyright holder names Acme as the responsible organization.

def metadata_author(node, xml)
  xml.contributor do |c|
    c.role **{ type: "author" }
    c.organization do |a| "Acme"
  • The editorial committees are represented as a single element. (node.attr() recovers Asciidoctor document attribute values.)

def metadata_committee(node, xml)
  xml.editorialgroup do |a|
    a.committee node.attr("committee"),
      **attr_code(type: node.attr("committee-type"))
  • The document identifier concatenates the document number, the abbreviation of the document status (retrieved via IsoDoc::Generic::Metadata), and the document year.

def metadata_id(node, xml)
  docstatus = node.attr("status")
  dn = node.attr("docnumber")
  if docstatus
    abbr ="en", "Latn", {}).
    dn = "#{dn}(#{abbr})" unless abbr.empty?
  node.attr("copyright-year") and dn += ":#{node.attr("copyright-year")}"
  xml.docidentifier dn, **{type: "acme"}
  xml.docnumber { |i| i << node.attr("docnumber") }
  • A security element is added to the document metadata, at the metadata extension point (where flavour-specific metadata is entered).

def metadata_security(node, xml)
  security = node.attr("security") || return security

def metadata_ext(node, xml)
  metadata_security(node, xml)
  • Title validation and style validation is disabled.

def title_validate(root)
  • The document type attribute is restricted to a prescribed set of options.

def doctype(node)
  d = node.attr("doctype")
  unless %w{policy-and-procedures best-practices
    supporting-document report legal directives proposal
    standard}.include? d
    warn "#{d} is not a legal document type: reverting to 'standard'"
    d = "standard"
  • Inline headers are ignored.

def sections_cleanup(x)
  x.xpath("//*[@inline-header]").each do |h|

Metanorma::Processor customization examples

  • initialize names the token by which Asciidoctor registers the standard

def initialize
  @short = :sample
  @input_format = :asciidoc
  @asciidoctor_backend = :sample
  • output_formats names the available output formats (including XML, which is inherited from the parent class)

def output_formats
    html: "html",
    doc: "doc",
    pdf: "pdf"
  • version gives the current version string for the gem

def version
  "Asciidoctor::Sample #{Asciidoctor::Sample::VERSION}"
  • input_to_isodoc is the call which converts Metanorma AsciiDoc input into Metanorma XML

def input_to_isodoc(file, filename), filename, @asciidoctor_backend)
  • output is the call which converts Metanorma XML into various nominated output formats

def output(isodoc_node, outname, format, options={})
  case format
  when :html, isodoc_node)
  when :doc, isodoc_node)
  when :pdf, isodoc_node)

Isodoc::Standoc customization examples

In Metadata-processing code:

  • Restrict author processing to the editorial committee: do not process any other contributors, including persons as authors:

def author(isoxml, _out)
  tc ="//bibdata/ext/editorialgroup/committee"))
  set(:tc, tc.text) if tc
  • Create abbreviations for the recognised statuses of documents:

def status_abbr(status)
  case status
  when "working-draft" then "wd"
  when "committee-draft" then "cd"
  when "draft-standard" then "d"
  • Add the month/year revision date to the metadata associated with the document version:

def version(isoxml, _out)
  revdate = get[:revdate]
  set(:revdate_monthyear, monthyr(revdate))
  • Add a security element to metadata:

def security(isoxml, _out)
  security ="//bibdata/ext/security")) || return
  set(:security, security.text)

In code common to all of HTML, PDF and Word (BaseConvert module):

  • Add the security element to the extraction of metadata:

def info(isoxml, out) isoxml, out
  • Add two line breaks between the annex label and the annex title:

def annex_name(annex, name, div)
  div.h1 **{ class: "Annex" } do |t|
    t << "#{get_anchors[annex['id']][:label]} "
    t.b do |b|
      name&.children&.each { |c2| parse(c2, b) }
  • Change the default label for annexes from "Annex" to "Appendix".

def i18n_init(lang, script)
  @annex_lbl = "Appendix"
  • Simplify the processing of predefined text for terms and definitions: do not add a trailing predefined text section. applicable whether or no the terms and definitions section is empty:

def term_defs_boilerplate(div, source, term, preface)
  if source.empty? && term.nil?
    div << @no_terms_boilerplate
    div << term_defs_boilerplate_cont(source, term)
  • Render term headings in the same paragraph as the term heading number

def term_cleanup(docxml)
  docxml.xpath("//p[@class = 'Terms']").each do |d|
    h2 ="./preceding-sibling::*[@class = 'TermNum'][1]")

Initialise the HTML Converter:

  • Set the default fonts for the HTML rendering, which will be used to populate the HTML CSS stylesheet.

def default_fonts(options)
    bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Overpass",sans-serif'),
    headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Overpass",sans-serif'),
    monospacefont: '"Space Mono",monospace'
  • Set the default HTML assets for the HTML rendering.

def default_file_locations(_options)
    htmlstylesheet: html_doc_path("htmlstyle.scss"),
    htmlcoverpage: html_doc_path("html_sample_titlepage.html"),
    htmlintropage: html_doc_path("html_sample_intro.html"),
    scripts: html_doc_path("scripts.html"),
  • Access Google Fonts for the HTML rendering.

def googlefonts
<link href=",300i,400,400i,600,600i|Space+Mono:400,700" rel="stylesheet">
<link href=",300i,600,900" rel="stylesheet">
  • Set distinct default fonts and HTML assets for the Word rendering.

class WordConvert < IsoDoc::WordConvert
  def default_fonts(options)
      bodyfont: (options[:script] == "Hans" ? '"SimSun",serif' : '"Arial",sans-serif'),
      headerfont: (options[:script] == "Hans" ? '"SimHei",sans-serif' : '"Arial",sans-serif'),
      monospacefont: '"Courier New",monospace'

  def default_file_locations(_options)
      wordstylesheet: html_doc_path("wordstyle.scss"),
      standardstylesheet: html_doc_path("sample.scss"),
      header: html_doc_path("header.html"),
      wordcoverpage: html_doc_path("word_sample_titlepage.html"),
      wordintropage: html_doc_path("word_sample_intro.html"),
      ulstyle: "l3",
      olstyle: "l2",