gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75.38k stars 7.49k forks source link

Use SGML Processing Instructions to pass arguments to render hooks #6670

Closed bep closed 8 months ago

bep commented 4 years ago

This is just me thinking out loud during Christmas. I kind of like the simplicity of it. The idea is to use SGML Processing Instructions as a way to pass parameters to the new and shiny render hooks in Hugo (images and links).

One example would maybe look like this:

<?params width="400" height="500" ?>
![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")

I suggest that we:

/cc @regisphilibert

regisphilibert commented 4 years ago

Looks promising in the long term. My feeling though is that Markdown will eventually be just one option among the many #6310 will open to Hugo users. So "roadmap wise" I woudn't put this in front of #6310.

bep commented 4 years ago

The road map is also budget constrained. This issue may be easier to finance (cheaper to implement).

jmooring commented 3 years ago

With https://github.com/gohugoio/hugo/commit/cd0c5d7ef32cbd570af00c50ce760452381df64e you can pass arguments (attributes) to heading render hooks:

# My Heading {data-foo="a" data-bar="b"}

The attributes are accessible within the heading render hook via .Attributes.

{{ range $k, $v := .Attributes }}
  {{ $k }} = {{ $v }}<br>
{{ end }}

However, you cannot do the same with either image render hooks or link render hooks because attribute support is limited to headings and blocks (see https://github.com/gohugoio/hugo/commit/2681633db8d340d2dc59cf801419874d572fc704).

celestehorgan commented 2 years ago

I would looooooove this for formatting table columns and the like 🤩

bep commented 2 years ago

@celestehorgan Hugo do have support for CommonMark attributes now (you need to enable it in config), so you should at least be able to set CSS classes on the table element.

dfl commented 2 years ago

With cd0c5d7 you can pass arguments (attributes) to heading render hooks:

# My Heading {data-foo="a" data-bar="b"}

The attributes are accessible within the heading render hook via .Attributes.

{{ range $k, $v := .Attributes }}
  {{ $k }} = {{ $v }}<br>
{{ end }}

However, you cannot do the same with either image render hooks or link render hooks because attribute support is limited to headings and blocks (see 2681633).

I'm really confused because the configuration markup page for render-hook templates says "Attributes (map) New in v0.82.0." under context for render-link and render-image. It really makes logical sense, can't wait for this feature to just simply work out of the box.

chalin commented 8 months ago

Was this closed because it won't be fixed or because it has been implemented? The text above shows "@bep closed this as completed" but I'm not seeing any linked commit or other information that would give evidence of this feature now being supported. Thanks!

bep commented 8 months ago

Was this closed because it won't be fixed or because it has been implemented?

We now have Markdown attributes that solves this:

https://gohugo.io/getting-started/glossary/#markdown-attribute

And yes, I should have commented on this before closing, I sometimes forget that other people watches these issues.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.