Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make p tags optional for render-image to enable use of figure elements #10492

Closed
andrewd72 opened this issue Dec 3, 2022 · 3 comments · Fixed by #10493
Closed

Make p tags optional for render-image to enable use of figure elements #10492

andrewd72 opened this issue Dec 3, 2022 · 3 comments · Fixed by #10493

Comments

@andrewd72
Copy link

Hello!
I'd like a config option to turn off the wrapping of markdown images with p tags.
I wanted to give my perspective and experience dealing with the way it currently works as a new Hugo user with photography blogs.

There was some discussion here:
-->](#6748 (comment))

It came down to this (and was closed):
"In this issue's original example, the render hook for a markdown image was coded to return a figure. This seems like we are hijacking the render hook, asking it do something for which it was not designed."
I disagree.

An image is an image

When writing my markdown content I just want to be able to add an image.
Having the render hooks in hugo is awesome, I could make figure elements from my existing content files with a simple template, awesome. An image is now the same image but can have retina, webp, responsive versions.

I just get them wrapped in unwanted p tags.

Being able to override the p tag wrapping would be to:

"override certain parts of the default Markdown rendering"
(Hugo docs description of a render hook)

Shortcodes are not the answer

the suggestion in the issue linked above was to use shortcodes
i) I have hundreds of articles with a few thousand images between them, swapping markdown image to shortcodes would have to be done programmatically or take weeks.
ii) the idea of having my content as markdown was to make it platform independent and it worked
iii) shortcodes don't show the content if you write with a markdown app with a preview

Coming from grav

I had the same issue in grav but there is a solution with a plugin which makes images into figure elements and it removes the p tags e.g.
-->](https://github.com/OleVik/grav-plugin-imgcaptions)
I don't think it can be just me with a need for this, trying to come up with a solution to match what I could do with grav I found people with solutions to strip p tags from images in other projects e.g. jekyll and wordpress

Workaround

I've spent quite some time trying to work around this.
This is what I came up with for a workaround (seemed simpler than some suggestions)
i) Since we get an unwanted

before the figure I close it immediately by starting the render hook with


And do the same idea at the end, finishing with

which gets wrapped in the unwanted


ii) I use a grunt task to remove /

\n?</p> from all the html files in the public folder

Thanks for your time.

@bep bep removed the NeedsTriage label Dec 3, 2022
@bep bep added this to the v0.108.0 milestone Dec 3, 2022
@bep
Copy link
Member

bep commented Dec 3, 2022

Somewhat related #8362

bep added a commit to bep/hugo that referenced this issue Dec 3, 2022
This both:

* Removes any surrounding <p> nodes
* And transfers any attributes from the surrounding <p> down to the image node

Closes gohugoio#8362
Fixes gohugoio#10492
bep added a commit to bep/hugo that referenced this issue Dec 3, 2022
This both:

* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node

Closes gohugoio#8362
Fixes gohugoio#10492
@bep bep added Enhancement and removed Proposal labels Dec 3, 2022
bep added a commit to bep/hugo that referenced this issue Dec 3, 2022
This both:

* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node

Closes gohugoio#8362
Fixes gohugoio#10492
bep added a commit to bep/hugo that referenced this issue Dec 4, 2022
* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node
* Adds a new IsBlock field to the link context passed to the render hooks, only set for images.

IsBlock is set to true if the image's parent node has only one child.

Closes gohugoio#8362
Fixes gohugoio#10492
Fixes gohugoio#10494
bep added a commit to bep/hugo that referenced this issue Dec 4, 2022
* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node
* Adds a new IsBlock field to the link context passed to the render hooks, only set for images.

IsBlock is set to true if `wrapStandAloneImageWithinParagraph = false` and  the image's parent node has only one child.

Closes gohugoio#8362
Fixes gohugoio#10492
Fixes gohugoio#10494
bep added a commit to bep/hugo that referenced this issue Dec 5, 2022
* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node
* Adds IsBlock and Ordinal (zero based) field to the image context passed to the image render hooks

IsBlock is set to true if `wrapStandAloneImageWithinParagraph = false` and  the image's parent node has only one child.

Closes gohugoio#8362
Fixes gohugoio#10492
Fixes gohugoio#10494
Fixes gohugoio#10501
@bep bep closed this as completed in #10493 Dec 5, 2022
bep added a commit that referenced this issue Dec 5, 2022
* Removes any surrounding paragraph nodes
* And transfers any attributes from the surrounding paragraph down to the image node
* Adds IsBlock and Ordinal (zero based) field to the image context passed to the image render hooks

IsBlock is set to true if `wrapStandAloneImageWithinParagraph = false` and  the image's parent node has only one child.

Closes #8362
Fixes #10492
Fixes #10494
Fixes #10501
@andrewd72
Copy link
Author

Amazing, look forward to testing it out.
I am really enjoying working with hugo and to have this is the icing on the cake.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants