Debian Codegraph @

markup/goldmark/goldmark_config/config.go

raw
1 // Copyright 2019 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 // Package goldmark_config holds Goldmark related configuration.
15 package goldmark_config
16
17 const (
18 AutoIDTypeBlackfriday = "blackfriday"
19 AutoIDTypeGitHub = "github"
20 AutoIDTypeGitHubAscii = "github-ascii"
21 RenderHookUseEmbeddedAlways = "always"
22 RenderHookUseEmbeddedAuto = "auto"
23 RenderHookUseEmbeddedFallback = "fallback"
24 RenderHookUseEmbeddedNever = "never"
25 )
26
27 // Default holds the default Goldmark configuration.
28 var Default = Config{
29 Extensions: Extensions{
30 Typographer: Typographer{
31 Disable: false,
32 LeftSingleQuote: "‘",
33 RightSingleQuote: "’",
34 LeftDoubleQuote: "“",
35 RightDoubleQuote: "”",
36 EnDash: "–",
37 EmDash: "—",
38 Ellipsis: "…",
39 LeftAngleQuote: "«",
40 RightAngleQuote: "»",
41 Apostrophe: "’",
42 },
43 Footnote: Footnote{
44 Enable: true,
45 EnableAutoIDPrefix: false,
46 BacklinkHTML: "↩︎",
47 },
48 DefinitionList: true,
49 Table: true,
50 Strikethrough: true,
51 Linkify: true,
52 LinkifyProtocol: "https",
53 TaskList: true,
54 CJK: CJK{
55 Enable: false,
56 EastAsianLineBreaks: false,
57 EastAsianLineBreaksStyle: "simple",
58 EscapedSpace: false,
59 },
60 Extras: Extras{
61 Delete: Delete{
62 Enable: false,
63 },
64 Insert: Insert{
65 Enable: false,
66 },
67 Mark: Mark{
68 Enable: false,
69 },
70 Subscript: Subscript{
71 Enable: false,
72 },
73 Superscript: Superscript{
74 Enable: false,
75 },
76 },
77 Passthrough: Passthrough{
78 Enable: false,
79 Delimiters: DelimitersConfig{
80 Inline: [][]string{},
81 Block: [][]string{},
82 },
83 },
84 },
85 Renderer: Renderer{
86 Unsafe: false,
87 },
88 Parser: Parser{
89 AutoHeadingID: true,
90 AutoDefinitionTermID: false,
91 AutoIDType: AutoIDTypeGitHub,
92 WrapStandAloneImageWithinParagraph: true,
93 Attribute: ParserAttribute{
94 Title: true,
95 Block: false,
96 },
97 },
98 RenderHooks: RenderHooks{
99 Image: ImageRenderHook{
100 UseEmbedded: RenderHookUseEmbeddedAuto,
101 },
102 Link: LinkRenderHook{
103 UseEmbedded: RenderHookUseEmbeddedAuto,
104 },
105 },
106 }
107
108 // Config configures Goldmark.
109 type Config struct {
110 Renderer Renderer
111 Parser Parser
112 Extensions Extensions
113 DuplicateResourceFiles bool
114 RenderHooks RenderHooks
115 }
116
117 func (c *Config) Init() error {
118 if err := c.Parser.Init(); err != nil {
119 return err
120 }
121 if c.Parser.AutoDefinitionTermID && !c.Extensions.DefinitionList {
122 c.Parser.AutoDefinitionTermID = false
123 }
124 return nil
125 }
126
127 // RenderHooks contains configuration for Goldmark render hooks.
128 type RenderHooks struct {
129 Image ImageRenderHook
130 Link LinkRenderHook
131 }
132
133 // ImageRenderHook contains configuration for the image render hook.
134 type ImageRenderHook struct {
135 // Enable the default image render hook.
136 // We need to know if it is set or not, hence the pointer.
137 // Deprecated: Use UseEmbedded instead.
138 EnableDefault *bool
139
140 // When to use the embedded image render hook.
141 // One of auto, never, always, or fallback. Default is auto.
142 UseEmbedded string
143 }
144
145 // LinkRenderHook contains configuration for the link render hook.
146 type LinkRenderHook struct {
147 // Disable the default image render hook.
148 // We need to know if it is set or not, hence the pointer.
149 // Deprecated: Use UseEmbedded instead.
150 EnableDefault *bool
151
152 // When to use the embedded link render hook.
153 // One of auto, never, always, or fallback. Default is auto.
154 UseEmbedded string
155 }
156
157 type Extensions struct {
158 Typographer Typographer
159 Footnote Footnote
160 DefinitionList bool
161 Extras Extras
162 Passthrough Passthrough
163
164 // GitHub flavored markdown
165 Table bool
166 Strikethrough bool
167 Linkify bool
168 LinkifyProtocol string
169 TaskList bool
170 CJK CJK
171 }
172
173 // Footnote holds footnote configuration.
174 type Footnote struct {
175 Enable bool
176 EnableAutoIDPrefix bool
177 BacklinkHTML string
178 }
179
180 // Typographer holds typographer configuration.
181 type Typographer struct {
182 // Whether to disable typographer.
183 Disable bool
184
185 // Value used for left single quote.
186 LeftSingleQuote string
187 // Value used for right single quote.
188 RightSingleQuote string
189 // Value used for left double quote.
190 LeftDoubleQuote string
191 // Value used for right double quote.
192 RightDoubleQuote string
193 // Value used for en dash.
194 EnDash string
195 // Value used for em dash.
196 EmDash string
197 // Value used for ellipsis.
198 Ellipsis string
199 // Value used for left angle quote.
200 LeftAngleQuote string
201 // Value used for right angle quote.
202 RightAngleQuote string
203 // Value used for apostrophe.
204 Apostrophe string
205 }
206
207 // Extras holds extras configuration.
208 // github.com/hugoio/hugo-goldmark-extensions/extras
209 type Extras struct {
210 Delete Delete
211 Insert Insert
212 Mark Mark
213 Subscript Subscript
214 Superscript Superscript
215 }
216
217 type Delete struct {
218 Enable bool
219 }
220
221 type Insert struct {
222 Enable bool
223 }
224
225 type Mark struct {
226 Enable bool
227 }
228
229 type Subscript struct {
230 Enable bool
231 }
232
233 type Superscript struct {
234 Enable bool
235 }
236
237 // Passthrough holds passthrough configuration.
238 // github.com/hugoio/hugo-goldmark-extensions/passthrough
239 type Passthrough struct {
240 // Whether to enable the extension
241 Enable bool
242
243 // The delimiters to use for inline and block passthroughs.
244 Delimiters DelimitersConfig
245 }
246
247 type DelimitersConfig struct {
248 // The delimiters to use for inline passthroughs. Each entry in the list
249 // is a size-2 list of strings, where the first string is the opening delimiter
250 // and the second string is the closing delimiter, e.g.,
251 //
252 // [["$", "$"], ["\\(", "\\)"]]
253 Inline [][]string
254
255 // The delimiters to use for block passthroughs. Same format as Inline.
256 Block [][]string
257 }
258
259 type CJK struct {
260 // Whether to enable CJK support.
261 Enable bool
262
263 // Whether softline breaks between east asian wide characters should be ignored.
264 EastAsianLineBreaks bool
265
266 // Styles of Line Breaking of EastAsianLineBreaks: "simple" or "css3draft"
267 EastAsianLineBreaksStyle string
268
269 // Whether a '\' escaped half-space(0x20) should not be rendered.
270 EscapedSpace bool
271 }
272
273 type Renderer struct {
274 // Whether softline breaks should be rendered as '<br>'
275 HardWraps bool
276
277 // XHTML instead of HTML5.
278 XHTML bool
279
280 // Allow raw HTML etc.
281 Unsafe bool
282 }
283
284 type Parser struct {
285 // Enables custom heading ids and
286 // auto generated heading ids.
287 AutoHeadingID bool
288
289 // Enables auto definition term ids.
290 AutoDefinitionTermID bool
291
292 // The strategy to use when generating IDs.
293 // Available options are "github", "github-ascii", and "blackfriday".
294 // Default is "github", which will create GitHub-compatible anchor names.
295 AutoIDType string
296
297 // Enables custom attributes.
298 Attribute ParserAttribute
299
300 // Whether to wrap stand-alone images within a paragraph or not.
301 WrapStandAloneImageWithinParagraph bool
302
303 // Renamed to AutoIDType in 0.144.0.
304 AutoHeadingIDType string `json:"-"`
305 }
306
307 func (p *Parser) Init() error {
308 // Renamed from AutoHeadingIDType to AutoIDType in 0.144.0.
309 if p.AutoHeadingIDType != "" {
310 p.AutoIDType = p.AutoHeadingIDType
311 }
312 return nil
313 }
314
315 type ParserAttribute struct {
316 // Enables custom attributes for titles.
317 Title bool
318 // Enables custom attributes for blocks.
319 Block bool
320 }