-
-
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
Add Details Shortcode for collapsable sections within markdown content #13090
Comments
Thanks for this. I would agree that this would be very useful. The challenge is to implement a shortcode that would make "most Hugo users" happy. For one, we would want to be JS framework agnostic. I would probably not mess with On a side note, I recently tested this CSS only https://github.com/bep/hugojsbatchdemo/blob/main/layouts/shortcodes/details.html But that one would certainly be too special cased for inclusion in Hugo. So, I'm not sure. /cc @jmooring |
GitHub didn't implement anything. They simply allow HTML Although the referenced forum topic has thousands of views, this is the first time that I have seen a request (either here or in the forum) to create an embedded Having said that, provided that it is not opinionated and that it will actually be used by someone, I don't have a problem with adding a layouts/shortcodes/details.html
Notes:
|
Thank you for the feedback and detailed notes! Focusing on the "not opinionated" aspect of this, both of our handling of
I also added your suggestions:
My revised code looks like this: details.html
Would this be acceptable? I believe this approach is not opinionated and versatile enough that it should satisfy many users looking to utilize the details element. Thanks for the time. |
These changes are mostly nits...
layouts/shortcodes/details.html
Unless you have any other recommendations, please submit a PR:
|
- Add new shortcode to render details HTML element. - Implement integration tests to check: default state, custom summary, open state, safeHTML sanitization, allowed attributes, and localization of default summary text. - Update docs to include details shortcode. Closes gohugoio#13090
Hello,
I would like to propose adding a new shortcode:
The Details shortcode would allow users to use the Details html element within their markdown files. I realize this could already be done by using a rawhtml shortcode but I believe this is a common enough element to warrant inclusion in the project. So common that github implemented it in their markdown which lets me show you what I'm talking about directly within this proposal:
Details
You can add a header
You can add text within a collapsed section.
You can add an image or a code block, too.
To implement the details element, I have developed the following code:
The code has 4 arguments that can be passed:
summary
(str). Default = "Details:". This is the text that appears for users to click on.open
(bool). Default =false
. If this argument is specified, and a value other thanfalse
(bool) or "false" (str) is provided, then the element will be expanded upon page load.altSummary
(str). Default =summary
. This is the text that appears when the details tag is open. If not provided it will be the same as the summary text.name
(str). Default = "" (empty string). This attribute allows you to connect multiple details elements so that only one can be open at a time. If a user opens a named element then all other same-named elements will be closed.Notes:
onclick
handler for the summary/altSummary text switching feature but the code is self-contained to the shortcode's .html file.open
behavior matches html's implementation, with the exception it also accepts "false" as a str to keep the element closed on page load.name
argument is an html argument and the shortcode does not deviate from the expected behavior.altSummary
is an added feature over existing html behavior. I added this since I wanted to express when the details elements were expanded/collapsed, such as toggling between "10 cells collapsed" and "10 cells expanded".Discourse 29546 has had 2.2k views in a few years demonstrating it is a popular query, and my proposal has additional features to align with html's implementation.
I cannot fully demonstrate my shortcode within github discussion. If you would like to see examples of its usage, You can see the usage of the details shortcode within hugo in my blog post here, .
This is would be my first contribution to the project. I have signed the CLA and am prepared to update documentation if my proposal is approved. Thanks for your time!
The text was updated successfully, but these errors were encountered: