-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Shortcode output wrapped in <p> tags under certain conditions #1642
Comments
As another participant in this discussion on discuss.gohugo.io, I can second that I see the above behaviour. I'm also willing to help continue debugging this. |
Am a new user... really appreciate the project, is incredibly elegant. Would really like to see bug fixed :) |
Deliberetely made to pass, even if they (probably) should not. See #1642
See 1ce184b These test cases are deliberately made green, even if they (probably) should not. Test case 1-3:
|
We ran into this as well. We also had the problem, that a markdown list of shortcodes inserted a wrong closing p-tag after an image from within the shortcode. Would it eventually make sense introduce a param or something like that, that prevents hugo from wrapping shortcode in p-tags? |
@AnBauer Hugo doesn't add any p-tags, we actually try to remove them ... This is coming from Blackfriday (the Markdown engine) ... so a flag wouldn't help ... |
You meant p-tags, didn't you? OK, I thought "shortcode output gets wrapped in a P-tag" is a thing, hugo does. Thanks for clarification! |
Yes. |
I also have this issue, although its behaviour is better on Hugo 0.15 but does happen when multiple shortcodes are used on the same page (as already mentioned above). Would love to see Hugo fix the Blackfriday output that adds those 's is that's possible. |
First, a workaround: Create a shortcode
Then wrap your shortcode sections in that:
To be even more protective, wrap it in a div:
I think Hugo should do two things:
/cc @halostatue @spf13 |
Currently, i have the same problem and i for me the workaround does not work properly. Is there any progress from the hugo-team? |
@ahausamm what is the problem with my workaround? |
@bep For me, it works only with the before the shortcodes, the {{ wrap }} does not change anything. But i don't want to have some HTML in the markdown, do you have an example of your working workaround?
gives me this output (first table seems to be okay, second has the around:
Any ideas? |
@ahausamm use plain HTML tables and the {{< -- your use case was not my intented target for my "workaround" ... and It looks like a hack. |
@bep okay, thanks for your answer. For me, plain HTML isn't the right solution (for the moment) because i want to have some custom section with custom templates. So i will try another way or simply wait on the next update of hugo. |
the workaround from @bep came unfortunately too late for my project, because we already have tons of mds with tons shortcodes in it. what I did was creating a grunt-task, which simply removes all wrong p-tags with a regex :-) |
In my case a temporary workaround is to wrap each shortcode in a block-element for example a div
FYI |
I think, the workaround of @maxxscho would be the best workaround for this problem. I had another nice discussion about this problem in the gohugo-forum: https://discuss.gohugo.io/t/single-page-with-nested-content/2645 |
@maxxscho: nice idea. Unfortunately I have multiple shortcodes already consisting of block elements. And I didn't want html-code in the md files or needless nesting.
|
As I think I said before, these "workarounds" should be included in the Hugo core. If we have to add a I will do it ... once I get some spare time. |
@AnBauer: nice one. Can you show me your gulp task, with handles the replacement? :) |
@maxxscho i think he uses gulp-replace-task (https://www.npmjs.com/package/gulp-replace-task). @AnBauer please correct me if i'm wrong. |
@AnBauer actually im wondering how i can use gulp with hugo server -w to create valid html code and replace the "shortcoddmistakes" |
I'm using grunt for that. But it should be nearly the same with gulp. Important is to htmlmin before replacing, so all line breaks are deleted. The config for grunt-replace looks like:
The elements in the regex depend on the project, of course. E.g. I also use angular material, so I needed md-content. @ahausamm: I have a custom "hugo" - task. When this one ran follows htmlmin and then replacing. |
This issue has been automatically marked as stale because it has not been commented on for at least four months. The resources of the Hugo team are limited, and so we are asking for your help. If this is a bug and you can still reproduce this error on the If this is a feature request, and you feel that it is still valuable, please open a proposal at https://discuss.gohugo.io/. This issue will automatically be closed in four months if no further activity occurs. Thank you for all your contributions. |
Note/Update: This issue is marked as stale, and I may have said something earlier about "opening a thread on the discussion forum". Please don't. If this is a bug and you can still reproduce this error on the latest If this is a feature request, and you feel that it is still relevant and valuable, please tell us why. |
Thanks for Hugo, I'm still a Hugo n00b, but I can confirm that I have this problem, about the p-wrapping. Hugo version: shortcodes/aaa.html: <div class="aaa">
This is the aaa shortcode
</div> shortcodes/aab.html: <div class="aab">
This is the aab shortcode.
{{ .Inner }}
</div> page.md variant 1: +++
+++
{{% aaa %}}
{{% aab %}}
My Markdown content goes here
{{% /aab %}} Output 1: <p><div class="aaa">
This is the aaa shortcode
</div>
<div class="aab">
This is the aab shortcode.
<p>My Markdown content goes here</p>
</div>
</p> page.md variant 2: +++
+++
{{% aaa %}}
{{% aab %}}
My Markdown content goes here
{{% /aab %}} Output 2: <div class="aaa">
This is the aaa shortcode
</div>
<p><div class="aab">
This is the aab shortcode.
<p>My Markdown content goes here</p>
</div>
</p> As you can see by inserting newlines I can move the P wrapping around, but I can't get rid of it in a sane manner. Again, thanks for working on Hugo, it's awesome. |
I can also confirm that this issue still happens on Hugo 0.19. Like Thomas mentioned above, the issue in my case also happens when 'irregular' text is used inside a shortcode. With that, I mean that this text without line endings gives no problem:
Renders as:
Going beyond regular text in the shortcode introduces the additional
Renders the invalid HTML (according to the w3.org validator) of:
Likewise, the shortcode use like shown below also generates the invalid
From my understanding, the
|
That’s Markdown, not Hugo, no? If you want to use inline shortcodes, I would recommend using the |
Maybe it's the Markdown engine. When I say "Hugo", I really just mean "Hugo and all of its internals and dependencies". I'm a newcomer to this issue and haven't been following it until now, but I did search around before and I came across old issues where a blocks/inline option was being discussed for the Markdown processor, and apparently in the end it was set up so that Hugo removes generated paragraphs from the Markdown output if the Markdown is one line. Perhaps I'm mistaken, but that's what I was referring to when I said "Hugo seems to see the line breaks as a trigger..." and "Hugo needs to ignore whitespace-only blocks when deciding...". I might be misunderstanding things though. If by |
I see @ChrisTucker2000 @Jos512 . It was only a question since I haven't been involved in Hugo much for the past half year 😄
Maybe something like this for a param in the |
Here's another simple way to reproduce this issue (using hugo v0.42.2):
Resulting html:
In this case, any of the following prevents the
|
This bug is still present in 0.46 and none of the above workarounds seem to work for me. I am using sections in my shortcodes and placing them in p makes the markup invalid - which definitely is a showstopper. Does anyone have a pointer to the regex that is supposed to insert these p's? |
Complex designs are always messed up because of this. |
What a shame... but still, ancient template toolkit (TT2) never had problems like this. Might as well migrate back again. |
FYI: mmark shows the same behaviour. If it really is a bug in blackfriday and not hugo itself, it has been in there for a long time, as mmark started off as a fork of blackfriday and has not seen much development in the last couple of years. |
And, for the record: Same problem with using pandoc instead of blackfriday. At this point I am pretty sure the problem has its roots in hugo itself. |
I was happy to see this bug fixed in 0.47. This corrected several cases of To repro, grab https://github.com/istio.github.io at commit be7c374f297a712fb6e5cd1be98b656a3b52732f and build the site with Hugo 0.47. This is where the error occurs:
|
The problem with our content is that there was an extra period after a closing shortcode: {{< text >}} where
which is invalid HTML. Removing the period in the markdown fixed the problem. |
In some cases reported above and in my own case, Hugo wraps the second shortcode with
the markdown will be converted to the following:
A simple workaround for this case is (1) define an empty shortcode like this:
and (2) put the shortcode as the second shortcode.
|
Following the trail of issues and discussions of shortcodes and |
@clutterstack. With closed issues, you're likely to get very little (if any) feedback. I would recommend taking your issue to the forums at https://discourse.gohugo.io and get feedback directly from other Hugo users. |
@clutterstack pls. see this discussion: https://discourse.gohugo.io/t/solved-empty-p-before-and-after-plain-html-in-markdown-files/5559 You must handle your shortcodes like block elements. |
@rdwatters @christophlieck Thanks for your comments -- in fact, I hadn't expected any feedback! I'm sure I've done something simple wrong in my own theme templates. I commented because my comment would been helpful to me, had I seen one like it in my prior searches. It took me some time to discover that my problem was not with my shortcode or the way I was using it in markdown files. |
I just came across this when looking for a solution to remove elements from around the {{ .Content }} when it is generated. it seem hugo or blackfriday assumes you need these. I am using hugo to generate a site. I have BODY element wrapped in my markdown file at the start and finish in each md file. not really using hugo for mark down but for keeping html code in every file so it will generate a site with header and footers in every file. To remove those annoying PARAGRAPH elements for a generated site i find a sed command on linux in my hugo project. This will remove the paragraph elements. I have to do this every time i generate the site. Here are the commands I use.
|
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. |
Previous related issue 'Shortcode output wrapped in
<p>
tags' #1148 which was closed with 004fcdd.Consistent incorrect wrapping of shortcode output under certain conditions
Reported in discuss forum here.
Salient points:
If there is just one shortcode, it doesn't get wrapped in
<p>
tagsIf there are multiple shortcodes, the first doesn't get wrapped in
<p>
tags (probably related to above)In order to ensure no shortcodes are wrapped in
<p>
tags, the final shortcode must be followed by a number of distinct<p>
tag wrapped lines proportionate to the number of shortcodes in the document.By that I mean if you have say 6 shortcodes one after the other, you need 16 lines following them in order for none to be wrapped in
<p>
tags. If you have 5 shortcodes one after the other you need 12 lines.'Lines following shortcode' don't have to come at the end of the document, if you have a series of shortcodes it seems the number of interceeding
<p>
tag wrapped lines are cumulatively ranked towards each consecutive shortcode so if you had 30 lines interspaced between shortcodes throughout the document, as long as each shortcode has at least 5 proceeding lines each, they'll all be spared wrapping.Related to point 4, the
<p>
tags that get wrapped around shortcodes incorrectly also count towards the number of<p>
tag wrapped lines needed to follow preceeding shortcodes - so enough shortcodes in a row and you seem to be about to start unwrapping some of the 'first' few in the list.Length of shortcode title attribute also affects whether output wrapped in
<p>
tags though this has not been investigated in detailNOTE - I may have miss counted the exact number of lines in between shortcodes, my eyes were actually bleeding...
The text was updated successfully, but these errors were encountered: