= AsciiCSD: Metanorma processor for CSD standards

image:https://img.shields.io/gem/v/asciidoctor-csd.svg["Gem Version", link="https://rubygems.org/gems/asciidoctor-csd"]
image:https://img.shields.io/travis/riboseinc/asciidoctor-csd/master.svg["Build Status", link="https://travis-ci.org/riboseinc/asciidoctor-csd"]
image:https://codeclimate.com/github/riboseinc/asciidoctor-csd/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/riboseinc/asciidoctor-csd"]

_Formerly known as_ `asciidoctor-csd`.

WARNING: This gem is still under development.

== Functionality

This gem processes http://asciidoctor.org/[Asciidoctor] documents following
a template for generating CSD International Standards.

The gem currently inherits from the https://github.com/riboseinc/metanorma-iso
gem, and aligns closely to it. Refer to the ISO gem
for guidance, including https://github.com/riboseinc/metanorma-iso/wiki/Guidance-for-authoring

The following outputs are generated.

* (Optional) An HTML preview generated directly from the Asciidoctor document,
using native Asciidoc formatting. 
** http://asciimath.org[AsciiMathML] is to be used for mathematical formatting.
The gem uses the https://github.com/asciidoctor/asciimath[Ruby AsciiMath parser],
which is syntactically stricter than the common MathJax processor;
if you do not get expected results, try bracketting terms your in AsciiMathML
expressions.
* an XML representation of the document, intended as a document model for CSD
International Standards. 
* The XML representation is processed in turn to generate the following outputs
as end deliverable CSD standard drafts.
** HTML
** PDF

This AsciiDoc syntax for writing CSD standards is hereby named "AsciiCSD".

== Usage

The preferred way to invoke this gem is via the `metanorma` script:

[source,console]
----
$ metanorma --type csd a.adoc                   # output HTML and PDF
$ metanorma --type csd --extensions html a.adoc # output just HTML
$ metanorma --type csd --extensions pdf a.adoc  # output just PDF
$ metanorma --type csd --extensions xml a.adoc  # output CSD XML
----

The gem translates the document into CSD XML format, and then
validates its output against the CSD XML document model; errors are
reported to console against the XML, and are intended for users to
check that they have provided all necessary components of the
document.

The gem then converts the XML into HTML and PDF.

The gem can also be invoked directly within asciidoctor, though this is deprecated:

[source,console]
----
$ asciidoctor -b csd -r 'metanorma-csd' a.adoc  
----

=== Installation

If you are using a Mac, the https://github.com/riboseinc/metanorma-macos-setup
repository has instructions on setting up your machine to run Metanorma
scripts such as this one. You need only run the following in a Terminal console:

[source,console]
----
$ bash <(curl -s https://raw.githubusercontent.com/riboseinc/metanorma-macos-setup/master/metanorma-setup)
$ gem install metanorma-csd
----

=== PDF output

PDF output is generated by printing the HTML output as PDF. This is done
within the gem, using 
https://developers.google.com/web/updates/2017/04/headless-chrome[Headless Chrome],
via the https://github.com/GoogleChrome/puppeteer[Puppeteer] Node library.

To get the PDF output working, do the following:

* Install Node, with at least version 7.6.0: https://nodejs.org/en/download/,
https://nodejs.org/en/download/package-manager/ . (For Mac, `brew install node`)
* Install npm: https://docs.npmjs.com/getting-started/installing-node
* Install puppeteer: `npm install -g --save --save-exact puppeteer`

The https://github.com/riboseinc/metanorma-macos-setup script includes Puppeteer
installation.

== Approach

=== Document model

The CSD Standard Document model is an instance of the
https://github.com/riboseinc/isodoc-models[StandardDocument model].

The CSD format ("CSD XML") intends to introduce rigour into the CSD
standards authoring process, and is prescribed in a separate document.

=== Asciidoctor

Asciidoctor has been selected as the authoring tool to generate the document
model representation of CSD standards. It is a document formatting tool like
Markdown and DocBook, which combines the relative ease of use of the former
(using relatively lightweight markup), and the rigour and expressively of the
latter (it has a well-defined syntax, and was in fact initially developed as a
DocBook document authoring tool). Asciidoctor has built-in capability to output
Text, DocBook and HTML; so it can be used to preview the file as it is being
authored.

Generating documents via a document model substantially automated formatting
associated with the document, including automating numbering of headings, figures,
tables etc, and automatically generating references and citations.

== Document Attributes

The gem relies on Asciidoctor document attributes to provide necessary
metadata about the document. These include:

`:edition:`:: The document edition

`:revdate:`:: The date the document was last updated

`:copyright-year:`:: The year which will be claimed as when the copyright for
the document was issued

`:title:`:: The main component of the English title of the document
(mandatory). (The first line of the AsciiDoc document, which contains the title
introduced with `=`, is ignored)

`:doctype:`:: The document type (see CSD deliverables: The different types of
CSD publications) (mandatory). The permitted types are:
+
--
code:: Code Artifact
presentation:: Presentation
proposal:: Proposal; includes IETF DRAFT
standard:: Recommendation; includes IETF RFC
report:: report
--

`:status:``:: The document status. The permitted types are: `proposal`,
`working-draft`, `committee-draft`, `draft-standard`, `final-draft`,
`published`, `withdrawn`.

`:technical-committee:`:: The name of the relevant CSD technical committee
(mandatory)

`:language:` :: The language of the document (only `en` for now)  (mandatory)


The attribute `:draft:`, if present, includes review notes in the XML output;
these are otherwise suppressed.

== AsciiCSD features not also present in AsciiISO

* `+[keyword]#...#+`: encodes keywords, such as "MUST", "MUST NOT". (Encoded as
`<span class="keyword">...</span>`.

== Data Models

The CSD Standard Document format is an instance of the
https://github.com/riboseinc/isodoc-models[StandardDocument model]. Details of
this general model can be found on its page. Details of the CSD modifications
to this general model can be found on the https://github.com/riboseinc/csd[CSD model]
repository.

== Examples

* link:spec/examples/rfc6350.adoc[] is an AsciiCSD version of https://tools.ietf.org/html/rfc6350[RFC 6350].
* link:spec/examples/rfc6350.html[] is an HTML file generated from the AsciiCSD.
* link:spec/examples/rfc6350.doc[] is a Word document generated from the AsciiCSD.