OPML to Markdown and back

By R. S. Doiel 2016-05-28


I wrote a Go language package to sort OPML outlines. I wrote this because my preferred feed reader supports manual sorting but not automatic alpha sorting by the outline element’s text attribute.


Out of the box the OPML 2 Spec provides attributes indicating inclusion of other OPML files, scripts, basic metadata (create, modified, authorship), and even directory structures.

Fargo allows userdefined attributes to be applied to the outline element in OPML. This could be used in support some of the Scrivener features I miss such as describing how to render a project to various formats such as rtf, pdf, ePub, web pages or even Final Draft fdx files.

I write allot of Markdown formatted text. Markdown is simple to index, search and convert into useful formats. Markdown is not good at expressing more complex structures such as metadata. Website generators that use markdown often require a preable or front matter in the markdown to provide any metadata. This leaves your document head cluttered and less human readable.

Another approach is to include a parallel document with the metadata. It occurred to me that an OPML file could easily hold that metadata. It can even hold Markdown content. The trouble with OPML is that it is not quick to edit by hand.

Is there a round trip semantic mapping between OPML and Markdown?

Germination of an idea

Entering a web link in Fargo the link is URL encoded and saved in the text attribute of the outline element.

The source view of a web links in Fargo’s outline element looks like

    <outline text="&gt; href=&quot;http://example.org&quot;&lt;My example.org&gt;/a&lt;" />

That outline element might render in Markdown as

    + [My element.org](http://example.org)

The steps to create the Markdown view are simple

  1. URL decode the text attribute
  2. Convert HTML to Markdown

Making a round trip could be done by

  1. Convert Markdown into HTML
  2. For each li element covert to an outline element URL encoding the inner HTML of the li

So far so good. What about something more complex?

Here’s an outline element example from http://hosting.opml.org/dave/spec/directory.opml

    <outline text="Scripting News sites" created="Sun, 16 Oct 2005 05:56:10 GMT" type="link" url="http://hosting.opml.org/dave/mySites.opml"/>

To me that should look like

    + [Scripting News Sites](http://hosting.opml.org/dave/mySites.opml)

What about the created attribute? Could we render this case as an additional set of anchors using data uri?

This suggest a rule like

This might work as follows.

    <outline text="Scripting News sites" 
        created="Sun, 16 Oct 2005 05:56:10 GMT" 

Would become

    + [Scripting News Sites](http://hosting.opml.org/dave/mySites.opml) [type](data:text/plain;link) [created](data:text/date;Sun, 16 Oct 2005 05:56:10 GMT)

In HTML this would look like

    <li><a href="http://histing.opml.org/dave/mySites.opml">Scripting News Sites</a>
        <a href="data:text/plain;link">type</a>
        <a href="data:text/date;Sun, 16 Oct 2005 05:56:10 GMT">created</a></li>

Markdown to OPML

Coming back to OPML from Markdown then becomes

Is this viable? Does it have any advantages?