2019-11-27 07:42:36 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package goldmark
|
|
|
|
|
|
|
|
import (
|
2021-02-23 12:04:05 -05:00
|
|
|
"bytes"
|
2021-07-15 02:46:54 -04:00
|
|
|
"strings"
|
2021-02-22 05:27:14 -05:00
|
|
|
"sync"
|
|
|
|
|
2021-02-23 12:04:05 -05:00
|
|
|
"github.com/spf13/cast"
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
"github.com/gohugoio/hugo/markup/converter/hooks"
|
|
|
|
|
|
|
|
"github.com/yuin/goldmark"
|
|
|
|
"github.com/yuin/goldmark/ast"
|
|
|
|
"github.com/yuin/goldmark/renderer"
|
|
|
|
"github.com/yuin/goldmark/renderer/html"
|
|
|
|
"github.com/yuin/goldmark/util"
|
|
|
|
)
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
var _ renderer.SetOptioner = (*hookedRenderer)(nil)
|
2019-11-27 07:42:36 -05:00
|
|
|
|
|
|
|
func newLinkRenderer() renderer.NodeRenderer {
|
2020-03-14 10:43:10 -04:00
|
|
|
r := &hookedRenderer{
|
2019-11-27 07:42:36 -05:00
|
|
|
Config: html.Config{
|
|
|
|
Writer: html.DefaultWriter,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func newLinks() goldmark.Extender {
|
|
|
|
return &links{}
|
|
|
|
}
|
|
|
|
|
2021-02-22 05:27:14 -05:00
|
|
|
type attributesHolder struct {
|
|
|
|
// What we get from Goldmark.
|
|
|
|
astAttributes []ast.Attribute
|
|
|
|
|
|
|
|
// What we send to the the render hooks.
|
|
|
|
attributesInit sync.Once
|
|
|
|
attributes map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *attributesHolder) Attributes() map[string]string {
|
|
|
|
a.attributesInit.Do(func() {
|
|
|
|
a.attributes = make(map[string]string)
|
|
|
|
for _, attr := range a.astAttributes {
|
|
|
|
a.attributes[string(attr.Name)] = string(util.EscapeHTML(attr.Value.([]byte)))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return a.attributes
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
type linkContext struct {
|
|
|
|
page interface{}
|
|
|
|
destination string
|
|
|
|
title string
|
|
|
|
text string
|
2019-12-18 11:23:09 -05:00
|
|
|
plainText string
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx linkContext) Destination() string {
|
|
|
|
return ctx.destination
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx linkContext) Resolved() bool {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx linkContext) Page() interface{} {
|
|
|
|
return ctx.page
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx linkContext) Text() string {
|
|
|
|
return ctx.text
|
|
|
|
}
|
|
|
|
|
2019-12-18 11:23:09 -05:00
|
|
|
func (ctx linkContext) PlainText() string {
|
|
|
|
return ctx.plainText
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
func (ctx linkContext) Title() string {
|
|
|
|
return ctx.title
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
type headingContext struct {
|
|
|
|
page interface{}
|
|
|
|
level int
|
|
|
|
anchor string
|
|
|
|
text string
|
|
|
|
plainText string
|
2021-02-22 05:27:14 -05:00
|
|
|
*attributesHolder
|
2020-03-14 10:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx headingContext) Page() interface{} {
|
|
|
|
return ctx.page
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx headingContext) Level() int {
|
|
|
|
return ctx.level
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx headingContext) Anchor() string {
|
|
|
|
return ctx.anchor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx headingContext) Text() string {
|
|
|
|
return ctx.text
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx headingContext) PlainText() string {
|
|
|
|
return ctx.plainText
|
|
|
|
}
|
|
|
|
|
|
|
|
type hookedRenderer struct {
|
2019-11-27 07:42:36 -05:00
|
|
|
html.Config
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
func (r *hookedRenderer) SetOption(name renderer.OptionName, value interface{}) {
|
2019-11-27 07:42:36 -05:00
|
|
|
r.Config.SetOption(name, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// RegisterFuncs implements NodeRenderer.RegisterFuncs.
|
2020-03-14 10:43:10 -04:00
|
|
|
func (r *hookedRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
|
2019-11-27 07:42:36 -05:00
|
|
|
reg.Register(ast.KindLink, r.renderLink)
|
2021-07-15 02:46:54 -04:00
|
|
|
reg.Register(ast.KindAutoLink, r.renderAutoLink)
|
2019-11-27 07:42:36 -05:00
|
|
|
reg.Register(ast.KindImage, r.renderImage)
|
2020-03-14 10:43:10 -04:00
|
|
|
reg.Register(ast.KindHeading, r.renderHeading)
|
|
|
|
}
|
|
|
|
|
2021-02-23 12:04:05 -05:00
|
|
|
func (r *hookedRenderer) renderAttributesForNode(w util.BufWriter, node ast.Node) {
|
|
|
|
renderAttributes(w, false, node.Attributes()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
|
|
|
// Attributes with special meaning that does not make sense to render in HTML.
|
|
|
|
attributeExcludes = map[string]bool{
|
|
|
|
"hl_lines": true,
|
2022-01-14 22:29:39 -05:00
|
|
|
"hl_style": true,
|
|
|
|
"linenos": true,
|
2021-02-23 12:04:05 -05:00
|
|
|
"linenostart": true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func renderAttributes(w util.BufWriter, skipClass bool, attributes ...ast.Attribute) {
|
|
|
|
for _, attr := range attributes {
|
|
|
|
if skipClass && bytes.Equal(attr.Name, []byte("class")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if attributeExcludes[string(attr.Name)] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
_, _ = w.WriteString(" ")
|
|
|
|
_, _ = w.Write(attr.Name)
|
|
|
|
_, _ = w.WriteString(`="`)
|
2021-02-23 12:04:05 -05:00
|
|
|
|
|
|
|
switch v := attr.Value.(type) {
|
|
|
|
case []byte:
|
|
|
|
_, _ = w.Write(util.EscapeHTML(v))
|
|
|
|
default:
|
|
|
|
w.WriteString(cast.ToString(v))
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
_ = w.WriteByte('"')
|
|
|
|
}
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
func (r *hookedRenderer) renderImage(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
n := node.(*ast.Image)
|
2021-03-09 04:26:44 -05:00
|
|
|
var h hooks.Renderers
|
2020-03-14 10:43:10 -04:00
|
|
|
|
|
|
|
ctx, ok := w.(*renderContext)
|
|
|
|
if ok {
|
|
|
|
h = ctx.RenderContext().RenderHooks
|
2021-03-09 04:26:44 -05:00
|
|
|
ok = h.ImageRenderer != nil
|
2020-03-14 10:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
2021-07-15 03:05:13 -04:00
|
|
|
return r.renderImageDefault(w, source, node, entering)
|
2020-03-14 10:43:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if entering {
|
|
|
|
// Store the current pos so we can capture the rendered text.
|
|
|
|
ctx.pos = ctx.Buffer.Len()
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
text := ctx.Buffer.Bytes()[ctx.pos:]
|
|
|
|
ctx.Buffer.Truncate(ctx.pos)
|
|
|
|
|
|
|
|
err := h.ImageRenderer.RenderLink(
|
|
|
|
w,
|
|
|
|
linkContext{
|
|
|
|
page: ctx.DocumentContext().Document,
|
|
|
|
destination: string(n.Destination),
|
|
|
|
title: string(n.Title),
|
|
|
|
text: string(text),
|
|
|
|
plainText: string(n.Text(source)),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-11-26 02:32:49 -05:00
|
|
|
ctx.AddIdentity(h.ImageRenderer)
|
2020-03-14 10:43:10 -04:00
|
|
|
|
|
|
|
return ast.WalkContinue, err
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
// Fall back to the default Goldmark render funcs. Method below borrowed from:
|
|
|
|
// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404
|
2021-07-15 03:05:13 -04:00
|
|
|
func (r *hookedRenderer) renderImageDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
if !entering {
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
n := node.(*ast.Image)
|
|
|
|
_, _ = w.WriteString("<img src=\"")
|
|
|
|
if r.Unsafe || !html.IsDangerousURL(n.Destination) {
|
|
|
|
_, _ = w.Write(util.EscapeHTML(util.URLEscape(n.Destination, true)))
|
|
|
|
}
|
|
|
|
_, _ = w.WriteString(`" alt="`)
|
|
|
|
_, _ = w.Write(n.Text(source))
|
|
|
|
_ = w.WriteByte('"')
|
|
|
|
if n.Title != nil {
|
|
|
|
_, _ = w.WriteString(` title="`)
|
|
|
|
r.Writer.Write(w, n.Title)
|
2019-11-27 07:42:36 -05:00
|
|
|
_ = w.WriteByte('"')
|
2021-07-15 03:05:13 -04:00
|
|
|
}
|
|
|
|
if r.XHTML {
|
|
|
|
_, _ = w.WriteString(" />")
|
2019-11-27 07:42:36 -05:00
|
|
|
} else {
|
2021-07-15 03:05:13 -04:00
|
|
|
_, _ = w.WriteString(">")
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
2021-07-15 03:05:13 -04:00
|
|
|
return ast.WalkSkipChildren, nil
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
func (r *hookedRenderer) renderLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
n := node.(*ast.Link)
|
2021-03-09 04:26:44 -05:00
|
|
|
var h hooks.Renderers
|
2019-11-27 07:42:36 -05:00
|
|
|
|
2019-12-19 11:43:07 -05:00
|
|
|
ctx, ok := w.(*renderContext)
|
2019-11-27 07:42:36 -05:00
|
|
|
if ok {
|
|
|
|
h = ctx.RenderContext().RenderHooks
|
2021-03-09 04:26:44 -05:00
|
|
|
ok = h.LinkRenderer != nil
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
2021-07-15 03:05:13 -04:00
|
|
|
return r.renderLinkDefault(w, source, node, entering)
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2019-12-19 11:43:07 -05:00
|
|
|
if entering {
|
|
|
|
// Store the current pos so we can capture the rendered text.
|
|
|
|
ctx.pos = ctx.Buffer.Len()
|
2019-11-27 07:42:36 -05:00
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
2019-12-19 11:43:07 -05:00
|
|
|
text := ctx.Buffer.Bytes()[ctx.pos:]
|
|
|
|
ctx.Buffer.Truncate(ctx.pos)
|
2019-12-18 11:23:09 -05:00
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
err := h.LinkRenderer.RenderLink(
|
2019-11-27 07:42:36 -05:00
|
|
|
w,
|
|
|
|
linkContext{
|
|
|
|
page: ctx.DocumentContext().Document,
|
|
|
|
destination: string(n.Destination),
|
|
|
|
title: string(n.Title),
|
2019-12-19 11:43:07 -05:00
|
|
|
text: string(text),
|
|
|
|
plainText: string(n.Text(source)),
|
2019-11-27 07:42:36 -05:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-11-26 02:32:49 -05:00
|
|
|
// TODO(bep) I have a working branch that fixes these rather confusing identity types,
|
|
|
|
// but for now it's important that it's not .GetIdentity() that's added here,
|
|
|
|
// to make sure we search the entire chain on changes.
|
|
|
|
ctx.AddIdentity(h.LinkRenderer)
|
2019-11-27 07:42:36 -05:00
|
|
|
|
2019-12-19 11:43:07 -05:00
|
|
|
return ast.WalkContinue, err
|
2020-03-14 10:43:10 -04:00
|
|
|
}
|
2019-11-27 07:42:36 -05:00
|
|
|
|
2021-07-15 03:05:13 -04:00
|
|
|
// Fall back to the default Goldmark render funcs. Method below borrowed from:
|
|
|
|
// https://github.com/yuin/goldmark/blob/b611cd333a492416b56aa8d94b04a67bf0096ab2/renderer/html/html.go#L404
|
|
|
|
func (r *hookedRenderer) renderLinkDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
n := node.(*ast.Link)
|
|
|
|
if entering {
|
|
|
|
_, _ = w.WriteString("<a href=\"")
|
|
|
|
if r.Unsafe || !html.IsDangerousURL(n.Destination) {
|
|
|
|
_, _ = w.Write(util.EscapeHTML(util.URLEscape(n.Destination, true)))
|
|
|
|
}
|
|
|
|
_ = w.WriteByte('"')
|
|
|
|
if n.Title != nil {
|
|
|
|
_, _ = w.WriteString(` title="`)
|
|
|
|
r.Writer.Write(w, n.Title)
|
|
|
|
_ = w.WriteByte('"')
|
|
|
|
}
|
|
|
|
_ = w.WriteByte('>')
|
|
|
|
} else {
|
|
|
|
_, _ = w.WriteString("</a>")
|
|
|
|
}
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:46:54 -04:00
|
|
|
func (r *hookedRenderer) renderAutoLink(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
if !entering {
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
n := node.(*ast.AutoLink)
|
|
|
|
var h hooks.Renderers
|
|
|
|
|
|
|
|
ctx, ok := w.(*renderContext)
|
|
|
|
if ok {
|
|
|
|
h = ctx.RenderContext().RenderHooks
|
|
|
|
ok = h.LinkRenderer != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
2021-07-15 03:05:13 -04:00
|
|
|
return r.renderAutoLinkDefault(w, source, node, entering)
|
2021-07-15 02:46:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
url := string(n.URL(source))
|
|
|
|
label := string(n.Label(source))
|
|
|
|
if n.AutoLinkType == ast.AutoLinkEmail && !strings.HasPrefix(strings.ToLower(url), "mailto:") {
|
|
|
|
url = "mailto:" + url
|
|
|
|
}
|
|
|
|
|
|
|
|
err := h.LinkRenderer.RenderLink(
|
|
|
|
w,
|
|
|
|
linkContext{
|
|
|
|
page: ctx.DocumentContext().Document,
|
|
|
|
destination: url,
|
|
|
|
text: label,
|
|
|
|
plainText: label,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO(bep) I have a working branch that fixes these rather confusing identity types,
|
|
|
|
// but for now it's important that it's not .GetIdentity() that's added here,
|
|
|
|
// to make sure we search the entire chain on changes.
|
|
|
|
ctx.AddIdentity(h.LinkRenderer)
|
|
|
|
|
|
|
|
return ast.WalkContinue, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to the default Goldmark render funcs. Method below borrowed from:
|
|
|
|
// https://github.com/yuin/goldmark/blob/5588d92a56fe1642791cf4aa8e9eae8227cfeecd/renderer/html/html.go#L439
|
2021-07-15 03:05:13 -04:00
|
|
|
func (r *hookedRenderer) renderAutoLinkDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
2021-07-15 02:46:54 -04:00
|
|
|
n := node.(*ast.AutoLink)
|
|
|
|
if !entering {
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
_, _ = w.WriteString(`<a href="`)
|
|
|
|
url := n.URL(source)
|
|
|
|
label := n.Label(source)
|
|
|
|
if n.AutoLinkType == ast.AutoLinkEmail && !bytes.HasPrefix(bytes.ToLower(url), []byte("mailto:")) {
|
|
|
|
_, _ = w.WriteString("mailto:")
|
|
|
|
}
|
|
|
|
_, _ = w.Write(util.EscapeHTML(util.URLEscape(url, false)))
|
|
|
|
if n.Attributes() != nil {
|
|
|
|
_ = w.WriteByte('"')
|
|
|
|
html.RenderAttributes(w, n, html.LinkAttributeFilter)
|
|
|
|
_ = w.WriteByte('>')
|
|
|
|
} else {
|
|
|
|
_, _ = w.WriteString(`">`)
|
|
|
|
}
|
|
|
|
_, _ = w.Write(util.EscapeHTML(label))
|
|
|
|
_, _ = w.WriteString(`</a>`)
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
func (r *hookedRenderer) renderHeading(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
n := node.(*ast.Heading)
|
2021-03-09 04:26:44 -05:00
|
|
|
var h hooks.Renderers
|
2019-11-27 07:42:36 -05:00
|
|
|
|
2019-12-18 11:23:09 -05:00
|
|
|
ctx, ok := w.(*renderContext)
|
2019-11-27 07:42:36 -05:00
|
|
|
if ok {
|
|
|
|
h = ctx.RenderContext().RenderHooks
|
2021-03-09 04:26:44 -05:00
|
|
|
ok = h.HeadingRenderer != nil
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
2021-07-15 03:05:13 -04:00
|
|
|
return r.renderHeadingDefault(w, source, node, entering)
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2019-12-18 11:23:09 -05:00
|
|
|
if entering {
|
|
|
|
// Store the current pos so we can capture the rendered text.
|
|
|
|
ctx.pos = ctx.Buffer.Len()
|
2019-11-27 07:42:36 -05:00
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
2019-12-18 11:23:09 -05:00
|
|
|
text := ctx.Buffer.Bytes()[ctx.pos:]
|
|
|
|
ctx.Buffer.Truncate(ctx.pos)
|
2020-03-14 10:43:10 -04:00
|
|
|
// All ast.Heading nodes are guaranteed to have an attribute called "id"
|
|
|
|
// that is an array of bytes that encode a valid string.
|
|
|
|
anchori, _ := n.AttributeString("id")
|
|
|
|
anchor := anchori.([]byte)
|
2019-12-18 11:23:09 -05:00
|
|
|
|
2020-03-14 10:43:10 -04:00
|
|
|
err := h.HeadingRenderer.RenderHeading(
|
2019-11-27 07:42:36 -05:00
|
|
|
w,
|
2020-03-14 10:43:10 -04:00
|
|
|
headingContext{
|
2021-02-22 05:27:14 -05:00
|
|
|
page: ctx.DocumentContext().Document,
|
|
|
|
level: n.Level,
|
|
|
|
anchor: string(anchor),
|
|
|
|
text: string(text),
|
|
|
|
plainText: string(n.Text(source)),
|
|
|
|
attributesHolder: &attributesHolder{astAttributes: n.Attributes()},
|
2019-11-27 07:42:36 -05:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-11-26 02:32:49 -05:00
|
|
|
ctx.AddIdentity(h.HeadingRenderer)
|
2019-11-27 07:42:36 -05:00
|
|
|
|
2019-12-18 11:23:09 -05:00
|
|
|
return ast.WalkContinue, err
|
2019-11-27 07:42:36 -05:00
|
|
|
}
|
|
|
|
|
2021-07-15 03:05:13 -04:00
|
|
|
func (r *hookedRenderer) renderHeadingDefault(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
|
|
|
|
n := node.(*ast.Heading)
|
|
|
|
if entering {
|
|
|
|
_, _ = w.WriteString("<h")
|
|
|
|
_ = w.WriteByte("0123456"[n.Level])
|
|
|
|
if n.Attributes() != nil {
|
|
|
|
r.renderAttributesForNode(w, node)
|
|
|
|
}
|
|
|
|
_ = w.WriteByte('>')
|
|
|
|
} else {
|
|
|
|
_, _ = w.WriteString("</h")
|
|
|
|
_ = w.WriteByte("0123456"[n.Level])
|
|
|
|
_, _ = w.WriteString(">\n")
|
|
|
|
}
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:42:36 -05:00
|
|
|
type links struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extend implements goldmark.Extender.
|
|
|
|
func (e *links) Extend(m goldmark.Markdown) {
|
|
|
|
m.Renderer().AddOptions(renderer.WithNodeRenderers(
|
|
|
|
util.Prioritized(newLinkRenderer(), 100),
|
|
|
|
))
|
|
|
|
}
|