# Rfc2pandoc


Have an I-D laying around and sick of typing XML? You want to use Pandoc2rfc, but you don't want to manually
convert the XML (or the generated text) into Pandoc? Well, now finally you can do this automatically. I created a little
[stylesheet](https://raw.github.com/miekg/pandoc2rfc/master/plain.xsl), that can be used to transform
the XML to Pandoc. Note the transformation is not perfect, there are a few cases where you still have to 
edit the Pandoc, most notably: 

* empty lines in artworks
* tables

This functionality is built into pandoc2rfc, but it's easy to use by only downloading the `plain.xsl`.

Lets download some I-D.

    wget http://www.ietf.org/id/draft-wouters-dane-openpgp-00.xml

Next make the draft XML fully self contained, otherwise the parser will complain:

    xml2rfc --exp draft-wouters-dane-openpgp-00.xml

Next convert the draft to Pandoc:

    xsltproc --nonet plain.xsl - < draft-wouters-dane-openpgp-00.exp.xml > middle.mkd 

Ok, so no we have a `middle.mdk` which is in Pandoc, but we need some other fluff, that
you cannot typeset in the Pandoc file.

Get out the front section from the original (XML) draft:

    perl -n -e 'if (m|</front>|) { print; exit }; print' draft-wouters-dane-openpgp-00.xml \
    > template.xml

Add empty middle section:

    echo '<middle>' >> template.xml
    echo '</middle>' >> template.xml

Add the back section and secretly add the closing `</rfc>` tag too:

     perl -n -e 'if (m|<back>|) { $back=1 }; if (m|</back>|) { print; exit }; print if $back;' \
     draft-wouters-dane-openpgp-00.xml >> template.xml
     echo '</rfc>' >> template.xml

The only thing left is to add an ENTITY which inserts `middle.mkd` when converted to xml, between
the `<middle>` tags add: `&pandocMiddle;` and at the top of the file add somewhere in the other
ENTITYs: `<!ENTITY pandocMiddle PUBLIC '' 'middle.xml'>`.

And then re-create the original draft, to see if everything has worked:

    pandoc2rfc middle.mkd

And wonder at your `draft.txt` that has been created (if all goes well). All edits can now be made
to `middle.mkd` and you only barely have to touch the XML again.

