-
-
Notifications
You must be signed in to change notification settings - Fork 445
/
MarkdownExtensions.cs
322 lines (299 loc) · 11.7 KB
/
MarkdownExtensions.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
using Markdig.Extensions.Abbreviations;
using Markdig.Extensions.AutoIdentifiers;
using Markdig.Extensions.Bootstrap;
using Markdig.Extensions.Cites;
using Markdig.Extensions.CustomContainers;
using Markdig.Extensions.DefinitionLists;
using Markdig.Extensions.Emoji;
using Markdig.Extensions.EmphasisExtra;
using Markdig.Extensions.Figures;
using Markdig.Extensions.Footers;
using Markdig.Extensions.Footnotes;
using Markdig.Extensions.GenericAttributes;
using Markdig.Extensions.Hardlines;
using Markdig.Extensions.ListExtra;
using Markdig.Extensions.Mathematics;
using Markdig.Extensions.Medias;
using Markdig.Extensions.SmartyPants;
using Markdig.Extensions.Tables;
using Markdig.Parsers;
using Markdig.Parsers.Inlines;
namespace Markdig
{
/// <summary>
/// Provides extension methods for <see cref="MarkdownPipeline"/> to enable several Markdown extensions.
/// </summary>
public static class MarkdownExtensions
{
/// <summary>
/// Uses all extensions except the Emoji.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseAllExtensions(this MarkdownPipeline pipeline)
{
return pipeline
.UseAbbreviation()
.UseAutoIdentifier()
.UseBootstrap()
.UseCite()
.UseCustomContainer()
.UseDefinitionList()
.UseEmphasisExtra()
.UseFigure()
.UseFooter()
.UseFootnotes()
.UseGridTable()
.UseMath()
.UseMedia()
.UsePipeTable()
.UseSoftlineBreakAsHardlineBreak()
.UseSmartyPants()
.UseGenericAttributes(); // Must be last as it is one parser that is modifying other parsers
}
/// <summary>
/// Uses the custom container extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseCustomContainer(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<CustomContainerExtension>();
return pipeline;
}
/// <summary>
/// Uses the media extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UseMedia(this MarkdownPipeline pipeline, MediaOptions options = null)
{
if (!pipeline.Extensions.Contains<MediaExtension>())
{
pipeline.Extensions.Add(new MediaExtension(options));
}
return pipeline;
}
/// <summary>
/// Uses the auto-identifier extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UseAutoIdentifier(this MarkdownPipeline pipeline, AutoIdentifierOptions options = AutoIdentifierOptions.Default)
{
if (!pipeline.Extensions.Contains<AutoIdentifierExtension>())
{
pipeline.Extensions.Add(new AutoIdentifierExtension(options));
}
return pipeline;
}
/// <summary>
/// Uses the SmartyPants extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UseSmartyPants(this MarkdownPipeline pipeline, SmartyPantOptions options = null)
{
if (!pipeline.Extensions.Contains<SmartyPantsExtension>())
{
pipeline.Extensions.Add(new SmartyPantsExtension(options));
}
return pipeline;
}
/// <summary>
/// Uses the boostrap extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseBootstrap(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<BootstrapExtension>();
return pipeline;
}
/// <summary>
/// Uses the math extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseMath(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<MathExtension>();
return pipeline;
}
/// <summary>
/// Uses the figure extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseFigure(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<FigureExtension>();
return pipeline;
}
/// <summary>
/// Uses the custom abbreviation extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseAbbreviation(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<AbbreviationExtension>();
return pipeline;
}
/// <summary>
/// Uses the definition lists extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseDefinitionList(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<DefinitionListExtension>();
return pipeline;
}
/// <summary>
/// Uses the pipe table extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UsePipeTable(this MarkdownPipeline pipeline, PipeTableOptions options = null)
{
if (!pipeline.Extensions.Contains<PipeTableExtension>())
{
pipeline.Extensions.Add(new PipeTableExtension(options));
}
return pipeline;
}
/// <summary>
/// Uses the grid table extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseGridTable(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<GridTableExtension>();
return pipeline;
}
/// <summary>
/// Uses the cite extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseCite(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<CiteExtension>();
return pipeline;
}
/// <summary>
/// Uses the footer extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseFooter(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<FooterExtension>();
return pipeline;
}
/// <summary>
/// Uses the footnotes extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseFootnotes(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<FootnoteExtension>();
return pipeline;
}
/// <summary>
/// Uses the softline break as hardline break extension
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseSoftlineBreakAsHardlineBreak(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<SoftlineBreakAsHardlineExtension>();
return pipeline;
}
/// <summary>
/// Uses the strikethrough superscript, subscript, inserted and marked text extensions.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <param name="options">The options to enable.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UseEmphasisExtra(this MarkdownPipeline pipeline, EmphasisExtraOptions options = EmphasisExtraOptions.Default)
{
if (!pipeline.Extensions.Contains<EmphasisExtraExtension>())
{
pipeline.Extensions.Add(new EmphasisExtraExtension(options));
}
return pipeline;
}
/// <summary>
/// Uses the list extra extension to add support for `a.`, `A.`, `i.` and `I.` ordered list items.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>
/// The modified pipeline
/// </returns>
public static MarkdownPipeline UseListExtra(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<ListExtraExtension>();
return pipeline;
}
/// <summary>
/// Uses the generic attributes extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseGenericAttributes(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<GenericAttributesExtension>();
return pipeline;
}
/// <summary>
/// Uses the emoji and smiley extension.
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline UseEmojiAndSmiley(this MarkdownPipeline pipeline)
{
pipeline.Extensions.AddIfNotAlready<EmojiExtension>();
return pipeline;
}
/// <summary>
/// This will disable the HTML support in the markdown processor (for constraint/safe parsing).
/// </summary>
/// <param name="pipeline">The pipeline.</param>
/// <returns>The modified pipeline</returns>
public static MarkdownPipeline DisableHtml(this MarkdownPipeline pipeline)
{
var parser = pipeline.BlockParsers.Find<HtmlBlockParser>();
if (parser != null)
{
pipeline.BlockParsers.Remove(parser);
}
var inlineParser = pipeline.InlineParsers.Find<AutolineInlineParser>();
if (inlineParser != null)
{
inlineParser.EnableHtmlParsing = false;
}
return pipeline;
}
}
}