How would you pass a class to markdown?

I did hit upon this page, it gave the example for custom named parameters - that left me wondering about how to access the short-form versions {.important #someid}

I’ll just play around with it and see but essentially still not sure if {.important .class1 .class2} get merged to {{ with .Attributes.class }} as the docs don’t cover the short form case. Would be helpful if they touched on this somehow.

Yes, there’s no difference between short form and long form notation

1 Like

Ok thanks, managed to confirm that locally and update my blockquote templates for support of attributes:

_markup/render-blockquote-regular.html

<blockquote {{ with .Attributes.class }}class="{{ . }}" {{ end }} {{ with .Attributes.id }}id="{{ . }}"{{ end }}>
  {{ .Text }}
</blockquote>

_markup/render-blockquote-alert.html

{{ $emojis := dict
"caution" ":exclamation:"
"important" ":exclamation:"
"note" ":pencil:"
"info" ":information:"
"tip" ":bulb:"
"warning" ":warning:"
"danger" ":fire:"
"success" ":white_check_mark:"
}}

<blockquote {{ if .Attributes.class }}class="{{ .AlertType }} {{ . }}" {{ else }}class="{{.AlertType}}" {{ end }} {{
  with .Attributes.id }}id="{{ . }}" {{ end }}>
  <h6 class="alert-heading">
    {{ transform.Emojify (index $emojis .AlertType) }}
    {{ with .AlertTitle }}
    {{ . }}
    {{ else }}
    {{ or (i18n .AlertType) (upper .AlertType) }}
    {{ end }}
  </h6>
  {{ .Text }}
</blockquote>

I’ll poke around the contributions guidelines and workup an update to the docs to touch on this.

To touch on what?

The markdown attribute short forms we just discussed that are not talked about in the templating docs at all, and how to ensure they are also included in templates. Shouldn’t need a lot, but at least a sentence or two. And it would be good to update some of the default templates that were added to the docs before this feature existed so they maintain compatibility with it. IE the cite example and the alert example if used directly as they are presented today break support for this.

I’ve added a paragraph and example to the bottom of this section:
https://gohugo.io/content-management/markdown-attributes/#overview

I believe this is sufficient. I really don’t want to complicate the examples.

2 Likes

Agreed, that covers it and the discovery point is right as you get into the markdown attributes doc :white_check_mark:

Thanks again!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.