RFC Beautification Working Group R. Gieben Internet-Draft Google Intended status: Informational April 10, 2013 Expires: October 12, 2013 Writing I-Ds and RFCs using Pandoc draft-gieben-pandoc2rfc-01 Abstract This document presents a technique for using a Markdown syntax variant, called Pandoc, as a source format for documents in the Internet-Drafts (I-Ds) and Request for Comments (RFC) series. Status of This Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at http://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on October 12, 2013. Copyright Notice Copyright (c) 2013 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. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Table of Contents Gieben Expires October 12, 2013 [Page 1] Internet-Draft Pandoc2rfc April 2013 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 2. Pandoc to RFC . . . . . . . . . . . . . . . . . . . . . . . . 2 2.1. Dependencies . . . . . . . . . . . . . . . . . . . . . . 4 3. Building an Internet-Draft . . . . . . . . . . . . . . . . . 4 4. Supported Features . . . . . . . . . . . . . . . . . . . . . 5 5. Unsupported Features . . . . . . . . . . . . . . . . . . . . 6 6. Pandoc Style . . . . . . . . . . . . . . . . . . . . . . . . 6 6.1. Figure/Artwork . . . . . . . . . . . . . . . . . . . . . 6 6.2. Tables . . . . . . . . . . . . . . . . . . . . . . . . . 6 6.3. References . . . . . . . . . . . . . . . . . . . . . . . 7 6.4. Indexes . . . . . . . . . . . . . . . . . . . . . . . . . 7 7. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 8 8. Security Considerations . . . . . . . . . . . . . . . . . . . 8 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 8 10. Normative References . . . . . . . . . . . . . . . . . . . . 8 Appendix A. Changelog . . . . . . . . . . . . . . . . . . . . . 8 A.1. -00 . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 A.2. -01 . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Appendix B. Cheat Sheet . . . . . . . . . . . . . . . . . . . . 9 Appendix C. XSLT . . . . . . . . . . . . . . . . . . . . . . . . 9 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 25 1. Introduction This document presents a technique for using Pandoc syntax as a source format for documents in the Internet-Drafts (I-Ds) and Request for Comments (RFC) series. Pandoc [Pandoc] is an "almost plain text" format and therefor particularly well suited for editing RFC-like documents. The syntax itself is a superset of the syntax championed by Markdown [Markdown]. Pandoc2rfc generates XML compatible with [RFC2629]. 2. Pandoc to RFC During the last few years people have been developing markup languages that are very easy to remember and type. These languages have become known as "almost plain text"-markup languages. One of the first was the Markdown ([Markdown]) syntax. One that was developed later and incorporates Markdown syntax and a number of extensions is Pandoc ([Pandoc]). The power of Pandoc comes from the fact that 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 (the simple) Pandoc syntax which is then transformed to XML and given to xml2rfc. The Gieben Expires October 12, 2013 [Page 2] Internet-Draft Pandoc2rfc April 2013 conversions are, in some way amusing, as we start off with (almost) plain text, use elaborate XML and end up with plain text again. +-------------------+ pandoc +---------+ | ALMOST PLAIN TEXT | ------> | DOCBOOK | +-------------------+ +---------+ | | non-existent | | xsltproc faster way | | v v +------------+ xml2rfc +---------+ | PLAIN TEXT | <-------- | XML | +------------+ +---------+ Attempt to justify Pandoc2rfc. Figure 1 The XML generated (the output after the "xsltproc" step in Figure 1) 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 a few places left where some XML needs to be edited. Most notably in the "front" section of an RFC. The simplest way to start is to create a template XML file and include the appropriate XML for this "front" section: ]> Writing I-Ds and RFCs using Pandoc &pandocMiddle; &rfc.2629; &pandocBack; Gieben Expires October 12, 2013 [Page 3] Internet-Draft Pandoc2rfc April 2013 A very minimal template.xml. Figure 2 In this case you need to edit three documents: 1. "middle.txt" - contains the main body of text; 2. "back.txt" - holds appendices; 3. this "template.xml" - probably a fairly static file, among other things, it holds the authors and the references. The up to date source code for Pandoc2rfc can be found at [Pandoc2rfc], this includes the stylesheet "transform.xsl" used for the transformation. 2.1. Dependencies Pandoc2rfc needs "xsltproc" [XSLT] and "pandoc" [Pandoc] to be installed. The conversion to xml2rfc XML is done with a stylesheet based on XSLT version 1.0 [W3C.REC-xslt-19991116]. See Figure 4 in Appendix C for the contents of that stylesheet. When using the template from Figure 2 xml2rfc version 2 must be used. 3. Building an Internet-Draft Assuming the setup from Section 2, we can build an I-D as follows (in a Unix-like environment): pandoc -st docbook middle.txt | xsltproc --nonet transform.xsl - \ > middle.xml pandoc -st docbook back.txt | xsltproc --nonet transform.xsl - \ > back.xml # Create text output xml2rfc template.xml -f draft.txt --text # ... or create HTML output xml2rfc template.xml -f draft.html --html # ... or create (self-contained) XML output xml2rfc template.xml -f draft.xml --exp Gieben Expires October 12, 2013 [Page 4] Internet-Draft Pandoc2rfc April 2013 Building an I-D with Pandoc2rfc. Figure 3 Note that the output file names ("middle.xml" and "back.xml") must match the names used as the XML entities in "template.xml". 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 *.txt" and "pandoc2rfc -X *.txt" respectively. 4. Supported Features Almost everything xml2rfc can do is supported, see Table 1 in Appendix B for a "cheat sheet". o Sections with an anchor and title attributes o Lists * style="symbols", use "* " for each item; * style="numbers", use digits: "1. " for each item; * style="empty", use "#. " for each item; * style="format %i", use roman lowercase numerals: "ii. "; * style="format (%d)", use roman uppercase numerals "II. "; * style="letters", use lower- or uppercase letters: "a. " and "A. " (note: two spaces); * style="hanging", use the Pandoc definition list syntax; o Spanx style="verb", style="emph" and style="strong", respectively use: "`text`", "_text_" or "**text**"; o Block quote - not supported by xml2rfc, so this is converted to "" paragraph; o Figure/artwork with an anchor and postamble (Section 6.1); o Tables with an anchor and postamble (Section 6.2); o References (Section 6.3) * external (eref); Gieben Expires October 12, 2013 [Page 5] Internet-Draft Pandoc2rfc April 2013 * internal (xref): + section (handled by Pandoc); + figures (handled by XSLT); + tables (handled by XSLT). o Citations, by using internal references; o Indexes, by (ab)using footnotes (Section 6.4). 5. Unsupported Features o Pandoc markup in the caption for figures/artwork. Pandoc markup for table captions _is_ supported; o Crefs: for comments, but you can use HTML comments: "" in the Pandoc source files; o Preamble in figures and tables. 6. Pandoc Style In some cases the Pandoc syntax is slightly misused to get the desired output, in the following paragraphs we will detail these. Also the meta data feature (Pandoc's "Title Block" extension) of Pandoc is not used in Pandoc2rfc. This information must be put in the "template.xml". 6.1. Figure/Artwork Indent the paragraph with 4 spaces as mandated by Pandoc. Note that xml2rfc supports a caption with "". If you add a "@Figure: some text" as the last line, the artwork gets a "" with the text after "@Figure: ". It will also be possible to reference the artwork. If such a caption is supplied the artwork will be centered on the page. If a caption is needed but the figure should not be centered use "@figure: ". 6.2. Tables 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 (plain "") table in xml2rfc. Gieben Expires October 12, 2013 [Page 6] Internet-Draft Pandoc2rfc April 2013 The table caption is _always_ translated to a "". The "" tag isn't supported. If a table has a caption, it will also be possible to reference the table. 6.3. References 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 (i.e. see Section X) reference is typeset with: "[Click here](#localid)" or "[](#localid)". For referencing RFCs (and other citations), you will need add the reference source in the template, as an external XML entity, Figure 2 provides an example. After that you can use: "[](#RFC2629)" Note that referencing figures/artworks and tables is done slightly different. The reason for this is that Pandoc does not have native support/syntax for this. We work around it, by "faking" the reference in the XSLT. Thus for referencing figures/artworks and tables, you need: o To take the first 10 characters of the caption (i.e. this is the text _after_ the string "Table: " or "@Figure: "); o Translate spaces and single quotes ' to a minus "-"; o Translate uppercase letters to lowercase; o For tables prefix the anchor with "tab:" and for figures use "fig:". The figure from Section 2 will get "fig:a-very-min" as an anchor. Note that duplicate anchors are an XML validation error which will make xml2rfc fail. These are not detected during the XSL transformation. 6.4. Indexes The footnote syntax of Pandoc is slightly abused to support an index. Sub items are also supported. Use an exclamation mark ("!") to separate them: [^1]: item!sub item Gieben Expires October 12, 2013 [Page 7] Internet-Draft Pandoc2rfc April 2013 7. Acknowledgements The following people have helped shape Pandoc2rfc: Benno Overeinder, Erlend Hamnaberg, Matthijs Mekking and Trygve Laugstoel. This document was prepared using Pandoc2rfc. 8. Security Considerations This document raises no security issues. 9. IANA Considerations This document has no actions for IANA. 10. Normative References [Markdown] Gruber, J., "Markdown", 2004, . [Pandoc2rfc] Gieben, R., "Pandoc2rfc git repository", October 2012, . [Pandoc] MacFarlane, J., "Pandoc, a universal document converter", 2006, . [RFC2629] Rose, M.T., "Writing I-Ds and RFCs using XML", RFC 2629, June 1999. [W3C.REC-xslt-19991116] Clark, J., "XSL Transformations (XSLT) Version 1.0", World Wide Web Consortium Recommendation REC-xslt-19991116, November 1999, . [XSLT] Veillard, D., "The XSLT C library for GNOME", 2006, . Appendix A. Changelog [This section should be removed by the RFC editor before publishing] A.1. -00 1. Initial document. Gieben Expires October 12, 2013 [Page 8] Internet-Draft Pandoc2rfc April 2013 A.2. -01 1. Lots of updates; 2. Added the stylesheet use in an appendix. Appendix B. Cheat Sheet +--------------------+------------------+---------------------------+ | Textual construct | Pandoc syntax | xml2rfc Syntax | +--------------------+------------------+---------------------------+ | Section Header | "# Section" | "
" | | Unordered List | "* item" | "" | | Unordered List | "#. item" | "" | | Ordered List | "1. item" | "" | | Ordered List | "a. item" | "" | | Ordered List | "ii. item" | "" | | Ordered List | "II. item" | "" | | Ordered List | "A. item" | "" | | Definition List | Definition | "" | | Emphasis | "_text_" | "" | | Strong Emphasis | "**text**" | "" | | Verbatim | "`text`" | "" | | Block Quote | "> quote" | "" | | Index | Footnotes | "" | | Table | Tables | "" | | Figure/Artwork | Code Blocks | "
" | | External Reference | "[Click](URI)" | "" | | Internal Reference | "[](#id)" | "" | | Figure Reference | "[](#fig:...)" | "" | | Table Reference | "[](#tab:...)" | "" | | Citations | "[](#RFC2119)" | "" | +--------------------+------------------+---------------------------+ The most important textual constructs that can be used in Pandoc2rfc. Table 1 Appendix C. XSLT This is the XSLT with Git version "f0cc985e291ae25a24c91934b8192930df1ad6f6", that is used for the transformation. Gieben Expires October 12, 2013 [Page 9] Internet-Draft Pandoc2rfc April 2013 This document was prepared using Pandoc2rfc https://github.com/miekg/pandoc2rfc Gieben Expires October 12, 2013 [Page 10] Internet-Draft Pandoc2rfc April 2013
Gieben Expires October 12, 2013 [Page 11] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 12] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 13] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 14] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 15] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 16] Internet-Draft Pandoc2rfc April 2013
Gieben Expires October 12, 2013 [Page 17] Internet-Draft Pandoc2rfc April 2013 fig: center fig:
Gieben Expires October 12, 2013 [Page 18] Internet-Draft Pandoc2rfc April 2013 tab: Gieben Expires October 12, 2013 [Page 19] Internet-Draft Pandoc2rfc April 2013 tab: Gieben Expires October 12, 2013 [Page 20] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 21] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 22] Internet-Draft Pandoc2rfc April 2013 Gieben Expires October 12, 2013 [Page 23] Internet-Draft Pandoc2rfc April 2013
Gieben Expires October 12, 2013 [Page 24] Internet-Draft Pandoc2rfc April 2013 XSLT used for the transformation. Figure 4 Author's Address R. (Miek) Gieben Google Email: miek@google.com Gieben Expires October 12, 2013 [Page 25]