mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
e1f696911e
commit
f7109771a0
7 changed files with 14 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
<div class="mermaid">
|
<div class="mermaid">
|
||||||
{{- .Code | safeHTML }}
|
{{- .Inner | safeHTML }}
|
||||||
</div>
|
</div>
|
||||||
{{ .Page.Store.Set "hasMermaid" true }}
|
{{ .Page.Store.Set "hasMermaid" true }}
|
||||||
|
|
|
@ -436,7 +436,7 @@ func (p *pageContentOutput) initRenderHooks() error {
|
||||||
|
|
||||||
switch v := ctx.(type) {
|
switch v := ctx.(type) {
|
||||||
case hooks.CodeblockContext:
|
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)
|
pos := p.p.posFromInput(p.p.source.parsed.Input(), offset)
|
||||||
|
|
|
@ -40,8 +40,8 @@ type CodeblockContext interface {
|
||||||
AttributesProvider
|
AttributesProvider
|
||||||
text.Positioner
|
text.Positioner
|
||||||
Options() map[string]interface{}
|
Options() map[string]interface{}
|
||||||
Lang() string
|
Type() string
|
||||||
Code() string
|
Inner() string
|
||||||
Ordinal() int
|
Ordinal() int
|
||||||
Page() interface{}
|
Page() interface{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,12 +40,12 @@ func TestCodeblocks(t *testing.T) {
|
||||||
style = 'monokai'
|
style = 'monokai'
|
||||||
tabWidth = 4
|
tabWidth = 4
|
||||||
-- layouts/_default/_markup/render-codeblock-goat.html --
|
-- layouts/_default/_markup/render-codeblock-goat.html --
|
||||||
{{ $diagram := diagrams.Goat .Code }}
|
{{ $diagram := diagrams.Goat .Inner }}
|
||||||
Goat SVG:{{ substr $diagram.SVG 0 100 | safeHTML }} }}|
|
Goat SVG:{{ substr $diagram.SVG 0 100 | safeHTML }} }}|
|
||||||
Goat Attribute: {{ .Attributes.width}}|
|
Goat Attribute: {{ .Attributes.width}}|
|
||||||
-- layouts/_default/_markup/render-codeblock-go.html --
|
-- layouts/_default/_markup/render-codeblock-go.html --
|
||||||
Go Code: {{ .Code | safeHTML }}|
|
Go Code: {{ .Inner | safeHTML }}|
|
||||||
Go Language: {{ .Lang }}|
|
Go Language: {{ .Type }}|
|
||||||
-- layouts/_default/single.html --
|
-- layouts/_default/single.html --
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
-- content/p1.md --
|
-- content/p1.md --
|
||||||
|
@ -129,7 +129,7 @@ echo "p1";
|
||||||
-- layouts/_default/single.html --
|
-- layouts/_default/single.html --
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
-- layouts/_default/_markup/render-codeblock.html --
|
-- layouts/_default/_markup/render-codeblock.html --
|
||||||
|{{ .Code | safeHTML }}|
|
|{{ .Inner | safeHTML }}|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
|
@ -150,11 +150,11 @@ func (c *codeBlockContext) Page() interface{} {
|
||||||
return c.page
|
return c.page
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *codeBlockContext) Lang() string {
|
func (c *codeBlockContext) Type() string {
|
||||||
return c.lang
|
return c.lang
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *codeBlockContext) Code() string {
|
func (c *codeBlockContext) Inner() string {
|
||||||
return c.code
|
return c.code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ func (h chromaHighlighter) HighlightCodeBlock(ctx hooks.CodeblockContext, opts i
|
||||||
return HightlightResult{}, err
|
return HightlightResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := highlight(&b, ctx.Code(), ctx.Lang(), attributes, cfg)
|
err := highlight(&b, ctx.Inner(), ctx.Type(), attributes, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HightlightResult{}, err
|
return HightlightResult{}, err
|
||||||
}
|
}
|
||||||
|
@ -125,9 +125,9 @@ func (h chromaHighlighter) RenderCodeblock(w hugio.FlexiWriter, ctx hooks.Codebl
|
||||||
return err
|
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 {
|
func (h chromaHighlighter) IsDefaultCodeBlockRenderer() bool {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{{ $height := .Attributes.height }}
|
{{ $height := .Attributes.height }}
|
||||||
{{ $class := .Attributes.class | default "" }}
|
{{ $class := .Attributes.class | default "" }}
|
||||||
<div class="goat svg-container {{ $class }}">
|
<div class="goat svg-container {{ $class }}">
|
||||||
{{ with diagrams.Goat .Code }}
|
{{ with diagrams.Goat .Inner }}
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
font-family="Menlo,Lucida Console,monospace"
|
font-family="Menlo,Lucida Console,monospace"
|
||||||
|
|
Loading…
Reference in a new issue