<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY pandocAbstract PUBLIC "" "abstract.xml">
<!ENTITY pandocMiddle PUBLIC "" "middle.xml">
<!ENTITY pandocBack PUBLIC "" "back.xml">
<!ENTITY ref.Markdown PUBLIC "" "bib/reference.Markdown.xml">
<!ENTITY ref.Pandoc PUBLIC "" "bib/reference.Pandoc.xml">
<!ENTITY ref.PandocGuide PUBLIC "" "bib/reference.Pandoc-user-guide.xml">
<!ENTITY ref.xslt PUBLIC "" "bib/reference.XSLT.xml">
<!ENTITY ref.Pandoc2rfc PUBLIC "" "bib/reference.Pandoc2rfc.xml">
<!ENTITY rfc.2629 PUBLIC "" "bib/reference.RFC.2629.xml">
<!ENTITY w3c.xslt PUBLIC "" "bib/reference.W3C.REC-xslt-19991116.xml">
]>
<rfc ipr="trust200902" category="info" docName="draft-gieben-pandoc2rfc-03" obsoletes="" updates="" submissionType="IETF" xml:lang="en">
  <front>
    <title abbrev="Pandoc2rfc">Writing I-Ds and RFCs using Pandoc and a bit of XML</title>
    <author initials="R." surname="Gieben" fullname="R. (Miek) Gieben">
      <organization>Google</organization>
      <address>
        <phone/>
        <email>miek@google.com</email>
        <uri/>
      </address>
    </author>
    <date month="October" year="2013"/>
    <area>General</area>
    <workgroup>RFC Beautification Working Group</workgroup>
    <keyword>RFC</keyword>
    <keyword>Request for Comments</keyword>
    <keyword>I-D</keyword>
    <keyword>Internet-Draft</keyword>
    <keyword>XML</keyword>
    <keyword>Pandoc</keyword>
    <keyword>Extensible Markup Language</keyword>
    <abstract><!--This document was prepared using Pandoc2rfc, https://github.com/miekg/pandoc2rfc --><t>This document presents a technique for using a Markdown syntax variant, called Pandoc, and a (bit) of XML <xref target="RFC2629" pageno="false" format="default"/> as a source format for documents in the Internet-Drafts (I-Ds) and Request for Comments (RFC) series.  </t><t>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, it does however not alleviate the need to typeset some files in XML.  </t> </abstract>
  </front>
  <middle><!--This document was prepared using Pandoc2rfc, https://github.com/miekg/pandoc2rfc --><section title="Introduction" anchor="introduction" toc="default"><t><?rfc toc="yes"?> <?rfc symrefs="yes"?> <?rfc sortrefs="yes"?> <?rfc compact="yes"?> <?rfc subcompact="no"?> </t><t>This document presents a technique for using a Markdown <xref target="Markdown" pageno="false" format="default"/> syntax variant, called Pandoc <xref target="Pandoc" pageno="false" format="default"/>, and a bit of XML <xref target="RFC2629" pageno="false" format="default"/> as a source format for documents in the Internet-Drafts (I-Ds) and Request for Comments (RFC) series.  </t><t>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, it does however not alleviate the need to typeset some files in XML.  </t><t>Pandoc is an almost plain text format and therefor particularly well suited for editing RFC-like documents. The syntax itself is a super set of the syntax championed by Markdown.  </t></section><section title="Pandoc to RFC" anchor="pandoc-to-rfc" toc="default"><t>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.  </t><t>Pandoc2rfc allows authors to write in Pandoc syntax which 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.  </t><figure anchor="fig:flow" align="center" title="Attempt to justify Pandoc2rfc." suppress-title="false" alt="" width="" height=""><artwork xml:space="preserve" name="" type="" align="left" alt="" width="" height="">
+-------------------+   pandoc   +---------+
| ALMOST PLAIN TEXT |   ------&gt;  | DOCBOOK |
+-------------------+     1      +---------+
              |                       |
non-existent  |                     2 | xsltproc
  faster way  |                       |
              v                       v
      +------------+    xml2rfc  +---------+
      | PLAIN TEXT |  &lt;--------  |   XML   |
      +------------+      3      +---------+
</artwork></figure><t></t><t>The output of step 2 in <xref target="fig:flow" pageno="false" format="default"/> is XML which is suitable for inclusion in either the <spanx style="verb" xml:space="preserve">middle</spanx> or <spanx style="verb" xml:space="preserve">back</spanx> section of an RFC.  </t><t>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 <spanx style="verb" xml:space="preserve">front</spanx> section of an RFC.  </t><t>The simplest way to start using Pandoc2rfc is to create a template XML file and include the appropriate XML for the <spanx style="verb" xml:space="preserve">front</spanx>, <spanx style="verb" xml:space="preserve">middle</spanx> and <spanx style="verb" xml:space="preserve">back</spanx> section: </t><figure anchor="fig:minimal" align="center" title="A minimal template.xml." suppress-title="false" alt="" width="" height=""><artwork xml:space="preserve" name="" type="" align="left" alt="" width="" height="">
&lt;?xml version='1.0' ?&gt;
&lt;!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
&lt;!ENTITY pandocAbstract PUBLIC '' 'abstract.xml'&gt;
&lt;!ENTITY pandocMiddle   PUBLIC '' 'middle.xml'&gt;
&lt;!ENTITY pandocBack     PUBLIC '' 'back.xml'&gt;
&lt;!ENTITY rfc.2629       PUBLIC '' 'reference.RFC.2629.xml'&gt;
]&gt;

&lt;rfc ipr='trust200902' docName='draft-gieben-pandoc2rfc'&gt;
 &lt;front&gt;
    &lt;title&gt;Writing I-Ds and RFCs using Pandoc&lt;/title&gt;
    &lt;author&gt;
       &lt;organization/&gt;
       &lt;address&gt;&lt;uri&gt;http://www.example.com&lt;/uri&gt;&lt;/address&gt;
    &lt;/author&gt;
    &lt;date/&gt;
    &lt;abstract&gt;
        &amp;pandocAbstract;
    &lt;/abstract&gt;
&lt;/front&gt;
&lt;middle&gt;
    &amp;pandocMiddle;
&lt;/middle&gt;
&lt;back&gt;
    &lt;references title="Normative References"&gt;
        &amp;rfc.2629;
    &lt;/references&gt;
    &amp;pandocBack;
&lt;/back&gt;
&lt;/rfc&gt;
</artwork></figure><t></t><t>In this case you will need to edit four documents: </t><t><list style="numbers"><t><spanx style="verb" xml:space="preserve">abstract.mkd</spanx> - contains the abstract; </t><t><spanx style="verb" xml:space="preserve">middle.mkd</spanx> - contains the main body of text; </t><t><spanx style="verb" xml:space="preserve">back.mkd</spanx> - holds the appendices (if any); </t><t>And this <spanx style="verb" xml:space="preserve">template.xml</spanx> - probably a fairly static file, among other things, it holds the author(s) and the references.  </t></list></t><t>Up to date source code for Pandoc2rfc can be found at <xref target="Pandoc2rfc" pageno="false" format="default"/>, this includes the style sheet <spanx style="verb" xml:space="preserve">transform.xsl</spanx> which used for the XML transformation (also see <xref target="building-an-internet-draft" pageno="false" format="default"/>).  </t><section title="Dependencies" anchor="dependencies" toc="default"><t>Pandoc2rfc needs <spanx style="verb" xml:space="preserve">xsltproc</spanx> <xref target="XSLT" pageno="false" format="default"/> and <spanx style="verb" xml:space="preserve">pandoc</spanx> <xref target="Pandoc" pageno="false" format="default"/> to be installed. The conversion to xml2rfc XML is done with a style sheet based on XSLT version 1.0 <xref target="W3C.REC-xslt-19991116" pageno="false" format="default"/>.  </t><t>When using the template from <xref target="fig:minimal" pageno="false" format="default"/> xml2rfc version 2 (or higher) must be used.  </t></section></section><section title="Building an Internet-Draft" anchor="building-an-internet-draft" toc="default"><t>Assuming the setup from <xref target="pandoc-to-rfc" pageno="false" format="default"/>, we can build an I-D as follows (in a Unix-like environment): </t><figure anchor="fig:build" align="center" title="Building an I-D." suppress-title="false" alt="" width="" height=""><artwork xml:space="preserve" name="" type="" align="left" alt="" width="" height="">
for i in abstract middle back; do
pandoc -st docbook $i.mkd | xsltproc --nonet transform.xsl - &gt; $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
</artwork></figure><t></t><t>Note that the output file names (abstract.xml, middle.xml and back.xml) must match the names used as the XML entities in <spanx style="verb" xml:space="preserve">template.xml</spanx> (See the <spanx style="verb" xml:space="preserve">!ENTITY</spanx> lines in <xref target="fig:minimal" pageno="false" format="default"/>). The Pandoc2rfc source repository includes a shell script that incorporates the above transformations. Creating a <spanx style="verb" xml:space="preserve">draft.txt</spanx> or a <spanx style="verb" xml:space="preserve">draft.xml</spanx> can be done with <spanx style="verb" xml:space="preserve">pandoc2rfc *.mkd</spanx> and <spanx style="verb" xml:space="preserve">pandoc2rfc -X *.mkd</spanx> respectively.  </t></section><section title="Supported Features" anchor="supported-features" toc="default"><t>The full description of Pandoc's syntax can be found in <xref target="PandocGuide" pageno="false" format="default"/>. The following features of xml2rfc are supported by Pandoc2rfc (also see <xref target="tab:cheat" pageno="false" format="default"/> in <xref target="cheat-sheet" pageno="false" format="default"/> for a "cheat sheet"): </t><t><list style="symbols"><t>Sections with an anchor and title attributes; </t><t>Several lists styles: <list style="symbols"><t>style="symbols", use "* " for each item; </t><t>style="numbers", use digits: "1. " for each item; </t><t>style="empty", use "#. " for each item; </t><t>style="format %i", use roman lowercase numerals: "ii. "; </t><t>style="format (%d)", use roman uppercase numerals "II. "; </t><t>style="letters", use lower- or uppercase letters: "a.  " and "A.  " (note: two spaces as mandated by Pandoc); </t><t>style="hanging", use the Pandoc definition list syntax: <figure anchor="noref1" align="center" title="Pandoc syntax used for a hanging paragraph." suppress-title="false" alt="" width="" height=""><artwork xml:space="preserve" name="" type="" align="left" alt="" width="" height="">
Term 1

:   Definition 1
</artwork></figure> <vspace blankLines="1"/> </t></list> </t><t>Spanx style="verb", style="emph" and style="strong", respectively use: <spanx style="verb" xml:space="preserve">`text`</spanx>, <spanx style="verb" xml:space="preserve">_text_</spanx> or <spanx style="verb" xml:space="preserve">**text**</spanx>; </t><t>Block quote is converted to <spanx style="verb" xml:space="preserve">&lt;list style="empty"&gt;</spanx> paragraph; </t><t>Figures with an anchor and title (<xref target="figures" pageno="false" format="default"/>); </t><t>Tables with an anchor and title (<xref target="tables" pageno="false" format="default"/>); </t><t>References (<xref target="references" pageno="false" format="default"/>) <list style="symbols"><t>external (<spanx style="verb" xml:space="preserve">&lt;eref&gt;</spanx>); </t><t>internal (<spanx style="verb" xml:space="preserve">&lt;xref&gt;</spanx>), to: <list style="symbols"><t>sections (handled by Pandoc); </t><t>figures (handled by XSLT); </t><t>tables (handled by XSLT).  </t></list> </t></list> </t><t>Citations, by using internal references; </t><t>Processing Instructions (<spanx style="verb" xml:space="preserve">PI</spanx>s: <spanx style="verb" xml:space="preserve">&lt;?rfc?&gt;</spanx>), may be used after a section header, they are carried over to the generated XML; </t><t>The <spanx style="verb" xml:space="preserve">&lt;vspace&gt;</spanx>-tag is supported and carried over to the generated XML.  </t></list></t></section><section title="Unsupported Features and Limitations" anchor="unsupported-features-and-limitations" toc="default"><t>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 forces the author to edit XML files. The meta data feature (Pandoc's "Title Block" extension) is not used in Pandoc2rfc. This information (authors, date, keyword and URLs) should be put in the <spanx style="verb" xml:space="preserve">template.xml</spanx>.  </t><t>Some other quirks: </t><t><list style="symbols"><t>An index is not supported; </t><t>Comments are supported via HTML comments in the Pandoc source files; </t><t>Citations are supported via internal references, the citation syntax of Pandoc is not used; </t><t>Authors still need to know how to deal with possible errors from xml2rfc.  </t></list></t></section><section title="Pandoc Style" anchor="pandoc-style" toc="default"><t>The following sections detail how to use the Pandoc syntax for figures, tables and references to get the desired output.  </t><section title="Figures" anchor="figures" toc="default"><t>Indent the paragraph with 4 spaces as mandated by Pandoc. If you add an inline footnote <spanx style="emph" xml:space="preserve">directly</spanx> after the figure, the artwork gets a title attribute with the text of that footnote (and a possible anchor).  </t></section><section title="Tables" anchor="tables" toc="default"><t>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 <spanx style="verb" xml:space="preserve">&lt;texttable&gt;</spanx>) table in xml2rfc. If you add an inline footnote <spanx style="emph" xml:space="preserve">directly</spanx> 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 <spanx style="verb" xml:space="preserve">Table:</spanx> should not be used.  </t></section><section title="References" anchor="references" toc="default"><t>Pandoc provides a syntax that can be used for references. Its syntax is repeated in this paragraph. Any reference like: <spanx style="verb" xml:space="preserve">[Click here](URI)</spanx>, is an external reference. An internal (i.e. see Section X) reference is typeset with: <spanx style="verb" xml:space="preserve">[](#localid)</spanx>.  </t><t>For referencing RFCs (and other citations), you will need add the reference source in the template, as an external XML entity, <xref target="fig:minimal" pageno="false" format="default"/> provides an example. After that you can use an internal reference: <spanx style="verb" xml:space="preserve">[](#RFC2629)</spanx> to reference RFC 2629.  </t><t>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 <spanx style="verb" xml:space="preserve">::</spanx> will be used as the anchor. If a figure has an anchor it will be centered on the page.  </t><t><xref target="fig:minimal" pageno="false" format="default"/> for instance, is followed by this inline footnote: </t><figure title="" suppress-title="false" align="left" alt="" width="" height=""><artwork xml:space="preserve" name="" type="" align="left" alt="" width="" height="">
^[fig:minimal::A minimal template.xml.]
</artwork></figure></section></section><section title="Acknowledgements" anchor="acknowledgements" toc="default"><t>The following people have helped shape Pandoc2rfc: Benno Overeinder, Erlend Hamnaberg, Matthijs Mekking and Trygve Laugstøl.  </t></section><section title="Security Considerations" anchor="security-considerations" toc="default"><t>This document raises no security issues.  </t></section><section title="IANA Considerations" anchor="iana-considerations" toc="default"><t>This document has no actions for IANA.  </t></section> </middle>
  <back><references title="Normative References"><reference anchor="Markdown" target="http://daringfireball.net/projects/markdown/"><front><title>Markdown</title><author initials="J." surname="Gruber" fullname="John Gruber"><organization>The Daring Fireball Company LLC.</organization><address><email>comments@daringfireball.net</email><uri>http://daringfireball.net/</uri></address></author><date year="2004"/></front></reference> <reference anchor="XSLT" target="http://xmlsoft.org/XSLT/xsltproc2.html"><front><title>The XSLT C library for GNOME</title><author initials="D." surname="Veillard" fullname="Daniel Veillard"><organization>XML Soft</organization><address><email/><uri>http://xmlsoft.org/</uri></address></author><date year="2006"/></front></reference> <reference anchor="Pandoc" target="http://johnmacfarlane.net/pandoc/"><front><title>Pandoc, a universal document converter</title><author initials="J." surname="MacFarlane" fullname="John MacFarlane"><organization>University of California, Berkeley</organization><address><email>jgm@berkeley.edu</email><uri>http://johnmacfarlane.net/</uri></address></author><date year="2006"/></front></reference> <reference anchor="PandocGuide" target="http://johnmacfarlane.net/pandoc/README.html"><front><title>Pandoc User's Guide</title><author initials="J." surname="MacFarlane" fullname="John MacFarlane"><organization>University of California, Berkeley</organization><address><email>jgm@berkeley.edu</email><uri>http://johnmacfarlane.net/</uri></address></author><date year="2006"/></front></reference> <reference anchor="Pandoc2rfc" target="http://github.com/miekg/pandoc2rfc"><front><title abbrev="Pandoc2rfc">Pandoc2rfc git repository</title><author initials="R." surname="Gieben" fullname="R. (Miek) Gieben"><address><email>miek@miek.nl</email></address></author><date year="2012" month="October"/></front></reference> <reference anchor="RFC2629"><front><title>Writing I-Ds and RFCs using XML</title><author initials="M.T." surname="Rose" fullname="Marshall T. Rose"><organization>Invisible Worlds, Inc.</organization><address><postal><street>660 York Street</street><city>San Francisco</city><region>CA</region><code>94110</code><country>US</country></postal><phone>+1 415 695 3975</phone><email>mrose@not.invisible.net</email><uri>http://invisible.net/</uri></address></author><date year="1999" month="June"/><area>General</area><keyword>RFC</keyword><keyword>Request for Comments</keyword><keyword>I-D</keyword><keyword>Internet-Draft</keyword><keyword>XML</keyword><keyword>Extensible Markup Language</keyword><abstract><t>This memo presents a technique for using XML (Extensible Markup Language) as a source format for documents in the Internet-Drafts (I-Ds) and Request for Comments (RFC) series.</t></abstract></front><seriesInfo name="RFC" value="2629"/><format type="TXT" octets="48677" target="http://www.rfc-editor.org/rfc/rfc2629.txt"/><format type="HTML" octets="72426" target="http://xml.resource.org/public/rfc/html/rfc2629.html"/><format type="XML" octets="53481" target="http://xml.resource.org/public/rfc/xml/rfc2629.xml"/></reference> <reference anchor="W3C.REC-xslt-19991116" target="http://www.w3.org/TR/1999/REC-xslt-19991116"><front><title>XSL Transformations (XSLT) Version 1.0</title><author initials="J." surname="Clark" fullname="James Clark"><organization/></author><date month="November" day="16" year="1999"/></front><seriesInfo name="World Wide Web Consortium Recommendation" value="REC-xslt-19991116"/><format type="HTML" target="http://www.w3.org/TR/1999/REC-xslt-19991116"/></reference> </references><!--This document was prepared using Pandoc2rfc, https://github.com/miekg/pandoc2rfc --><section title="Changelog" anchor="changelog" toc="default"><t>[This section should be removed by the RFC editor before publishing] </t><section title="-00" anchor="section" toc="default"><t><list style="numbers"><t>Initial document.  </t></list></t></section><section title="-01" anchor="section-1" toc="default"><t><list style="numbers"><t>Lots of updates; </t><t>Added the style sheet use in an appendix.  </t></list></t></section><section title="-02" anchor="section-2" toc="default"><t><list style="numbers"><t>Make <spanx style="verb" xml:space="preserve">template.xml</spanx> actually valid XML; </t><t>Removed the style sheet from the appendix; </t><t>Make more explicit that typesetting some XML files is still needed; </t><t>Fix blockquote text and conversion; </t><t>Overhauled the way references to figures and tables work; </t><t>Cleaned up and removed duplicate text.  </t></list></t></section><section title="-03" anchor="section-3" toc="default"><t><list style="numbers"><t>Change affiliation for R. Gieben.  </t></list></t></section></section><section title="Cheat Sheet" anchor="cheat-sheet" toc="default"><texttable anchor="tab:cheat" align="center" title="The most important textual constructs that can be used in Pandoc2rfc. The bottom three create output to voluminous to show in this table." suppress-title="false" style="full"><ttcol align="left">Textual construct </ttcol><ttcol align="left">Pandoc syntax </ttcol><ttcol align="left">Text output </ttcol><c>Section Header </c><c><spanx style="verb" xml:space="preserve"># Section</spanx> </c><c>1. Section </c><c>Unordered List </c><c><spanx style="verb" xml:space="preserve">* item</spanx> </c><c>o  item </c><c>Unordered List </c><c><spanx style="verb" xml:space="preserve">#. item</spanx> </c><c>item </c><c>Ordered List </c><c><spanx style="verb" xml:space="preserve">1. item</spanx> </c><c>1.  item </c><c>Ordered List </c><c><spanx style="verb" xml:space="preserve">a.  item</spanx> </c><c>a.  item </c><c>Ordered List </c><c><spanx style="verb" xml:space="preserve">ii. item</spanx> </c><c>i.  item </c><c>Ordered List </c><c><spanx style="verb" xml:space="preserve">II. item</spanx> </c><c>(1)  item </c><c>Ordered List </c><c><spanx style="verb" xml:space="preserve">A.  item</spanx> </c><c>A.  item </c><c>Emphasis </c><c><spanx style="verb" xml:space="preserve">_text_</spanx> </c><c><spanx style="emph" xml:space="preserve">text</spanx> </c><c>Strong Emphasis </c><c><spanx style="verb" xml:space="preserve">**text**</spanx> </c><c><spanx style="strong" xml:space="preserve">text</spanx> </c><c>Verbatim </c><c><spanx style="verb" xml:space="preserve">`text`</spanx> </c><c>"text" </c><c>Block Quote </c><c><spanx style="verb" xml:space="preserve">&gt; quote</spanx> </c><c>quote </c><c>External Reference </c><c><spanx style="verb" xml:space="preserve">[Click](URI)</spanx> </c><c>Click [1] </c><c>Internal Reference </c><c><spanx style="verb" xml:space="preserve">[](#id)</spanx> </c><c>Section 1 </c><c>Figure Anchor </c><c><spanx style="verb" xml:space="preserve">^[fid::text]</spanx> </c><c>N/A </c><c>Figure Reference </c><c><spanx style="verb" xml:space="preserve">[](#fid)</spanx> </c><c>Figure 1 </c><c>Table Anchor </c><c><spanx style="verb" xml:space="preserve">^[tid::text]</spanx> </c><c>N/A </c><c>Table Reference </c><c><spanx style="verb" xml:space="preserve">[](#tid)</spanx> </c><c>Table 1 </c><c>Citations </c><c><spanx style="verb" xml:space="preserve">[](#RFC2119)</spanx> </c><c>[RFC2199] </c><c>Table </c><c>Tables </c><c></c><c>Figures </c><c>Code Blocks </c><c></c><c>Definition List </c><c>Definition </c><c></c></texttable><t></t></section> </back>
</rfc>
