0
# Flavor Management
1
2
Flavor management for applying preset configuration bundles that match different Markdown dialects and use cases.
3
4
## Capabilities
5
6
### setFlavor
7
8
Sets the global flavor, applying a preset configuration bundle.
9
10
```javascript { .api }
11
/**
12
* Set the flavor showdown should use as default
13
* @param name - Flavor name ('vanilla', 'github', 'ghost', 'original', 'allOn')
14
*/
15
showdown.setFlavor(name: string): void
16
```
17
18
**Usage Examples:**
19
20
```javascript
21
// Set GitHub Flavored Markdown compatibility
22
showdown.setFlavor('github');
23
24
// Set original Markdown behavior
25
showdown.setFlavor('original');
26
27
// Set vanilla (default) flavor
28
showdown.setFlavor('vanilla');
29
30
// All new converters will use the selected flavor
31
const converter = new showdown.Converter();
32
```
33
34
### getFlavor
35
36
Gets the currently active global flavor.
37
38
```javascript { .api }
39
/**
40
* Get the currently set flavor
41
* @returns Current flavor name
42
*/
43
showdown.getFlavor(): string
44
```
45
46
**Usage Examples:**
47
48
```javascript
49
// Check current flavor
50
const currentFlavor = showdown.getFlavor();
51
console.log('Current flavor:', currentFlavor);
52
53
// Conditional logic based on flavor
54
if (showdown.getFlavor() === 'github') {
55
console.log('Using GitHub-compatible settings');
56
}
57
```
58
59
### getFlavorOptions
60
61
Gets the options configuration for a specific flavor.
62
63
```javascript { .api }
64
/**
65
* Get the options of a specified flavor
66
* @param name - Flavor name
67
* @returns Flavor options object, or undefined if flavor not found
68
*/
69
showdown.getFlavorOptions(name: string): ConverterOptions | undefined
70
```
71
72
**Usage Examples:**
73
74
```javascript
75
// Get GitHub flavor options
76
const githubOptions = showdown.getFlavorOptions('github');
77
console.log(githubOptions);
78
79
// Check if a flavor exists
80
const customOptions = showdown.getFlavorOptions('custom');
81
if (customOptions) {
82
console.log('Custom flavor is available');
83
} else {
84
console.log('Custom flavor not found');
85
}
86
87
// Compare flavor options
88
const vanillaOpts = showdown.getFlavorOptions('vanilla');
89
const githubOpts = showdown.getFlavorOptions('github');
90
console.log('Differences:', Object.keys(githubOpts).filter(
91
key => githubOpts[key] !== vanillaOpts[key]
92
));
93
```
94
95
## Available Flavors
96
97
### vanilla
98
99
Default Showdown behavior with minimal options enabled.
100
101
```javascript
102
showdown.setFlavor('vanilla');
103
// Equivalent to showdown.getDefaultOptions(true)
104
```
105
106
**Key characteristics:**
107
- Basic Markdown support
108
- No GitHub extensions
109
- Conservative parsing
110
- Maximum compatibility
111
112
### github
113
114
GitHub Flavored Markdown compatibility.
115
116
```javascript
117
showdown.setFlavor('github');
118
```
119
120
**Enabled options:**
121
- `omitExtraWLInCodeBlocks: true`
122
- `simplifiedAutoLink: true`
123
- `excludeTrailingPunctuationFromURLs: true`
124
- `literalMidWordUnderscores: true`
125
- `strikethrough: true`
126
- `tables: true`
127
- `tablesHeaderId: true`
128
- `ghCodeBlocks: true`
129
- `tasklists: true`
130
- `disableForced4SpacesIndentedSublists: true`
131
- `simpleLineBreaks: true`
132
- `requireSpaceBeforeHeadingText: true`
133
- `ghCompatibleHeaderId: true`
134
- `ghMentions: true`
135
- `backslashEscapesHTMLTags: true`
136
- `emoji: true`
137
- `splitAdjacentBlockquotes: true`
138
139
### ghost
140
141
Ghost platform compatibility.
142
143
```javascript
144
showdown.setFlavor('ghost');
145
```
146
147
**Enabled options:**
148
- `omitExtraWLInCodeBlocks: true`
149
- `parseImgDimensions: true`
150
- `simplifiedAutoLink: true`
151
- `excludeTrailingPunctuationFromURLs: true`
152
- `literalMidWordUnderscores: true`
153
- `strikethrough: true`
154
- `tables: true`
155
- `tablesHeaderId: true`
156
- `ghCodeBlocks: true`
157
- `tasklists: true`
158
- `smoothLivePreview: true`
159
- `simpleLineBreaks: true`
160
- `requireSpaceBeforeHeadingText: true`
161
- `ghMentions: false`
162
- `encodeEmails: true`
163
164
### original
165
166
Original Markdown behavior (closest to Gruber's spec).
167
168
```javascript
169
showdown.setFlavor('original');
170
```
171
172
**Key characteristics:**
173
- `noHeaderId: true`
174
- `ghCodeBlocks: false`
175
- Minimal extensions
176
- Strict parsing
177
178
### allOn
179
180
All available options enabled (useful for testing).
181
182
```javascript
183
showdown.setFlavor('allOn');
184
```
185
186
**Key characteristics:**
187
- Every option set to `true`
188
- Maximum feature set
189
- May produce unexpected results
190
- Primarily for development/testing
191
192
## Flavor Usage Patterns
193
194
### Per-Application Flavor
195
196
Set once at application startup:
197
198
```javascript
199
// In your app initialization
200
showdown.setFlavor('github');
201
202
// All converters throughout the app use GitHub flavor
203
const converter1 = new showdown.Converter();
204
const converter2 = new showdown.Converter();
205
```
206
207
### Mixed Flavor Usage
208
209
Different flavors for different contexts:
210
211
```javascript
212
// For GitHub-compatible content
213
showdown.setFlavor('github');
214
const githubConverter = new showdown.Converter();
215
216
// For original Markdown
217
showdown.setFlavor('original');
218
const originalConverter = new showdown.Converter();
219
220
// Restore default
221
showdown.setFlavor('vanilla');
222
```
223
224
### Custom Flavor Creation
225
226
Create custom configurations based on existing flavors:
227
228
```javascript
229
// Start with GitHub flavor
230
const githubOptions = showdown.getFlavorOptions('github');
231
232
// Create custom variant
233
const customOptions = {
234
...githubOptions,
235
emoji: false, // Disable emoji
236
tables: false, // Disable tables
237
customOption: true // Add custom option
238
};
239
240
const converter = new showdown.Converter(customOptions);
241
```
242
243
## Error Handling
244
245
```javascript
246
try {
247
showdown.setFlavor('nonexistent');
248
} catch (error) {
249
console.error('Invalid flavor:', error.message);
250
// Error: nonexistent flavor was not found
251
}
252
253
// Safe flavor checking
254
const flavorOptions = showdown.getFlavorOptions('unknown');
255
if (!flavorOptions) {
256
console.log('Flavor not available, using default');
257
showdown.setFlavor('vanilla');
258
}
259
```