Hugo: Support for Kramdown/Maruku attribute lists in markdown files

Created on 17 Nov 2015  路  8Comments  路  Source: gohugoio/hugo

Attribute lists are a great way of being able to customize the HTML attributes (class and id), and thus the visual style of the rendered markdown.

Here are some examples:

A simple paragraph with an ID attribute.
{: #para-one}

> A blockquote with a title
{:title="The blockquote title"}
{: #myid}
This *is*{:.underline} some `code`{:#id}{:.class}.

A [link](test.html){:rel='something'} and some **tools**{:.tools}.

It's supported by both Kramdown and Maruku. Would it be possible to add them to Hugo's parser as well?

Enhancement Stale Upstream Wish

Most helpful comment

@msimanga 's solution almost worked for me, but I had to change markdownify to safeHTML, otherwise some HTML tags would be stripped (e.g. first paragraph's <p> tags). I'm new to Hugo but I'm guessing HTML was being run through markdownify twice.

{{ replace .Content "<table>" "<table class='table'>" | safeHTML }}

All 8 comments

Hugo's parser is mainly Blackfriday (there are some alternatives, but that is the main).

So if you could create a similar issue at

https://github.com/russross/blackfriday

That would make it more likely that this will happen. Please post a reference back to this issue so we can track it.

Thanks @bep

Hope this will help someone. I had similar challenge, I needed to add class="table" to all <table> tags for Bootstrap styling to take effect. Using Hugo v0.16 I used the _replace_ function.

Before
{{ .Content }}

After
{{ replace .Content "<table>" "<table class='table'>" | markdownify }}

I have a very small site so performance isn't an issue with me.

This issue has been automatically marked as stale because it has not been commented on for at least four months.

The resources of the Hugo team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still valuable, please open a proposal at https://discuss.gohugo.io/.

This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions.

Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't.

If this is a bug and you can still reproduce this error on the latest release or the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.

@msimanga 's solution almost worked for me, but I had to change markdownify to safeHTML, otherwise some HTML tags would be stripped (e.g. first paragraph's <p> tags). I'm new to Hugo but I'm guessing HTML was being run through markdownify twice.

{{ replace .Content "<table>" "<table class='table'>" | safeHTML }}

This would be super useful, e.g. extending HTML lists with js to work a bit like workflowy and identifying which lists by adding a "workflowy" class, or to set the width/height of an image without having to resort to HTML, etc.

{{ replace .Content "<table>" "<table class='table'>" | markdownify }}

Is it possible to use a regex in replace? I'm moving from nanoc to hugo and I really miss the flexibility of Kramdown.

Was this page helpful?
0 / 5 - 0 ratings