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

Transfer paragraph attributes to image when used as a block #8362

Closed
bep opened this issue Mar 25, 2021 · 5 comments · Fixed by #10493
Closed

Transfer paragraph attributes to image when used as a block #8362

bep opened this issue Mar 25, 2021 · 5 comments · Fixed by #10493

Comments

@bep
Copy link
Member

bep commented Mar 25, 2021

See discussion in https://discourse.gohugo.io/t/is-it-possible-to-use-attribute-lists-with-render-hooks/31374/6?u=bep

So, images are by definition an inline element, but it most typically is used in block contexts, e.g.:

This is some text.

![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1")
{ .myclass }

And then some more text.

I have not tested the above, but I suspect that the attributes list { .myclass } will be applied to the surround paragraph block.

Since the parsing complexity prevents us from adding attributes to links/images, an option may be to transfer the surrounding block's attributes to the image.

We can certainly have an option to toggle this off, but I suspect that most people would say that the attribute above belongs to the image and not the paragraph.

Thoughts?

@bep bep added the Proposal label Mar 25, 2021
@bep bep added this to the v0.83 milestone Mar 25, 2021
@HenrySkup
Copy link

For images that are treated as blocks this make sense.

but it does raise the question of what the config option should be... such as:

  • "treat images as blocks"
  • "treat "orphan" images as blocks"
  • "treat images with attributes as blocks"

Just a thought:
Would it be possible to do something similar to how footnotes are treated for inline elements ( and )? would that help with the parsing complexity?

@bep
Copy link
Member Author

bep commented Mar 25, 2021

@HenrySkup thanks for your input.

  1. As to the config option, I think it should be very specific. We're not "treating images as blocks" -- they're still an inline element that happens to be surrounded by a block (paragraph). So, something ala moveParagraphAttributesToImageBlocks or ... something.

  2. I don't understand the footnote reference, but when working with Goldmark, it's much easier to reason with its AST (instead of the actual markdown text) and say stuff ala "if an image is the only child of a paragraph, then ...".

@HenrySkup
Copy link

2. I don't understand the footnote reference, but when working with Goldmark, it's much easier to reason with its AST (instead of the actual markdown text) and say stuff ala "if an image is the only child of a paragraph, then ...".

I was thinking about something like:

This would be some normal text. ![alt](url "title){^1} Bla bla bla.


{^1}: attribute list

but I now realize that this would prob be just as difficult and quite a departure from markdown syntax.

However on the forum @jmooring made an excellent comment. An i realized that I too had hacked together a render hook for this... though haven't been using it...

Gist here.

If I remember correctly, there were some issues creating a properly formatted HTML string.

@HenrySkup
Copy link

2. I don't understand the footnote reference, but when working with Goldmark, it's much easier to reason with its AST (instead of the actual markdown text) and say stuff ala "if an image is the only child of a paragraph, then ...".

Just found this in the common mark spec, which is kind of what I meant... i think.

@bep bep modified the milestones: v0.83, v0.84 May 1, 2021
@bep bep modified the milestones: v0.84, v0.85 Jun 18, 2021
@bep bep modified the milestones: v0.85, v0.86 Jul 5, 2021
@bep bep modified the milestones: v0.86, v0.87, v0.88 Jul 26, 2021
@bep bep modified the milestones: v0.88, v0.89 Sep 2, 2021
@bep bep modified the milestones: v0.89, v0.90 Nov 2, 2021
@bep bep modified the milestones: v0.90, v0.91.0 Dec 13, 2021
@bep bep modified the milestones: v0.91.0, v0.92.0 Dec 22, 2021
@bep bep modified the milestones: v0.92.0, v0.93.0 Jan 12, 2022
@bep bep modified the milestones: v0.93.0, v0.94.0 Mar 1, 2022
@bep bep modified the milestones: v0.94.0, v0.95.0 Mar 9, 2022
@bep bep added this to the v0.100.0 milestone May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.104.0, v0.105.0 Sep 23, 2022
@bep bep modified the milestones: v0.105.0, v0.106.0 Oct 26, 2022
@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Dec 3, 2022
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 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
@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