= AsciiISO: Asciidoctor processor for ISO standards image:https://img.shields.io/gem/v/asciidoctor-iso.svg["Gem Version", link="https://rubygems.org/gems/asciidoctor-iso"] image:https://img.shields.io/travis/riboseinc/asciidoctor-iso/master.svg["Build Status", link="https://travis-ci.org/riboseinc/asciidoctor-iso"] image:https://codeclimate.com/github/riboseinc/asciidoctor-iso/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/riboseinc/asciidoctor-iso"] WARNING: This gem is still under development. == Functionality This gem processes http://asciidoctor.org/[Asciidoctor] documents following a template for generating ISO International Standards. The following outputs are generated. * (Optional) An HTML preview generated directly from the Asciidoctor document, using native Asciidocot 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 ISO International Standards. * The XML representation is processed in turn to generate the following outputs as end deliverable ISO standard drafts. ** Microsoft Word output (`.doc`), following the style conventions of the https://www.iso.org/iso-templates.html[ISO Standard Microsoft Word template]. ** PDF (forthcoming) ** HTML (in development) This AsciiDoc syntax for writing ISO standards is hereby named "AsciiISO". == Usage [source,console] ---- $ asciidoctor a.adoc # HTML output of Asciidoc file $ asciidoctor -b iso -r 'asciidoctor-iso' a.adoc # ISO XML output, ---- The initial step is optional, and can be used as a preview of what the gem will do; it generates a `{filename}.html` file. When invoked within Asciidoctor, the gem translates the document into ISO XML format, and then validates its output against the ISO 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 to Micosoft Word (`{filename}.doc`), HTML (`{filename}.html`), and PDF (forthcoming). In the process of generating the Microsoft Word document, the associated https://github.com/riboseinc/isodoc[IsoDoc] gem generates temporary files: `{filename}.htm` contains the Microsoft Word-specific HTML for inclusion in that file, and the `{filename}_files` folder contains any images and headers for the Word document. === Content Warnings The gem also realises several format checks as prescribed in ISO/IEC DIR 2, and warns the user about them in the console: * Numbers with what looks like dots instead of commas for decimal points. * Groups of numbers without spacing for every three digits. (The gem attempts to ignore ISO references.) * No space before percent sign. * No bracketing of tolerance in percentage (e.g. `15 ± 7 % .`) * No recommendations, permissions or requirements (detected by keyword) in: foreword, scope, introduction, term examples and examples, notes, footnotes. * No subclauses that are the only child of a clause. (In clauses, annexes, or scopes.) * 5 levels of subclause nesting. (Never actuated, AsciiDoc only permits 4 levels of subsections.) * Non-ISO/IEC reference turning up as normative. * Term definition starts with an article, or ends with a period. * Title intro or title part appears in only one of French or English. == Approach === Document model The document model ("IsoDoc") used in document generation intends to introduce rigour into the ISO standards authoring process; the existing https://www.iso.org/iso-templates.html[Microsoft Word template from ISO] do not support such rigour down to the element level. The ISO International Standard format is prescribed in http://www.iec.ch/members_experts/refdocs/iec/isoiecdir-2%7Bed7.0%7Den.pdf[ISO/IEC DIR 2 "Principles and rules for the structure and drafting of ISO and IEC documents"], to a level amenable to an explicit document model. A formal document model would allow checking for consistency in format and content, and expedite authoring and quality control of ISO standards. Authoring standards through a more abstract formal model also permit enhanced functionality such as cross reference link checking and auto numbering of sections, figures, tables and formulas. The document model for ISO Standards specifically is derived from a more general https://github.com/riboseinc/isodoc-models[StandardDocument model]. Other ISO-like standards can also be derived from this more general model; CSD (https://github.com/riboseinc/csd, https://github.com/riboseinc/asciidoctor-csd) is one such instance. The document model for ISO Standards is still under development, but it already contains all the markup needed to render the https://www.iso.org/publication/PUB100407.html["Rice document"], the ISO's model document of an international standard, and all the structures described in ISO/IEC DIR 2. It is expressed as a link:lib/asciidoctor/iso/isostandard.rnc[Relax NG Compact schema]; actual validation occurs against its link:lib/asciidoctor/iso/isostandard.rng[full Relax NG counterpart]. === Asciidoctor Asciidoctor has been selected as the authoring tool to generate the document model representation of ISO 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 and HTML; so it can be used to preview the file as it is being authored. However the gem natively outputs HTML and Word output, so there should not be much need for this. In order to generate HTML preview output close to what is intended in the ISO standard, the Asciidoc document includes a fair amount of formatting instructions (e.g. disabling section numbering where appropriate, the titling of Appendixes as Annexes), as well as ISO boilerplate text, and predefined section headers (sections are recognised by fixed titles such as `Normative References`). Authoring ISO standards in this fashion assumes that users will be populating an Asciidoc template, and not removing needed formatting instructions. Asciidoctor has some formatting constraints because of its own document model, that users need to be aware. For example, Asciidoc has a strict division between inline and block elements, which disallows certain kinds of nesting; so a list cannot be embedded within a paragraph, it can only constitute its own paragraph (though lists themselves can be nested within each other). Asciidoctor also disallows multiple paragraphs in footnotes, http://discuss.asciidoctor.org/footnotes-with-paragraph-breaks-td4130.html[by design]. (The document model does not impose this constraint, so you could edit the generated XML to break up paragraphs within a footnote.) [[model_additions]] === Asciidoctor model additions ==== Paragraph alignment Alignment is defined as an attribute for paragraphs: [source,asciidoctor] -- [align=left] This paragraph is aligned left [align=right] This paragraph is aligned right [align=center] This paragraph is aligned center [align=justified] This paragraph is justified, which is the default -- ==== Dates on reviewer notes Reviewer notes are encoded as sidebars. A date attribute (in ISO 8601 format) and a reviewer attribute (naming the reviewer) are mandatory for reviewer notes; supplying the time as well as the date is optional. [source,asciidoctor] -- [reviewer="Nick Nicholas",date=20180125T0121] **** I do not agree with this statement. **** -- ==== Strikethrough and Small Caps The following formatting macros are used for strikethrough and small caps text: [source,asciidoctor] -- [strike]#strike through text# [smallcap]#small caps text# -- ==== Count of table header and footer rows In Asciidoc, a table can have at most one header row or footer row. In ISO, a nominal single header row is routinely broken up into multiple rows in order to accommodate units or symbols, that line up against each other, though they are displayed as merged cells with no grid between them. To address this, tables can be marked up with an optional `headerrows` attribute: [source,asciidoctor] -- [headerrows=2] |=== .2+|Defect 4+^| Maximum permissible mass fraction of defects in husked rice + stem:[w_max] | in husked rice | in milled rice (non-glutinous) | in husked parboiled rice | in milled parboiled rice | Extraneous matter: organic footnote:[Organic extraneous matter includes foreign seeds, husks, bran, parts of straw, etc.] | 1,0 | 0,5 | 1,0 | 0,5 |=== -- ==== Inline clause numbers For some clauses (notably test methods), the clause heading appears inline with the clause, instead of being separated on a different line. This is indicated in Asciidoc by the option attribute `inline-header`: [source,asciidoctor] -- [%inline-header] [[AnnexA-2-1]] ==== Sample divider, consisting of a conical sample divider -- === Features not visible in HTML preview The gem uses built-in Asciidoc formatting as much as possible, so that users can retain the ability to preview documents; for _Terms and Definitions_ clauses, which have a good deal of explicit structure, macros have been introduced for semantic markup (admitted terms, deprecated terms, etc). The default HTML output of an Asciidoc-formatted ISO document is quite close to the intended final output, with the following exceptions, and with the additional exceptions listed <> as markup introduced for ISO markup. Note that the final outputs of the conversion (Microsoft Word, PDF, HTML) do not have these exceptions, and comply with the ISO Standard specifications. * _Terms and Definitions_: each term is marked up as an unnumbered subclause, the semantic markup of alternate and other terms is not rendered visually. * _Formulas_: Asciidoctor has no provision for the automated numbering of isolated block formulas ("stem"), and does not display the number assigned a block formula in its default HTML processor—although it does provide automated numbering of examples. Formula numbering is provided in the final outputs of the conversion. * _Missing elements_: The document model does not yet include Asciidoc elements that do not appear to be relevant to ISO Standards; these will be ignored in generating ISO XML. Those elements include: ** sidebars (`aside`) (as distinct from warnings), ** ASCII art/preformatted text (`literal`) (as distinct from sourcecode listings), ** page breaks (`thematic break`). * _Markup_: Some connecting text which is used to convey markup structure is left out: in particular, `DEPRECATED` and `SOURCE` (replaced by formatting macros). * _Tables_: Table footnotes are treated like all other footnotes: they are rendered at the bottom of the document, rather than the bottom of the table, and they are not numbered separately. * _Cross-references_: Footnoted cross-references are indicated with the reference text `fn` in isolation, or `fn:` as a prefix to the reference text. The default HTML processor leaves these as is: if no reference text is given, only `fn` will be displayed (though it will still hyperlink to the right reference). * _References_: The convention for references is that ISO documents are cited without brackets by ISO number, and optionally year, whether they are normative or in the bibliography (e.g. `ISO 20483:2013`); while all other references are cited by bracketed number in the bibliography (e.g. `[1]`). The default HTML processor treats all references the same, and will bracket them (e.g. `[ISO 20483:2013]`). For the same reason, ISO references listed in the bibliography will be listed under an ISO reference, rather than a bracketed number. * _References_: References are rendered cited throughout, since they are automated. For that reason, if reference is to be made to both an undated and a dated version of an ISO reference, these need to be explicitly listed as separate references. (This is not done in the Rice model document, which lists ISO 6646, but under _Terms and Definitions_ cites the dated ISO 6646:2011. * _References_: ISO references that are undated but published have their date indicated under the ISO standards format in an explanatory footnote. Because of constraints introduced by Asciidoctor, that explanation is instead given in square brackets in Asciidoc format. * _Annexes_: Subheadings cannot preserve subsection numbering, while also appearing inline with their text (e.g. Rice document, Annex B.2): they appear as headings in separate lines. * _Annexes_: Cross-references to Annex subclauses are automatically prefixed with `Clause` rather than `Annex` or nothing. * _Metadata_: Document metadata such as document numbers, technical committees and title wording are not rendered in the default HTML output. * _Patent Notice_: Patent notices are treated and rendered as a subsection of the introduction, with an explicit subheading. * _Numbering_: The numbering of figures and tables is sequential in the default HTML processor: it does not include the Clause or Annex number. This, _Figure 1_, not _Figure A.1_. * _Notes_: There is no automatic note numbering by the default HTML processor. * _Review Notes_: The reviewer on the review note is not displayed. * _Keys_: Keys to formulas and figures are expected to be marked up as definition lists consistently, rather than as inline prose. * _Figures_: Simple figures are marked up as images, figures containing subfigures as examples. Numbering by the default HTML processor may be inconsistent. Subfigures are automatically numbered as independent figures. * _Markup_: The default HTML processor does not support CSS extensions such as small caps or strike through, though these can be marked up as CSS classes through custom macros in Asciidoctor: a custom CSS stylesheet will be needed to render them. == Document Attributes The gem relies on Asciidoctor document attributes to provide necessary metadata about the document. These include: `:docnumber:`:: The ISO document number (mandatory) `:tc-docnumber:`:: The document number assigned by the Technical committee `:partnumber:`:: The ISO document part number `:edition:`:: The document edition `:revdate:`:: The date the document was last updated `:draft:`:: The document draft (used in addition to document stage, for multiple iterations: expected format _X.Y_) `:copyright-year:`:: The year which will be claimed as when the copyright for the document was issued `:title-intro-en:`:: The introductory component of the English title of the document `:title-main-en:`:: 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) `:title-part-en:`:: The English title of the document part `:title-intro-fr:`:: The introductory component of the French title of the document. (This document template presupposes authoring in English; a different template will be needed for French, including French titles of document components such as annexes.) `:title-main-fr:`:: The main component of the French title of the document (mandatory). `:title-part-fr:`:: The French title of the document part `:doctype:`:: The document type (see https://www.iso.org/deliverables-all.html[ISO deliverables: The different types of ISO publications] ) (mandatory). The permitted types are: `international-standard, technical-specification, technical-report, publicly-available-specification, international-workshop-agreement, guide`. `:docstage:`:: The stage code for the document status (see https://www.iso.org/stage-codes.html[International harmonized stage codes]) `:docsubstage:`:: The substage code for the document status (see https://www.iso.org/stage-codes.html[International harmonized stage codes]) `:secretariat:`:: The national body acting as the secretariat for the document in the deafting stage `:technical-committee-number:`:: The number of the relevant ISO technical committee `:technical-committee:`:: The name of the relevant ISO technical committee (mandatory) `:subcommittee-number:`:: The number of the relevant ISO subcommittee `:subcommittee:`:: The name of the relevant ISO subcommittee `:workgroup-number:`:: The number of the relevant ISO workgroup `:workgroup:`:: The name of the relevant ISO workgroup `:language:` :: The language of the document (`en` or `fr`) (mandatory) The attribute `:draft:`, if present, includes review notes in the XML output; these are otherwise suppressed. == Data Models The IsoDoc data model (IsoStandardDocument) is instantiated from the https://github.com/riboseinc/isodoc-models[StandardDocument model]. For details please visit that page. == Code Structure The gem invokes the following other gems as a division of labour. * This gem generates the IsoDoc XML proper * https://github.com/riboseinc/isodoc renders IsoDoc XML into HTML * https://github.com/riboseinc/html2doc converts HTML into Microsoft Word * https://github.com/riboseinc/isodoc-models derives the ISO Standard grammar used for validation from the generic IsoDoc grammar == Examples The gem has been tested to date against the https://www.iso.org/publication/PUB100407.html["Rice document"], the ISO's model document of an international standard. This repository includes: * the link:spec/examples/rice.adoc[AsciiISO version of the Rice document]. * the link:spec/examples/rice.preview.html[AsciiISO rendering of the Rice document as an HTML preview] (native Asciidoc rendering) * the link:spec/examples/rice.xml[ISO XML rendering of the Rice document]. * the link:spec/examples/rice.doc[Word .doc rendering of the Rice document]. * the link:spec/examples/rice.html[HTML rendering of the Rice document].