-
-
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
Markdown render hooks for code blocks #6702
Comments
I would love to have this. Right now, I use a custom short code (e.g. In case this is implemented, it would be great if the entire info string of fenced code blocks is passed to the render hook. Right now, my short code supports specifying an optional caption for the code snippet, e.g.
or something along the lines of that to specify an optional caption. |
A render hook for code blocks would also make it possible (I think?) to add links to documentation / hover information on some elements inside the code blocks. Something like GitHub code navigation. |
This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help. |
I'd still greatly appreciate this feature. To avoid that this ticket gets closed due to a lack of activity, I'd like to summarise. There are many plausible features associated with code blocks:
Right now, implementing any of these features requires a custom shortcode. However, a shortcode has a number of downsides:
|
I can add one more use case To be able to process something like mermaid using standard code fence
Shortcodes block are not rendered as code in any text editors or even on Github, making it very hard to read block as a Markdown content. for example, the following content loses indentation, very bad for copy paste: {{< mermaid >}} I would love to see hooks for code blocks and even inline code. IMHO, the more we can get out from standard markdown syntax the better it is for the entire ecosystem 🙏 . |
You would get a map of
Which would allow this hook: {{ comment := .Attributes.comment }} (note to self: #8313) |
I really need this, is anyone is working on this? I would like to work on this and appreciate any guidance or direction and files that I need to update/modified? Thank you so much This will be my first issue |
Updates gohugoio#7765 Closes gohugoio#9538 Fixes gohugoio#9553 Fixes gohugoio#8520 Fixes gohugoio#6702
Updates gohugoio#7765 Closes gohugoio#9538 Fixes gohugoio#9553 Fixes gohugoio#8520 Fixes gohugoio#6702
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates gohugoio#7765 Closes gohugoio#9538 Fixes gohugoio#9553 Fixes gohugoio#8520 Fixes gohugoio#6702 Fixes gohugoio#9558
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates gohugoio#7765 Closes gohugoio#9538 Fixes gohugoio#9553 Fixes gohugoio#8520 Fixes gohugoio#6702 Fixes gohugoio#9558
You can now create custom hook templates for code blocks, either one for all (`render-codeblock.html`) or for a given code language (e.g. `render-codeblock-go.html`). We also used this new hook to add support for diagrams in Hugo: * Goat (Go ASCII Tool) is built-in and enabled by default; just create a fenced code block with the language `goat` and start draw your Ascii diagrams. * Another popular alternative for diagrams in Markdown, Mermaid (supported by GitHub), can also be implemented with a simple template. See the Hugo documentation for more information. Updates gohugoio#7765 Closes gohugoio#9538 Fixes gohugoio#9553 Fixes gohugoio#8520 Fixes gohugoio#6702 Fixes gohugoio#9558
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. |
Would it be possible to have markdown render hooks for code blocks, just as we do for links and images since v0.62?
Say I want to add a "copy" button in all code snippets in my site. Right now I'm forced to use a shortcode around my code snippets that adds it. If we had something similar to link/image render hooks, we could keep using standard markdown syntax and implement these kind of features in an elegant way.
The text was updated successfully, but these errors were encountered: