-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathwidgets.go
39 lines (32 loc) · 826 Bytes
/
widgets.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package rtl
import (
. "github.com/emad-elsaid/xlog"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/text"
"github.com/yuin/goldmark/util"
)
func init() {
MarkDownRenderer.Parser().AddOptions(
parser.WithASTTransformers(
util.Prioritized(addDirAuto(0), 0),
),
)
}
type addDirAuto int
func (t addDirAuto) Transform(doc *ast.Document, reader text.Reader, pc parser.Context) {
tags := []ast.Node{}
ast.Walk(doc, func(node ast.Node, entering bool) (ast.WalkStatus, error) {
kind := node.Kind()
if kind == ast.KindParagraph ||
kind == ast.KindHeading ||
kind == ast.KindList ||
kind == ast.KindBlockquote {
tags = append(tags, node)
}
return ast.WalkContinue, nil
})
for _, t := range tags {
t.SetAttributeString("dir", []byte("auto"))
}
}