Preprocessor for Raku Advent Articles, with syntax highlighter. Saves the
trouble of not having to deal with broken escapes in code blocks in Wordpress
and provides syntax-highlights, as a cherry on top.
To get the best syntax highlights, the module uses GitHub's Gists for
highlighting. You'll need to
obtain a GitHub API token. Only
gist Create gists permission is needed. After creating the gist, the
script grabs syntax highlighted code from it, and then deletes it.
Install this module:
zef install Acme::Advent::Highlighter
If you're using
rakudobrew, then don't,
but if you insist, be sure to run
rakudobrew rehash after installation,
to update script shims.
If you want to run extra tests, set
ONLINE_TESTING=1 env var.
Write your article in basic
Markdown and save
it to a file
advent-highlighter.raku Your-Article Your-Gist-Token > out.html
The gist token can alternatively be given via
ACME_ADVENT_HIGHLIGHTER_TOKEN environmental variable. The STDOUT of
the script will output the rendered content while STDERR will output
some info on what the script is doing.
Go to Wordpress and copy-paste contents of
out.html (or wherever you
saved the output) into Wordpress's editor, ensuring you're editing in
"HTML" and not "Visual" mode.
Preview or Publish
Celebrate with an appropriate amount of fun
advent-highlighter.raku --wrap Your-Article Your-Gist-Token > out.html
If you'd like to have a rough idea of how the thing will look like on Wordpress,
you can pass
--wrap option to the script. It'll wrap the output into a bit
of markup to make the width of the article to be approximately what it is on
Raku Advent articles right now (might wanna check your codeblocks don't
overflow if you don't want readers scrolling).
--multi option for Multi Markdown
advent-highlighter.raku --multi Your-Article Your-Gist-Token > out.html
Text::Markdown to be a bit of a weak sauce and it failed to render
some things I thought it would. If you
Inline::Perl5 along with
Text::MultiMarkdown Perl module (just run
cpanm -v Text::MultiMarkdown or
cpan Text::MultiMarkdown if you don't have
then you can add
--multi command line option to make the script use that as Markdown renderer.
Alternative Content Options
The script does some heuristics for the value of the content argument:
- If it starts with
https://, assumes it's a URL and will fetch
the actual content from it
- If a readable file exists with such a name, assumes the content is in that
file and will read it from it
- Otherwise, assume the given value is literally the content
Notes on Editing/Content
Wordpress is a finicky beast (or at least the installation on our Advent is). For paragraphs: ensure they're all on one line in your Markdown, otherwise, there'll be weird line breaks in the final article.
Also, there's a way to mess up code blocks on the article even after using this script. It looks like it happens
if you save your article (or have autosave feature trigger) when using "Visual" mode. So be sure to keep around your originals and keep an eye out on messed up code blocks if you edit your articles on Wordpress
If you copy-paste code from the article, the paste will have a ton of blank newlines. I'm not bothered by this enough
to do anything about it, but will take a patch that removes those, without risk of damaging intended content.
Fork this module on GitHub:
To report bugs or request features, please use
Zoffix Znet (http://perl6.party/)
You can use and distribute this module under the terms of the
The Artistic License 2.0. See the
LICENSE file included in this
distribution for complete details.
Syntax highlighting CSS code is based on GitHub Light v0.4.1,
Copyright (c) 2012 - 2017 GitHub, Inc. Licensed under MIT
META6.json file of this distribution may be distributed and modified
without restrictions or attribution.