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

0.60.0 goldmark: <html> indentation in partial/shortcode wrapped in <pre><code> #6553

Closed
divinerites opened this issue Nov 28, 2019 · 27 comments

Comments

@divinerites
Copy link

divinerites commented Nov 28, 2019

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.60.0/extended darwin/amd64 BuildDate: unknown

Does this issue reproduce with the latest release?

Yes. In lates 0.60.0 using goldmark

  • Following this discourse discussion, confirmed by @onedrawingperday , I fill a bug here
  • Using indentation in partial/shortcode (inline or classic) causes the HTML to be wrapped in code blocks
  • Option [markup.goldmark.renderer] unsafe = true has no effect.
@bep
Copy link
Member

bep commented Nov 28, 2019

@divinerites
Copy link
Author

divinerites commented Nov 28, 2019

Yes, I can understand that indenting with 4 spaces means a code block. No problem.

But I was not expecting that pure HTML/Go-template would be treated like this (it was not with blackFriday).

So, If i read between lines :-) this means that goldmark will treat every 4 spaces as a code block, even for HTML.

So a good prevention measure would be to change "tab->number of space" default in my editor (VSCode) to 3 (at least not 4).

Will look if it changes things. Thanks.

@divinerites
Copy link
Author

Done some testing with 3 spaces.

  • If there is strictly 3 spaces as indentation, the result is OK : HTML is written as is.
  • At the moment where i do 2 indentations (2 x 3) => same problem than before

So I guess that at the moment any HTML code with several indentations (not equal to 3 exactly) will have a problem.
I'll keep testing.

@divinerites
Copy link
Author

So, after testing a bit I can confirm that :

  • HTML in a shortcode (inline or called via a partial) is processed by goldmark as if it was markdown.
  • So if you have ONE indentation of 3 (less than 4) space, it works as HTML. As before.
  • If you have 4 or more spaces (for ex 3+3 or 3+3+3) it is processed by goldmark and identify and rendered as code block.

I understand that Bep was not surprised by this behaviour, which is fine by me if it is expected behaviour.
But I found this quite surprising because i would never expect HTML being impacted by indentation.

Workaround is to flat your HTML code if it could be called by shortcode. Not read friendly but efficient.

cc @onedrawingperday who helped me a lot on this diagnostic.

@bep
Copy link
Member

bep commented Nov 28, 2019

OK, that seems to be a bug in Goldmark. I will create a bug report over there.

I understand that Bep was not surprised by this behaviour,

I didn't say I wasnt surprised, I just pointed to a possible explanation.

@bep bep added this to the v0.60.1 milestone Nov 28, 2019
@bep
Copy link
Member

bep commented Nov 28, 2019

OK; I had a look at this and I don't understand it. The example shows an inline shortcode using {{< which Goldmark should never see. I could understand it if the {{< was indented 4 chars, but that isn't the case. I tested some variants of this myself, and cannot reproduce.

@jensamunch
Copy link

Hi @bep - I'm not sure this should be closed.
#6552

I made a screencast I think you might enjoy. Headless only works when the folder name does NOT match the name I'm calling it with 🤯

https://youtu.be/pRznYM-3Itk

@divinerites
Copy link
Author

Later today, I'll provide access to the repo and prepare 3 pages with 3 different shortcodes/partials with this problem. Stay tuned.

@divinerites
Copy link
Author

divinerites commented Nov 29, 2019

Bep & MooreReason, I invited you to the repo.

  • Use "Migration-en-goldmark" branch.
  • post vintage.fr.md is working fine (partial is flat HTML)
  • post test1.fr.md has problem (partial is fully indented HTML)
  • post test2.fr.md has same problem but different layout because indented a bit differently

First : thanks for your help, and let me know if I can do/test other things.

You can see the 3 post with exactly same code except HTML indentation on the 3 last post here : https://migration-en-goldmark--lagouille.netlify.com/dernieres-nouveautes/

@divinerites
Copy link
Author

And test1/test2.html have 3 space indentation, and still get the problem. Mmmmmmmm

@moorereason
Copy link
Contributor

@divinerites,
Your issue appears to be related to the use of {{ .Content | markdownify }} in layouts/_default/single.html.

@bep bep removed the Bug label Nov 29, 2019
@bep bep modified the milestones: v0.60.1, v0.61 Nov 29, 2019
@divinerites
Copy link
Author

Ahhhh. Yes makes sense. Thanks a lot. I Will take this in account.

So as the behaviour was different with use of blackFriday in 0.59.x, will look forward to see if this is expected behaviour or not and then change my code accordingly to the right practice.
But anyhow i DO thanks you a lot for founding a "reasonable" cause & explanation :-). Thanks.

@XhmikosR
Copy link
Contributor

XhmikosR commented Dec 2, 2019

I think this is the issue I'm hitting in Bootstrap too after updating Hugo.

This worked fine before but now renders invalid HTML:

<div class="bd-example">
  <table class="table">
    <thead>
      <tr>
        <th scope="col">Class</th>
        <th scope="col">Heading</th>
        <th scope="col">Heading</th>
      </tr>
    </thead>
    <tbody>
      <tr class="table-active">
        <th scope="row">Active</th>
        <td>Cell</td>
        <td>Cell</td>
      </tr>
      <tr>
        <th scope="row">Default</th>
        <td>Cell</td>
        <td>Cell</td>
      </tr>

      {{< table.inline >}}
      {{- range (index $.Site.Data "theme-colors") }}
      <tr class="table-{{ .name }}">
        <th scope="row">{{ .name | title }}</th>
        <td>Cell</td>
        <td>Cell</td>
      </tr>
      {{- end -}}
      {{< /table.inline >}}
    </tbody>
  </table>
</div>

@ahmetb
Copy link

ahmetb commented Dec 2, 2019

Also hitting this after updating to v0.60.0. If you use {% %} syntax while invoking shortcodes, HTML tags inside the shortcodes are stripped off.

For example, shortcodes/details.html:

<details>
<summary>{{with .Get "title" }}{{.}}{{else}}Click to expand{{end}}</summary>
{{.Inner}}
</details>

Usage:

{{% details title="foo" %}}
bar
{{% /details %}}

Generated HTML Output:

<p>foo</p>
<!-- raw HTML omitted -->
<p>hello world</p>
<!-- raw HTML omitted -->

@moorereason
Copy link
Contributor

@XhmikosR, how does that render?

@ahmetb, are you enabling unsafe in Goldmark?

@XhmikosR
Copy link
Contributor

XhmikosR commented Dec 2, 2019

@moorereason <pre><code> inside the HTML with unclosed div tags. I'll be able to provide the exact snippet tomorrow since for now I just reduced indentation to work around this issue https://github.com/twbs/bootstrap/pull/29750/files#diff-dcbb1aeb2504a4b02de5c00ba0296ceb

@ahmetb
Copy link

ahmetb commented Dec 2, 2019

@ahmetb, are you enabling unsafe in Goldmark?

First time I'm hearing about Goldmark and the goldmark: configuration.

I don't have markdown: key in my config.yaml and actually things work fine when I downgrade to v0.59.1. Was I relying on undocumenting behavior previously?

@ahmetb
Copy link

ahmetb commented Dec 2, 2019

...to add to my previous comment:

I did not realize Blackfriday was replaced with Goldmark.

My Blackfriday config also did not have any relevant keys with respect to unsafe html.

@bep bep modified the milestones: v0.67, v0.68 Mar 9, 2020
XhmikosR added a commit to twbs/bootstrap that referenced this issue Mar 19, 2020
* Fix commonmark syntax

related gohugoio/hugo#6553

* Fix indentation

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
@bep bep modified the milestones: v0.68, v0.69 Mar 20, 2020
@bep bep modified the milestones: v0.69, v0.70 Apr 8, 2020
@bep bep modified the milestones: v0.70, v0.71 Apr 28, 2020
@bep bep modified the milestones: v0.71, v0.72 May 18, 2020
@bep bep modified the milestones: v0.72, v0.73 May 31, 2020
@bep bep modified the milestones: v0.73, v0.74 Jun 23, 2020
@bep bep modified the milestones: v0.74, v0.75 Jul 13, 2020
@bep bep modified the milestones: v0.75, v0.76 Sep 14, 2020
olsza pushed a commit to olsza/bootstrap that referenced this issue Oct 3, 2020
* Fix commonmark syntax

related gohugoio/hugo#6553

* Fix indentation

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
@bep bep modified the milestones: v0.76, v0.77 Oct 6, 2020
@bep bep modified the milestones: v0.77, v0.78 Oct 30, 2020
@jmooring
Copy link
Member

Closing. The only way to reproduce the original problem is by erroneously piping .Content through markdownify as noted by @moorereason in #6553 (comment).

Simplified test site:

git clone --single-branch -b hugo-github-issue-6553 https://github.com/jmooring/hugo-testing hugo-github-issue-6553
cd hugo-github-issue-6553
hugo server

@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 Jan 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants