CodeblockContext method renames

Fixes #9577
This commit is contained in:
Bjørn Erik Pedersen 2022-02-27 13:31:55 +01:00
parent e1f696911e
commit f7109771a0
7 changed files with 14 additions and 14 deletions

View file

@ -1,4 +1,4 @@
<div class="mermaid">
{{- .Code | safeHTML }}
{{- .Inner | safeHTML }}
</div>
{{ .Page.Store.Set "hasMermaid" true }}

View file

@ -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)

View file

@ -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{}
}

View file

@ -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 }}|
`

View file

@ -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
}

View file

@ -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 {

View file

@ -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"