Skip to content

Instantly share code, notes, and snippets.

@masak
Last active December 22, 2015 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/0636c964eb17725da38b to your computer and use it in GitHub Desktop.
Save masak/0636c964eb17725da38b to your computer and use it in GitHub Desktop.
A short converter script for people who want to write their post in Markdown but convert it to Wordpress broken HTML
sub paragraphs { $^s.split: /\n\n+/ }
sub is-code-block { $^s ~~ /^ ' ' ** 4/ }
sub escape { $^s.trans: ['>', '<', '&'] => ['&gt;', '&lt;', '&amp;'] }
for paragraphs(slurp.trim) -> $_ is copy {
if is-code-block($_) {
say "<code><pre>{ .indent(-4).&escape }</code></pre>";
}
else {
.=subst(:g, / '[' (<-[\]]>+) '](' (<-[)]>+) ')' /, -> $/ { qq[<a href="$1">{$0}</a>] });
.=subst(:g, / '`' (<-[`]>+) '`' /, -> $/ { qq[<code>{$0}</code>] });
.say;
}
say "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment