How are you adding citation to blockquotes?

Since Hugo disables inline HTML by default, which methods are y’all using to add citation? So far, I have found the two ways below. (The second one looks more promising).

  1. With a render hook
  1. With replaceRE

I think you want to show HTML?

in the MD files:

```HTML
<link rel=stylesheet href=/dark.css  media="(prefers-color-scheme: dark)">
<link rel=stylesheet href=/light.css media="(prefers-color-scheme: light)">
<link rel=stylesheet href=/main.css>
````

my render-codeblock.html

{{ $class   := .Attributes.class | default ""    }}
{{ $lang    := .Attributes.lang  | default .Type }}
{{ if transform.CanHighlight $lang }}
<div class="code {{ $class }}">{{ highlight .Inner $lang }}</div>
{{else}}
<pre><code class=" code {{ $class }}">{{.Inner}}</code></pre>
{{end}}

sometimes I use a shortcode to insert a file

<div>
  {{ $file := .Page.File.Path }}
  {{ $lang := path.Ext .Page.File.Path }}
  {{ if gt (len .Params) 0 -}}
  {{ $lang = .Get 1 | default "text"}}
  {{ $file = .Get 0 }}
  {{- end -}}
  {{ $file = readFile $file }}
  {{ highlight $file $lang "linenos=table" }}
</div>

hope this help to find your solution

No. But to include <cite>lorem ipsum</cite> in my blockquotes where applicable without enabling unsafe: true in the markdown parser.

I asked once to create a markup-render-hook for blockquote but it was somehow swatted down as not something the system needs. So I created my own shortcode for this. There is no Markdown-way to add cite attributes to blockquote tags. I did not “re-visit” the issue for some years now, it might have changed. My shortcode is the following setup:

layouts/shortcodes/quote.html

<blockquote class="blockquote">
	{{.Inner}}
    {{ if .Get "source" }}
    <footer class="blockquote-footer">
		<cite title="Quelle: {{ with .Get "source"}}{{.}}{{ end }}">
            {{ with .Get "src"}}
                Weiterlesen auf
                <a href="{{.}}" target="_blank" rel="noopener noreferrer">
            {{ end }}
            {{ with .Get "source" }}{{.}}{{ end }}
            {{ with .Get "src"}}
                </a>
            {{ end }}
		</cite>
	</footer>
    {{ end }}
</blockquote>

call this in your markdown files via:

Something something

{{< quote source="the guy who said it" src="https://alinktotheguywhosaidit.com" >}}
the quote
{{< /quote >}}

There are some optimizations in there (like the src-attribute for an URL and (my fault), plenty of German phrases), so you probably want to re-create the shortcode instead of just copying it.

It’s more work, but this is the way Hugo can add cite tags to your blockquotes (for now), because… it can’t (add cite tags to your blockquotes).

1 Like

I will take this for a spin.

what’s wrong with your render hook ? I found it genius, and adopted it.

I went with this option after much testing

security issue ?
I can understand, I needed the unsafe setting to add <cite> and <q>. But how does it relate with the render hook method ? No need for unsafe = true and it’s much more elegant than using shortcodes

Please read this:
https://gohugo.io/about/security-model/#web-application-security

Templates authors (you) are trusted, but the data you send in is not.

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