Skip to content

Commit

Permalink
CodeblockContext method renames
Browse files Browse the repository at this point in the history
Fixes #9577
  • Loading branch information
bep committed Feb 27, 2022
1 parent e1f6969 commit f710977
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="mermaid">
{{- .Code | safeHTML }}
{{- .Inner | safeHTML }}
</div>
{{ .Page.Store.Set "hasMermaid" true }}
2 changes: 1 addition & 1 deletion hugolib/page__per_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions markup/converter/hooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
8 changes: 4 additions & 4 deletions markup/goldmark/codeblocks/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down Expand Up @@ -129,7 +129,7 @@ echo "p1";
-- layouts/_default/single.html --
{{ .Content }}
-- layouts/_default/_markup/render-codeblock.html --
|{{ .Code | safeHTML }}|
|{{ .Inner | safeHTML }}|
`

Expand Down
4 changes: 2 additions & 2 deletions markup/goldmark/codeblocks/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions markup/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f710977

Please sign in to comment.