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

Incomplete HTML in .AlertTitle and .Text of Blockquote render hooks #12913

Open
Lruihao opened this issue Oct 8, 2024 · 1 comment
Open

Incomplete HTML in .AlertTitle and .Text of Blockquote render hooks #12913

Lruihao opened this issue Oct 8, 2024 · 1 comment
Labels
Milestone

Comments

@Lruihao
Copy link

Lruihao commented Oct 8, 2024

Reproduce Steps

Given the following Markdown:

> [!NOTE] Hugo

> [!NOTE] _Hugo_
> The world’s fastest framework for building websites

> [!NOTE] **Hugo**

> [!TIP] **Hugo** FixIt

and the following render-blockquote-alert.html

{{ warnf "%s\t%s" .AlertTitle .Text }}

Actual results is .AlertTitle lost the trailing > and .Text in a start <p> without a closing tag:

WARN  Hugo      <p>
WARN  <em>Hugo</em      <p>The world’s fastest framework for building websites</p>
WARN  <strong>Hugo</strong      <p>
WARN  <strong>Hugo</strong> FixIt       <p>

Expected results (complete .AlertTitle and .Text):

WARN  Hugo      <p></p>
WARN  <em>Hugo</em>      <p>The world’s fastest framework for building websites</p>
WARN  <strong>Hugo</strong>      <p></p>
WARN  <strong>Hugo</strong> FixIt       <p></p>

BTW, if content body of alert is empty, .Text return nil seems better.

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

hugo v0.135.0+extended darwin/arm64 BuildDate=2024-09-27T13:17:08Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes

@Lruihao
Copy link
Author

Lruihao commented Oct 9, 2024

@bep Excuse me, could you take a look at this issue, please! 🙏

I think these problems should be in the following two places, but I am not familiar with go and don't know how to correct them. Can anyone help me?

if typ == typeAlert {
// Trim preamble: <p>[!NOTE]<br>\n but preserve leading paragraph.
// We could possibly complicate this by moving this to the parser, but
// keep it simple for now.
text = "<p>" + text[strings.Index(text, "\n")+1:]
}

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 {
title := strings.TrimSpace(m[3])
title = strings.TrimRight(title, "</p>")
return blockQuoteAlert{
typ: strings.ToLower(m[1]),
sign: m[2],
title: title,
}
}
return blockQuoteAlert{}
}

@bep bep removed the NeedsTriage label Oct 13, 2024
@bep bep added this to the Unscheduled milestone Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
@bep @Lruihao and others