Independent Submission R. Gieben Request for Comments: 7328 Google Category: Informational August 2014 ISSN: 2070-1721
Writing I-Ds and RFCs Using Pandoc and a Bit of XML
This document presents a technique for using a Markdown syntax variant, called Pandoc, and a bit of XML (as defined in RFC 2629) as a source format for documents that are Internet-Drafts (I-Ds) or RFCs.
The goal of this technique (which is called Pandoc2rfc) is to let an author of an I-D focus on the main body of text without being distracted too much by XML tags; however, it does not alleviate the need to typeset some files in XML.
Status of This Memo
This document is not an Internet Standards Track specification; it is published for informational purposes.
This is a contribution to the RFC Series, independently of any other RFC stream. The RFC Editor has chosen to publish this document at its discretion and makes no statement about its value for implementation or deployment. Documents approved for publication by the RFC Editor are not a candidate for any level of Internet Standard; see Section 2 of RFC 5741.
Copyright (c) 2014 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document.
This document presents a technique for using a Markdown [Markdown] syntax variant, called Pandoc [Pandoc], and a bit of XML [RFC2629] as a source format for documents that are Internet-Drafts (I-Ds) or RFCs.
The goal of this technique is to let an author of an I-D focus on the main body of text without being distracted too much by XML tags; however, it does not alleviate the need to typeset some files in XML.
Pandoc is a format that is almost plain text and therefore particularly well suited for editing RFC-like documents. The syntax itself is a superset of the syntax championed by Markdown.
Pandoc's syntax is easy to learn and write, and it can be translated to numerous output formats, including, but not limited to: HTML, EPUB, (plain) Markdown, and DocBook XML.
Pandoc2rfc allows authors to write in Pandoc syntax that is then transformed to XML and given to xml2rfc. The conversions are, in a way, amusing, as we start off with (almost) plain text, use elaborate XML, and end up with plain text again.
Gieben Informational [Page 2]
RFC 7328 Pandoc2rfc August 2014
+-------------------+ pandoc +---------+ | ALMOST PLAIN TEXT | ------> | DOCBOOK | +-------------------+ 1 +---------+ | | non-existent | 2 | xsltproc faster way | | v v +------------+ xml2rfc +---------+ | PLAIN TEXT | <-------- | XML | +------------+ 3 +---------+
Figure 1: Attempt to justify Pandoc2rfc
The output of step 2 in Figure 1 is XML that is suitable for inclusion in either the "middle" or "back" section of an RFC.
Even though Pandoc2rfc abstracts away a lot of XML details, there are still places left where XML files needs to be edited -- most notably in the "front" section of an RFC.
The simplest way to start using Pandoc2rfc is to create a template XML file and include the appropriate XML for the "front", "middle", and "back" section:
Gieben Informational [Page 3]
RFC 7328 Pandoc2rfc August 2014
<?xml version='1.0' ?> <!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [ <!ENTITY pandocAbstract PUBLIC '' 'abstract.xml'> <!ENTITY pandocMiddle PUBLIC '' 'middle.xml'> <!ENTITY pandocBack PUBLIC '' 'back.xml'> <!ENTITY rfc.2629 PUBLIC '' 'reference.RFC.2629.xml'> ]>
Assuming the setup from Section 2, we can build an I-D as follows (in a Unix-like environment):
for i in abstract middle back; do pandoc -st docbook $i.mkd | xsltproc --nonet transform.xsl - > $i.xml done
xml2rfc template.xml -f draft.txt --text # create text output xml2rfc template.xml -f draft.html --html # or create HTML output xml2rfc template.xml -f draft.xml --exp # or create XML output
Figure 3: Building an I-D
Note that the output file names (abstract.xml, middle.xml, and back.xml) must match the names used as the XML entities in "template.xml". (See the "!ENTITY" lines in Figure 2.) The Pandoc2rfc source repository includes a shell script that incorporates the above transformations. Creating a "draft.txt" or a "draft.xml" can be done with "pandoc2rfc *.mkd" and "pandoc2rfc -X *.mkd", respectively.
With Pandoc2rfc, an author of an I-D can get a long way without needing to input XML, but it is not a 100% solution. The initial setup and the reference library still force the author to edit XML files. The metadata feature (Pandoc's "Title Block" extension) is not used in Pandoc2rfc. This information (authors, date, keyword, and URLs) should be put in the "template.xml".
Some other quirks:
o Comments are supported via HTML comments in the Pandoc source files.
o Citations are supported via cross-references; the citation syntax of Pandoc is not used.
o Authors still need to know how to deal with possible errors from xml2rfc.
Indent the paragraph with 4 spaces as mandated by Pandoc. If you add an inline footnote _directly_ after the figure, the artwork gets a title attribute with the text of that footnote (and a possible anchor).
A table can be entered by using Pandoc's table syntax. You can choose multiple styles as input, but they all are converted to the same style table (plain "<texttable>") in xml2rfc. If you add an inline footnote _directly_ after the table, it will get a title attribute with the text of that footnote (and a possible anchor). The built-in syntax of Pandoc to create a caption with "Table:" should not be used.
Pandoc provides a syntax that can be used for references. Its syntax is repeated in this paragraph. Any reference like "[Click here](URI)" is an external reference. An internal reference (i.e., "see Section X") is typeset with "(#localid)".
Gieben Informational [Page 7]
RFC 7328 Pandoc2rfc August 2014
For referencing RFCs (and other documents), you will need to add the reference source in the template as an external XML entity; Figure 2 provides an example. After that, you can use the following syntax to create a citation: "(#RFC2629)" to cite RFC 2629.
There is no direct support for referencing tables, figures, and artworks, but Pandoc2rfc employs the following "hack". If an inline footnote is added after the figure or table, the text of the footnote is used as the title. The first word up until a double colon "::" will be used as the anchor. If a figure has an anchor, it will be centered on the page.
Figure 2, for instance, is followed by this inline footnote: