1// Copyright 2023 The goldmark-figure authors
 2//
 3// Use of this source code is governed by an MIT-style
 4// license that can be found in the LICENSE file or at
 5// https://opensource.org/licenses/MIT.
 6package figure
 7
 8import (
 9	"github.com/mangoumbrella/goldmark-figure/ast"
10	"github.com/yuin/goldmark"
11	aparser "github.com/yuin/goldmark/parser"
12	"github.com/yuin/goldmark/renderer"
13	"github.com/yuin/goldmark/util"
14
15	fparser "github.com/mangoumbrella/goldmark-figure/parser"
16)
17
18type extension struct {
19}
20
21// Figure is an extension to render <figure> elements.
22var Figure = &extension{}
23
24func (f *extension) Extend(m goldmark.Markdown) {
25	m.Parser().AddOptions(
26		aparser.WithParagraphTransformers(
27			util.Prioritized(fparser.NewFigureParagraphTransformer(), 120),
28		),
29		aparser.WithASTTransformers(
30			util.Prioritized(fparser.NewFigureASTTransformer(), 0),
31		),
32	)
33	m.Renderer().AddOptions(renderer.WithNodeRenderers(
34		util.Prioritized(ast.NewFigureHTMLRenderer(), 0),
35	))
36}