1// based on HUGO markup/converter/hooks/hooks.go -- Pet
2
3// Copyright 2019 The Hugo Authors. All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16package goldmark_extensions
17
18/*
19import (
20// "context"
21// "io"
22
23// "github.com/gohugoio/hugo/common/hugio"
24// "github.com/gohugoio/hugo/common/text"
25// "github.com/gohugoio/hugo/common/types/hstring"
26// "github.com/gohugoio/hugo/markup/internal/attributes"
27)
28
29var _ AttributesOptionsSliceProvider = (*attributes.AttributesHolder)(nil)
30
31type AttributesProvider interface {
32 // Attributes passed in from Markdown (e.g. { attrName1=attrValue1 attrName2="attr Value 2" }).
33 Attributes() map[string]any
34}
35
36// LinkContext is the context passed to a link render hook.
37type LinkContext interface {
38 PageProvider
39
40 // The link URL.
41 Destination() string
42
43 // The link title attribute.
44 Title() string
45
46 // The rendered (HTML) text.
47 Text() hstring.HTML
48
49 // The plain variant of Text.
50 PlainText() string
51}
52
53// ImageLinkContext is the context passed to a image link render hook.
54type ImageLinkContext interface {
55 LinkContext
56
57 // Returns true if this is a standalone image and the config option
58 // markup.goldmark.parser.wrapStandAloneImageWithinParagraph is disabled.
59 IsBlock() bool
60
61 // Zero-based ordinal for all the images in the current document.
62 Ordinal() int
63}
64
65// CodeblockContext is the context passed to a code block render hook.
66type CodeblockContext interface {
67 BaseContext
68 AttributesProvider
69
70 // Chroma highlighting processing options. This will only be filled if Type is a known Chroma Lexer.
71 Options() map[string]any
72
73 // The type of code block. This will be the programming language, e.g. bash, when doing code highlighting.
74 Type() string
75
76 // The text between the code fences.
77 Inner() string
78}
79
80// TableContext is the context passed to a table render hook.
81type TableContext interface {
82 BaseContext
83 AttributesProvider
84
85 THead() []TableRow
86 TBody() []TableRow
87}
88
89// BaseContext is the base context used in most render hooks.
90type BaseContext interface {
91 text.Positioner
92 PageProvider
93
94 // Zero-based ordinal for all elements of this kind in the current document.
95 Ordinal() int
96}
97
98// BlockquoteContext is the context passed to a blockquote render hook.
99type BlockquoteContext interface {
100 BaseContext
101
102 AttributesProvider
103
104 // The blockquote text.
105 // If type is "alert", this will be the alert text.
106 Text() hstring.HTML
107
108 /// Returns the blockquote type, one of "regular" and "alert".
109 // Type "alert" indicates that this is a GitHub type alert.
110 Type() string
111
112 // The GitHub alert type converted to lowercase, e.g. "note".
113 // Only set if Type is "alert".
114 AlertType() string
115
116 // The alert title.
117 // Currently only relevant for Obsidian alerts.
118 // GitHub does not suport alert titles and will not render alerts with titles.
119 AlertTitle() hstring.HTML
120
121 // The alert sign, "+" or "-" or "" used to indicate folding.
122 // Currently only relevant for Obsidian alerts.
123 // GitHub does not suport alert signs and will not render alerts with signs.
124 AlertSign() string
125}
126
127type PositionerSourceTargetProvider interface {
128 // For internal use.
129 PositionerSourceTarget() []byte
130}
131
132// PassThroughContext is the context passed to a passthrough render hook.
133type PassthroughContext interface {
134 BaseContext
135 AttributesProvider
136
137 // Currently one of "inline" or "block".
138 Type() string
139
140 // The inner content of the passthrough element, excluding the delimiters.
141 Inner() string
142}
143
144type AttributesOptionsSliceProvider interface {
145 AttributesSlice() []attributes.Attribute
146 OptionsSlice() []attributes.Attribute
147}
148
149type LinkRenderer interface {
150 RenderLink(cctx context.Context, w io.Writer, ctx LinkContext) error
151}
152
153type CodeBlockRenderer interface {
154 RenderCodeblock(cctx context.Context, w hugio.FlexiWriter, ctx CodeblockContext) error
155}
156
157type BlockquoteRenderer interface {
158 RenderBlockquote(cctx context.Context, w hugio.FlexiWriter, ctx BlockquoteContext) error
159}
160
161type TableRenderer interface {
162 RenderTable(cctx context.Context, w hugio.FlexiWriter, ctx TableContext) error
163}
164
165type PassthroughRenderer interface {
166 RenderPassthrough(cctx context.Context, w io.Writer, ctx PassthroughContext) error
167}
168
169type IsDefaultCodeBlockRendererProvider interface {
170 IsDefaultCodeBlockRenderer() bool
171}
172
173// HeadingContext contains accessors to all attributes that a HeadingRenderer
174// can use to render a heading.
175type HeadingContext interface {
176 PageProvider
177 // Level is the level of the header (i.e. 1 for top-level, 2 for sub-level, etc.).
178 Level() int
179 // Anchor is the HTML id assigned to the heading.
180 Anchor() string
181 // Text is the rendered (HTML) heading text, excluding the heading marker.
182 Text() hstring.HTML
183 // PlainText is the unrendered version of Text.
184 PlainText() string
185
186 // Attributes (e.g. CSS classes)
187 AttributesProvider
188}
189
190type PageProvider interface {
191 // Page is the page being rendered.
192 Page() any
193
194 // PageInner may be different than Page when .RenderShortcodes is in play.
195 // The main use case for this is to include other pages' markdown into the current page
196 // but resolve resources and pages relative to the original.
197 PageInner() any
198}
199
200// HeadingRenderer describes a uniquely identifiable rendering hook.
201type HeadingRenderer interface {
202 // RenderHeading writes the rendered content to w using the data in w.
203 RenderHeading(cctx context.Context, w io.Writer, ctx HeadingContext) error
204}
205
206// ElementPositionResolver provides a way to resolve the start Position
207// of a markdown element in the original source document.
208// This may be both slow and approximate, so should only be
209// used for error logging.
210type ElementPositionResolver interface {
211 ResolvePosition(ctx any) text.Position
212}
213
214type RendererType int
215
216const (
217 LinkRendererType RendererType = iota + 1
218 ImageRendererType
219 HeadingRendererType
220 CodeBlockRendererType
221 PassthroughRendererType
222 BlockquoteRendererType
223 TableRendererType
224)
225
226type GetRendererFunc func(t RendererType, id any) any
227
228type TableCell struct {
229 Text hstring.HTML
230 Alignment string // left, center, or right
231}
232
233type TableRow []TableCell
234
235type Table struct {
236 THead []TableRow
237 TBody []TableRow
238}
239*/