Skip to content

Commit 91d25c2

Browse files
committed
feat: add custom org link resolve function for denote
1 parent d913f46 commit 91d25c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

markup/org/convert.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package org
1717
import (
1818
"bytes"
1919
"log"
20+
"strings"
2021

2122
"github.com/gohugoio/hugo/identity"
2223

@@ -51,6 +52,19 @@ func (c *orgConverter) Convert(ctx converter.RenderContext) (converter.ResultRen
5152
config.ReadFile = func(filename string) ([]byte, error) {
5253
return afero.ReadFile(c.cfg.ContentFs, filename)
5354
}
55+
config.ResolveLink = func(protocol string, description []org.Node, link string) org.Node {
56+
out := org.RegularLink{
57+
Protocol: protocol,
58+
Description: description,
59+
URL: link,
60+
AutoLink: false,
61+
}
62+
if protocol == "denote" {
63+
id := strings.TrimPrefix(link, "denote:")
64+
out.URL = "../" + strings.ToLower(id) + "/"
65+
}
66+
return out
67+
}
5468
writer := org.NewHTMLWriter()
5569
writer.HighlightCodeBlock = func(source, lang string, inline bool, params map[string]string) string {
5670
highlightedSource, err := c.cfg.Highlight(source, lang, "")

0 commit comments

Comments
 (0)