Skip to content

A better alert shortcode more markdown friendly - #941

Merged
chalin merged 9 commits into
docsy:mainfrom
chalin:chalin-gitpod-alert-rework-2022-03-21
Jun 12, 2025
Merged

chalin merged 9 commits into
docsy:mainfrom
chalin:chalin-gitpod-alert-rework-2022-03-21

Conversation

@chalin

@chalin chalin commented Mar 21, 2022 •

Copy link
Copy Markdown
Collaborator

This doesn't offer as clean a solution as I would have liked, but I feel that it is a step in the right direction. Note that this will introduce a breaking change. I'll continue to explore if/how this shortcode can further be simplified -- ideally, so that we can avoid the use of the markdownify shortcode argument -- but any further changes will be submitted through another PR.

Edit 2025-06-10: got it to work the way I want. See the UG alert section for details.

Preview

Screenshot

image

@chalin
chalin force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch from b0f82c2 to 2996bd1 Compare March 28, 2022 20:17
@chalin
chalin marked this pull request as draft August 1, 2022 15:26
@deining
deining force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch from 2996bd1 to e3b96d6 Compare February 10, 2023 09:26
@deining

deining commented Feb 10, 2023

Copy link
Copy Markdown
Contributor

I'll continue to explore if/how this shortcode can further be simplified -- ideally, so that we can avoid the use of the markdownify shortcode argument

I rebased your PR to HEAD of repo and added a second commit, that exactly does what you wished/proposed: discarding/avoiding the shortcode argument markdownify.

This topic is a bit tricky: the key to the solution is the common mark spec:

An HTML block is a group of lines that is treated as raw HTML
...
It ends with the first subsequent line that meets a matching end condition

We do introduce html blocks with our shortcode, so if we want to get our markup evaluated, we have to make sure that within our shortcode, an end condition for the introduced html block is met again. The easiest way to fulfill the end condition is to insert a blank line (number 7 in the spec), and that's exactly what my second commit does.

The irony is that the solution proposed with your first commit worked quite well already (were you aware of that?). In the end my second commit is only a reinforcement of your original approach in the sense that it now allows even corner cases like:

{{% alert title="Note" color="info" %}}**Bold** content{{% /alert %}}

that weren't covered with your first approach. Everything else did work already (even without shortcode argument markdownify!).

but any further changes will be submitted through another PR.

I hope my change is small enough to justify adding a second commit here.

I now wonder whether you still considering this a breaking change? I hope we can finalize this issue soon, I don't think we can do any better here.

@fekete-robert

Copy link
Copy Markdown
Contributor

Hi, since you are already working on this shortcode, I'd suggest getting rid of the h4 heading, and replacing it with a non-heading styling. Currently such alerts can appear in the page-level toc, and they also break the heading structure (for example, a h4 heading from the alert appears under a h2 heading), which is against best practices.

@deining
deining marked this pull request as ready for review February 10, 2023 13:33
@deining

deining commented Feb 10, 2023

Copy link
Copy Markdown
Contributor

I'd suggest getting rid of the h4 heading, and replacing it with a non-heading styling.

Great suggestion, done.

@fekete-robert: can you comment on/review this PR?

@fekete-robert

Copy link
Copy Markdown
Contributor

I'm swamped by work right now, but I hope to take a look during the weekend

@fekete-robert fekete-robert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work fine to me, thanks!

@chalin

chalin commented Aug 18, 2023

Copy link
Copy Markdown
Collaborator Author

Thanks for the updates @deining. I've revisited this PR, making the following adjustments:

  • Recovered the .h4 styling of the alert header, without making it heading element
  • Changed the shortcode file suffix to .md

Note that I still can't get the alert shortcode to play well when used in lists, for example. I'm unsure if this is a Hugo bug/feature or due to the shortcode itself. I don't have time to investigate this further now, so I've opened the following issue to track the problem:

PTAL @deining @fekete-robert. Note that I'm OOO next week so feel free to merge this if you judge that it's ready.

@chalin

chalin commented Aug 18, 2023

Copy link
Copy Markdown
Collaborator Author

Hmm, given that this is potentially a breaking change, it should be postponed until:

I'll update the CHANGELOG.

/cc @geriom

@chalin chalin mentioned this pull request Aug 18, 2023
21 tasks done
@deining

deining commented Aug 19, 2023 •

Copy link
Copy Markdown
Contributor

Thanks for the updates @deining. I've revisited this PR, making the following adjustments:

* Recovered the `.h4` _styling_ of the alert header, without making it heading element

That's great, I was aware of this defect already, your solution is great!

* Changed the shortcode file suffix to `.md`

Fine for me.

Note that I still can't get the alert shortcode to play well when used in lists, for example.

I got aware of this defect recently, too.

I'm unsure if this is a Hugo bug/feature or due to the shortcode itself.

This is a bug in the shortcode itself. Whitespace handling inside the shortcode is really trick.
I addressed this issue in an additional commit which hopefully resolves this problem.

I don't have time to investigate this further now, so I've opened the following issue to track the problem:

* [Alert shortcode in markdown not playing nice when indented #1672](https://github.com/google/docsy/issues/1672)

This PR hopefully closes #1672.

PTAL @deining @fekete-robert. Note that I'm OOO next week so feel free to merge this if you judge that it's ready.

Yes, I think it's ready for merging now, but from my understanding, this should go into the v0.8 release, correct? What is the time schedule date for this release?

@deining deining left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is eventually ready for merging 😄.

@deining
deining requested a review from fekete-robert August 19, 2023 19:50
@chalin
chalin force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch 6 times, most recently from 5142655 to 5035d81 Compare June 11, 2025 01:43
@chalin chalin changed the title Rework alert shortcode A better alert shortcode more markdown friendly Jun 11, 2025
@chalin

chalin commented Jun 11, 2025

Copy link
Copy Markdown
Collaborator Author

Ok, after 3+ years, I think I've got it :). This shortcode does everything I want it to do: it supports markdown content, and can be used in, e.g., markdown lists. It can even contain other shortcodes. @LisaFC @deining @fekete-robert PTAL when you have a moment.

- Discard shortcode parameter 'markdownify'
- Replace <h4> heading tag with <div> tag
- Recover heading h4 styling
- Update changelog
@chalin
chalin force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch from 5035d81 to 768961b Compare June 11, 2025 01:56
@deining
deining self-requested a review June 11, 2025 06:35

@deining deining left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't believe that this PR is going to be merged eventually :-).
My opinion hasn't changed: I consider this PR ready for merging.

@chalin
chalin force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch from 243d518 to 7413f28 Compare June 11, 2025 12:39
@chalin
chalin force-pushed the chalin-gitpod-alert-rework-2022-03-21 branch from 5933c88 to 7d1b1e1 Compare June 11, 2025 13:20

@LisaFC LisaFC left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@chalin
chalin merged commit b3e4ccf into docsy:main Jun 12, 2025
@chalin
chalin deleted the chalin-gitpod-alert-rework-2022-03-21 branch June 12, 2025 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alert shortcode in markdown not playing nice when indented

5 participants