Repository: gohugoio/hugo (language: go)

Issue:
CodeblockContext method renames
This is a narrower and more actionable version of parts of #9573 

What we currently have (unreleased) is this:

```go
type CodeblockContext interface {
	Attributes() map[string]interface{}
        Options() map[string]interface{}
	Position() text.Position
	Lang() string
	Code() string
	Ordinal() int
	Page() interface{}
}
```

I think it helps to look at how we use this information to determine what we do with it, e.g.:

```
render-codeblock-bash.en.html
```

And then the same using the "Hugo terms":

```
render-<Kind>-<Lang>.<Lang>.<OutputFormat>
```

* `Kind`: [codeblock](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks) is an established term and I think we need to keep on using that even if these code blocks can contain ... other things.
* `Lang`: Programming language, which I find mighty confusing considering that we also have the _other_ language. I suggest we rename this to `Type`.

* `Attributes`: One could make an argument for `Params`, but I think that ship has sailed.
* `Code`: Let's rename that to `Inner` to make it more generic and in line with the shortcodes.

With that we get:

```go
type CodeblockContext interface {
	Attributes() map[string]interface{}
        Options() map[string]interface{}
	Position() text.Position
	Type() string
	Inner() string
	Ordinal() int
	Page() interface{}
}
```

/cc @jmooring 


Discussion / hints:

Fix patch:
diff --git a/docs/layouts/_default/_markup/render-codeblock-mermaid.html b/docs/layouts/_default/_markup/render-codeblock-mermaid.html
index 15e4fdfbb77..59641551ca6 100644
--- a/docs/layouts/_default/_markup/render-codeblock-mermaid.html
+++ b/docs/layouts/_default/_markup/render-codeblock-mermaid.html
@@ -1,4 +1,4 @@
 <div class="mermaid">
-  {{- .Code | safeHTML }}
+  {{- .Inner | safeHTML }}
 </div>
 {{ .Page.Store.Set "hasMermaid" true }}
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 4067e827faf..d79b152f3b7 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -436,7 +436,7 @@ func (p *pageContentOutput) initRenderHooks() error {
 
 			switch v := ctx.(type) {
 			case hooks.CodeblockContext:
-				offset = bytes.Index(p.p.source.parsed.Input(), []byte(v.Code()))
+				offset = bytes.Index(p.p.source.parsed.Input(), []byte(v.Inner()))
 			}
 
 			pos := p.p.posFromInput(p.p.source.parsed.Input(), offset)
diff --git a/markup/converter/hooks/hooks.go b/markup/converter/hooks/hooks.go
index e81689f0435..54ebf405ec5 100644
--- a/markup/converter/hooks/hooks.go
+++ b/markup/converter/hooks/hooks.go
@@ -40,8 +40,8 @@ type CodeblockContext interface {
 	AttributesProvider
 	text.Positioner
 	Options() map[string]interface{}
-	Lang() string
-	Code() string
+	Type() string
+	Inner() string
 	Ordinal() int
 	Page() interface{}
 }
diff --git a/markup/goldmark/codeblocks/render.go b/markup/goldmark/codeblocks/render.go
index 27252fc27cf..97604eb55fb 100644
--- a/markup/goldmark/codeblocks/render.go
+++ b/markup/goldmark/codeblocks/render.go
@@ -150,11 +150,11 @@ func (c *codeBlockContext) Page() interface{} {
 	return c.page
 }
 
-func (c *codeBlockContext) Lang() string {
+func (c *codeBlockContext) Type() string {
 	return c.lang
 }
 
-func (c *codeBlockContext) Code() string {
+func (c *codeBlockContext) Inner() string {
 	return c.code
 }
 
diff --git a/markup/highlight/highlight.go b/markup/highlight/highlight.go
index dac45e3121b..c04fbad314f 100644
--- a/markup/highlight/highlight.go
+++ b/markup/highlight/highlight.go
@@ -103,7 +103,7 @@ func (h chromaHighlighter) HighlightCodeBlock(ctx hooks.CodeblockContext, opts i
 		return HightlightResult{}, err
 	}
 
-	err := highlight(&b, ctx.Code(), ctx.Lang(), attributes, cfg)
+	err := highlight(&b, ctx.Inner(), ctx.Type(), attributes, cfg)
 	if err != nil {
 		return HightlightResult{}, err
 	}
@@ -125,9 +125,9 @@ func (h chromaHighlighter) RenderCodeblock(w hugio.FlexiWriter, ctx hooks.Codebl
 		return err
 	}
 
-	code := text.Puts(ctx.Code())
+	code := text.Puts(ctx.Inner())
 
-	return highlight(w, code, ctx.Lang(), attributes, cfg)
+	return highlight(w, code, ctx.Type(), attributes, cfg)
 }
 
 func (h chromaHighlighter) IsDefaultCodeBlockRenderer() bool {
diff --git a/tpl/diagrams/diagrams.go b/tpl/diagrams/diagrams.go
index 1bdbc2a02fd..b0ddf5a42f1 100644
--- a/tpl/diagrams/diagrams.go
+++ b/tpl/diagrams/diagrams.go
@@ -25,9 +25,17 @@ import (
 )
 
 type SVGDiagram interface {
-	Body() template.HTML
+	// Inner returns the inner markup of the SVG.
+	// This allows for the <svg> container to be created manually.
+	Inner() template.HTML
+
+	// SVG returns the diagram as an SVG, including the <svg> container.
 	SVG() template.HTML
+
+	// Width returns the width of the SVG.
 	Width() int
+
+	// Height returns the height of the SVG.
 	Height() int
 }
 
@@ -35,7 +43,7 @@ type goatDiagram struct {
 	d goat.SVG
 }
 
-func (d goatDiagram) Body() template.HTML {
+func (d goatDiagram) Inner() template.HTML {
 	return template.HTML(d.d.Body)
 }
 
diff --git a/tpl/tplimpl/embedded/templates/_default/_markup/render-codeblock-goat.html b/tpl/tplimpl/embedded/templates/_default/_markup/render-codeblock-goat.html
index b1e57e94a7b..35ec0b309d3 100644
--- a/tpl/tplimpl/embedded/templates/_default/_markup/render-codeblock-goat.html
+++ b/tpl/tplimpl/embedded/templates/_default/_markup/render-codeblock-goat.html
@@ -2,7 +2,7 @@
 {{ $height := .Attributes.height }}
 {{ $class := .Attributes.class | default "" }}
 <div class="goat svg-container {{ $class }}">
-  {{ with diagrams.Goat .Code }}
+  {{ with diagrams.Goat .Inner }}
     <svg
       xmlns="http://www.w3.org/2000/svg"
       font-family="Menlo,Lucida Console,monospace"
@@ -12,7 +12,7 @@
       {{ else }}
         viewBox="0 0 {{ .Width }} {{ .Height }}"
       {{ end }}>
-      {{ .Body }}
+      {{ .Inner }}
     </svg>
   {{ end }}
 </div>


Test patch:
diff --git a/markup/goldmark/codeblocks/integration_test.go b/markup/goldmark/codeblocks/integration_test.go
index 001deb9f8dd..fcd406c2cb3 100644
--- a/markup/goldmark/codeblocks/integration_test.go
+++ b/markup/goldmark/codeblocks/integration_test.go
@@ -40,12 +40,12 @@ func TestCodeblocks(t *testing.T) {
     style = 'monokai'
     tabWidth = 4
 -- layouts/_default/_markup/render-codeblock-goat.html --
-{{ $diagram := diagrams.Goat .Code }}
+{{ $diagram := diagrams.Goat .Inner }}
 Goat SVG:{{ substr $diagram.SVG 0 100 | safeHTML }}  }}|
 Goat Attribute: {{ .Attributes.width}}|
 -- layouts/_default/_markup/render-codeblock-go.html --
-Go Code: {{ .Code | safeHTML }}|
-Go Language: {{ .Lang }}|
+Go Code: {{ .Inner | safeHTML }}|
+Go Language: {{ .Type }}|
 -- layouts/_default/single.html --
 {{ .Content }}
 -- content/p1.md --
@@ -129,7 +129,7 @@ echo "p1";
 -- layouts/_default/single.html --
 {{ .Content }}
 -- layouts/_default/_markup/render-codeblock.html --
-|{{ .Code | safeHTML }}|
+|{{ .Inner | safeHTML }}|
 
 `