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

Some Obsidian styled alerts result in invalid HTML #12828

Closed
McShelby opened this issue Sep 4, 2024 · 4 comments
Closed

Some Obsidian styled alerts result in invalid HTML #12828

McShelby opened this issue Sep 4, 2024 · 4 comments
Assignees
Milestone

Comments

@McShelby
Copy link

McShelby commented Sep 4, 2024

Given the following Markdown:

> [!caution] Callouts can have custom titles
> Like this one.

> [!caution] Title-only callout

> [!note]- Are callouts foldable?
> Yes! In a foldable callout, the contents are hidden when the callout is collapsed

> [!note]+ Are callouts foldable?
> Yes! In a foldable callout, the contents are hidden when the callout is collapsed

> [!info] Can callouts be nested?
> > [!important] Yes!, they can.
> > > [!tip]  You can even use multiple layers of nesting.

and the following render-blockquote.html

{{ warnf "%s" .AlertTitle }}

somtimes results in a closing </p> at the end of the title

WARN  Callouts can have custom titles
WARN  Title-only callout</p>
WARN  Are callouts foldable?
WARN  You can even use multiple layers of nesting.</p>
WARN  Yes!, they can.</p>
WARN  Can callouts be nested?</p>

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

$ hugo version
hugo v0.134.0-77df7bbbff8ce6b56ed693270088de973a87d5ce+extended windows/amd64 BuildDate=2024-09-03T09:54:22Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

@bep bep self-assigned this Sep 4, 2024
@bep bep removed the NeedsTriage label Sep 4, 2024
@bep bep added this to the v0.134.1 milestone Sep 4, 2024
@LicketySpliket
Copy link

Not a super frequent contributor to Hugo, but I think the issue is in the following lines:

(blockquotes.go:162)

var blockQuoteAlertRe = regexp.MustCompile(`^<p>\[!([a-zA-Z]+)\](-|\+)?[^\S\r\n]?([^\n]*)\n?`)

func resolveBlockQuoteAlert(s string) blockQuoteAlert {
	m := blockQuoteAlertRe.FindStringSubmatch(s)
	if len(m) == 4 {
		return blockQuoteAlert{
			typ:   strings.ToLower(m[1]),
			sign:  m[2],
			title: m[3],
		}
	}

	return blockQuoteAlert{}
}

This Regex terminates the title group at \n, not </p>, so the </p> gets included and passed to the renderer. I fixed it by using this Regex: ^<p>\[!([a-zA-Z]+)\](-|\+)?[^\S\r\n]?([^(\n|<\/p>)]*)\n?. It checks for termination of the title group at both \n and </p>.

@bep
Copy link
Member

bep commented Sep 5, 2024

@LicketySpliket thanks, I tested your regexp, and it didn't pass all the test cases. I opted for a ... simplar non-regexp approach.

bep added a commit that referenced this issue Sep 5, 2024
bep added a commit that referenced this issue Sep 5, 2024
Also remove test references to deprecated funcs now in ERROR.

Closes #12828
@bep bep closed this as completed in 66a3a11 Sep 5, 2024
@LicketySpliket
Copy link

No worries bep, thanks for testing it.

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 Sep 27, 2024
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

3 participants