# Although WordPress fully supports Markdown via the JetPack plugin and Markdown supports code blocks there are occasions where the encoding gets thrown off on posting and has to be edited before making a post live.
Chris Aldrich linked to a piece on the WordPress.com support pages that details the [code]
shortcode which, with a language
parameter, preserves formatting and even adds syntax highlighting within posts and pages.
This is native to WordPress.com but a plugin is available for self-hosted blogs which I may start using.
Compare the two blocks below:
function make_post($post){
$post = [
'title' => $title,
'content' => $body,
'status' => $status,
'format' => $format,
];
return $post;
}
[code lang="php"] function make_post($post){ $post = [ 'title' => $title, 'content' => $body, 'status' => $status, 'format' => $format, ]; return $post; } [/code]
The first is the standard Markdown rendering (I had to correct the greater than symbols having been converted to >) and the second uses the plugin.
Pretty cool!
In Drafts I can create an action that inserts the shortcode after prompting for the language I want and I'll look at creating an Alfred workflow to do the same thing.
(You’ll need to visit the actual post to see the difference as you won’t get the effect via RSS.)
Comments
# I'm starting to build a little library of Alfred workflows from around the web. Nothing amazing but just a few little things to make life easier such as:
- mark all as read in mail.app
- take screenshots (because I can never remember the keyboard shortcuts)
- toggle do not disturb
- look up synonyms and antonyms (and paste the selected word)
- open things like specific folders or my WordPress dashboard
I'm still not very familiar with AppleScript (I've learnt how to do a few things) but that will come with time.
# I've also now created a Drafts action and Alfred workflow to insert the [code]
shortcode with the specified language type into whatever I'm writing. Just like the actual WordPress.com shortcode, if no language is entered they default to txt.
Drafts prompts me for the language (php, js, etc.) whereas with Alfred I type the language as part of the command - code php
for example.
# Liked: Drafts 5.2 – The Navigation Update – nahumck.me...
The pace at which Greg Pierce is able to iterate on Drafts 5 is proof that the subscription model works when used correctly.
@colinwalker I saw this yesterday in M.B, and it looks fine. Today I saw it in my feed reader (ReadKit via Feedly) and the two code blocks are the wrong way round. Nice colourful one first, then old black and white.
Hard to imagine what could have caused that, but I thought you should know.
I was going to mention this, I noticed the same thing in FeedBin. I think the Markdown code block is being recognised and certain feed readers include syntax highlighting whereas the second version is stored as plain text where the formatting is retained and the plugin does the work on site at the time of rendering. Because it’s plain text it isn’t recognised as a code block by the readers.
And something about the browser at work stops the plugin from rendering so I just see two grey boxes.
@colinwalker Oooo, thanks for the tip about the plugin. I was looking for something like it. ?
heh, saw this on the RSS feed and for a moment, was like, "but there's no difference!"
Then read till the end and came here to see it :)
Yeah, readers tend to vary in how they display the first one but the [code] blocks just seem to be blocks of text so not treated in any special way away from the site.