mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-08 23:40:40 +02:00
Add Markdown diagrams and render hooks for code blocks
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 #7765 Closes #9538 Fixes #9553 Fixes #8520 Fixes #6702 Fixes #9558
This commit is contained in:
@@ -281,15 +281,10 @@ func (t *templateExec) UnusedTemplates() []tpl.FileInfo {
|
||||
|
||||
for _, ts := range t.main.templates {
|
||||
ti := ts.info
|
||||
if strings.HasPrefix(ti.name, "_internal/") {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(ti.name, "partials/inline/pagination") {
|
||||
// TODO(bep) we need to fix this. These are internal partials, but
|
||||
// they may also be defined in the project, which currently could
|
||||
// lead to some false negatives.
|
||||
if strings.HasPrefix(ti.name, "_internal/") || ti.realFilename == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, found := t.templateUsageTracker[ti.name]; !found {
|
||||
unused = append(unused, ti)
|
||||
}
|
||||
@@ -740,6 +735,7 @@ func (t *templateHandler) extractIdentifiers(line string) []string {
|
||||
}
|
||||
|
||||
//go:embed embedded/templates/*
|
||||
//go:embed embedded/templates/_default/*
|
||||
var embededTemplatesFs embed.FS
|
||||
|
||||
func (t *templateHandler) loadEmbedded() error {
|
||||
@@ -757,9 +753,19 @@ func (t *templateHandler) loadEmbedded() error {
|
||||
// to write the templates to Go files.
|
||||
templ := string(bytes.ReplaceAll(templb, []byte("\r\n"), []byte("\n")))
|
||||
name := strings.TrimPrefix(filepath.ToSlash(path), "embedded/templates/")
|
||||
templateName := name
|
||||
|
||||
if err := t.AddTemplate(internalPathPrefix+name, templ); err != nil {
|
||||
return err
|
||||
// For the render hooks it does not make sense to preseve the
|
||||
// double _indternal double book-keeping,
|
||||
// just add it if its now provided by the user.
|
||||
if !strings.Contains(path, "_default/_markup") {
|
||||
templateName = internalPathPrefix + name
|
||||
}
|
||||
|
||||
if _, found := t.Lookup(templateName); !found {
|
||||
if err := t.AddTemplate(templateName, templ); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if aliases, found := embeddedTemplatesAliases[name]; found {
|
||||
|
Reference in New Issue
Block a user