Last active
December 22, 2015 23:13
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub paragraphs { $^s.split: /\n\n+/ } | |
sub is-code-block { $^s ~~ /^ ' ' ** 4/ } | |
sub escape { $^s.trans: ['>', '<', '&'] => ['>', '<', '&'] } | |
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