Convert Markdown to earthli format

Published by marco on

The earthli blogging format uses HTML-like formatting, described in the lengthy manual (with examples). However, Encodo’s blogging back-end now uses Umbraco, with Markdown for content. I used to be able to cross-post with ease, by copy/pasting. Now, I need to convert the content from Markdown to earthli formatting.

The following steps suffice to convert any article:

  1. If there are attached media (e.g. graphics), save those locally
  2. Create a new earthli article with the same title as the source article
  3. Attach all media to the new article
  4. Copy the main text; paste into Sublime Text
  5. Find/replace the following regular expressions with the replacements:
    • ### ([^\n]+)$ => <h level=“3”>\1</h>
    • ## ([^\n]+)$ => <h>\1</h>
    • \[([^!][^\]]+)\]\(([^\)]+)\) => <a href=“\2”>\1</a>
    • \*\*([^\*]+)\*\* => <b>\1</b>
    • _([^_]+)_ => <i>\1</i>
    • ```txt\n([^`]+)\n``` => <pre>\1</pre>
    • ```[a-z]+\n([^`]+)\n``` => <code>\1</code>
    • `([^`]+)` => <c>\1</c>
  6. Manually re-attach all media in the appropriate locations[1]

I haven’t automated this process yet because I only rarely transfer articles.

[1] This is easy since the earthli UI includes an attachment formatter that lets you place, align, link and scale the attachment better than in the original specification anyway.