Redcarpet Markdown



In order to use custom content processing libarary (I wanted to try out new markdown lib from github, Redcarpet) I needed to extend Nesta's FileModel'. This installs a custom image renderer on RedCarpet, which adds a width='100%' attribute to your image elements. It also converts bare image links to markdown-recognized image links in the gsub call. This results in an embedded image url being rendered like this. Red Carpet Events.

28 August 2018

by Alex Harvey

Markdown

I recently spent some time automating the generation of Markdown tables-of-contents for compatibility with my open source projects in Github and also Gitlab Cloud. In the process, I reviewed a number of auto table-of-contents options by Markdown flavour and version, which I will document here.

Github Markdown

Github uses Github Flavoured Markdown (GFM), which is based on the CommonMark spec. GFM is documented here. As such, a table of contents is something you are expected to write yourself in Markdown, using inline links.

For example:

There are tools out there to auto-generate tables of contents e.g. markdown-toc, but I wanted something simpler and I wrote my own Ruby script to do it. My script is gen_markdown_toc.rb.

To use it (on a Mac):

Then copy the generated text in your Markdown file where you want the table of contents to appear.

Gitlab Markdown

As of now, Gitlab Cloud Markdown uses GFM as well, or at least the version of Gitlab Cloud that I tested this on does. Free microsoft office software download for mac.

Note that Gitlab’s docs here reveal that until recently Gitlab used Kramdown under the hood (see below). I discovered this page here that explains why they migrated away from Kramdown and thereby broke the useful table of contents feature.

Bitbucket Markdown

According to documentation here, Bitbucket’s Markdown is also based on CommonMark, so I would expect my script to work on Bitbucket too.

Kramdown Markdown

Meanwhile, other versions of Markdown have built in features to auto-generate tables of contents. Kramdown documented here is a Ruby implementation of Markdown that makes tables of contents a lot easier. If you are using Kramdown, you just need to add this:

Redcarpet Markdown Image

This Jekyll blog uses Kramdown Markdown for example.

RedCarpet Markdown

RedCarpet documented here is another flavour that makes auto-generation of tables of contents easy. It is apparently used in Gitlab’s Wikis. Just add this for a table of contents:

Typora Markdown

Another flavour is Typora Markdown documented here. For a ToC you can write:

End note

These are all the Markdown formats I am aware of. I would like to keep this page up to date and to that end I welcome feedback and updates.

tags: markdown

Opinion

Seeing Donald Trump go after London Mayor Sadiq Khan was as predictable as seeing Trump spell his name wrong. But Khan's mistaken about one thing, Mark Hallam says; it's very British to fawn over this misogynist fibber.

RedcarpetRedcarpet markdown editor

Donald Trump certainly won't be the classiest cat ever to sit down with Queen Elizabeth II. But nor will he be the nastiest, to use his own chosen adjective of the week.

Read more:Trump arrives in the UK, protests planned

London Mayor Sadiq Khan drew the ire of The Donald with his column in The Observer this weekend, arguing 'It's un-British to roll out the red carpet for Donald Trump.'

Markdown

Trump, ever one to take the high road, decided his best means of response was a two-part set of Twitter insults aimed at Khan, spelling his name Kahn, as Air Force One touched down in the UK.

Redcarpet Markdown

Mysteriously, he also thought it wise to use the very same 'nasty' label he had used to describe Meghan Markle, the Duchess of Sussex — because reminding your hosts that you insulted the second-newest member of their family in one of the country's top-selling papers is sure to keep the wine and the conversation flowing.

Trump, for his part, seems improperly keen on a second meeting with Her Majesty, based on an old interview with his chum from reality TV show The Apprentice, Piers Morgan: 'She's an incredible woman, she is so sharp, she is so beautiful. And when I say beautiful: inside and out, that is a beautiful woman.' Golly, 97-year-old Prince Philip and the corgis had better stay on guard.

Outgoing leader Theresa May and the Tories should remain watchful, too. He's barely even hit the tarmac in London, but already Trump has backed Boris Johnson as a possible next prime minister and suggested sending Nigel Farage off to 'negotiate Brexit' in Brussels. These suggestions will go down rather better in certain British newspapers and among Conservative members than it will among the party leadership, desperately trying to find both an electable leader and a way to deliver Brexit without voluntarily crashing the economy or triggering a risky election first.

Proud tradition of pandering to miscreants

Public dissatisfaction and even protests like the massive inflatable Trump Baby blimp are entirely understandable as this contentious commander in chief comes to town. It's also in keeping with the restless Brexit mood in the UK. Still, let's keep things in perspective.

While it's true that not every world leader is afforded a state visit, it's also true that plenty of reprehensible ones have enjoyed the honor before Trump. And it's just as likely that far worse will follow the real estate mogul turned rant merchant.

Markdown

Arguably the world's most experienced stateswoman, Queen Elizabeth II could handle Trump with one arm behind her back.

Buckingham Palace cleared out the valuables ahead of the Ceausescus' 1978 state visit, after a tipoff from the French

She's seen off Romania's Nicolae and Elena Ceausescu in 1978, and the corrupt and mentally unbalanced Mobuto Sese Seko (of what was then known as Zaire) in 1973. She's entertained a quartet of Saudi kings over the decades, and presumably MBS won't have that long to wait to complete the full house since Faisal's visit in 1967.

Zimbabwe's authoritarian Robert Mugabe was knighted when he rocked up in 1994. And in 2003, as the second Iraq war began, Buckingham Palace hedged its bets — welcoming Russia's Vladimir Putin in June and US President George W. Bush in November. China's Xi Jinping, Hu Jintao and Jiang Zemin all had their moment on the Mall. Ugandan butcher Idi Amin didn't get a full state visit, but he dined with Elizabeth in 1971.

Redcarpet Markdown Table

On his state visit in 1994, Zimbabwe's Robert Mugabe (right) also met with Prime Minister John Major

Almost all these leaders prompted some kinds of protests. It's no surprise that Trump, with his oversized profile, may draw out larger crowds and more inventive insults. But in truth, it's also a little sad that the golf-obsessed blowhard mobilizes the masses more effectively than some of recent history's genuine villains.

Auto-generating Markdown Tables Of Contents | Alex Harvey

DW recommends





Comments are closed.