0
# Global Configuration
1
2
Global configuration methods for managing options that affect all Showdown instances unless overridden locally.
3
4
## Capabilities
5
6
### setOption
7
8
Sets a global option that affects all new Converter instances.
9
10
```javascript { .api }
11
/**
12
* Set a global option
13
* @param key - Option name
14
* @param value - Option value
15
* @returns showdown object for chaining
16
*/
17
showdown.setOption(key: string, value: any): showdown
18
```
19
20
**Usage Examples:**
21
22
```javascript
23
// Enable strikethrough globally
24
showdown.setOption('strikethrough', true);
25
26
// Set header prefix globally
27
showdown.setOption('prefixHeaderId', 'section-');
28
29
// All new converters will inherit these settings
30
const converter1 = new showdown.Converter();
31
const converter2 = new showdown.Converter();
32
```
33
34
### getOption
35
36
Gets the value of a global option.
37
38
```javascript { .api }
39
/**
40
* Get a global option value
41
* @param key - Option name
42
* @returns Option value
43
*/
44
showdown.getOption(key: string): any
45
```
46
47
**Usage Examples:**
48
49
```javascript
50
// Set and get an option
51
showdown.setOption('tables', true);
52
const tablesEnabled = showdown.getOption('tables');
53
console.log(tablesEnabled); // true
54
55
// Check if an option is set
56
const headerIdPrefix = showdown.getOption('prefixHeaderId');
57
if (headerIdPrefix) {
58
console.log('Header IDs will be prefixed with:', headerIdPrefix);
59
}
60
```
61
62
### getOptions
63
64
Gets all global options as an object.
65
66
```javascript { .api }
67
/**
68
* Get all global options
69
* @returns Object containing all global options
70
*/
71
showdown.getOptions(): ConverterOptions
72
```
73
74
**Usage Examples:**
75
76
```javascript
77
// Get all current global options
78
const globalOptions = showdown.getOptions();
79
console.log(globalOptions);
80
81
// Check multiple options
82
const options = showdown.getOptions();
83
if (options.tables && options.strikethrough) {
84
console.log('Both tables and strikethrough are enabled');
85
}
86
87
// Create converter with modified global options
88
const customOptions = { ...showdown.getOptions(), emoji: true };
89
const converter = new showdown.Converter(customOptions);
90
```
91
92
### resetOptions
93
94
Resets all global options to their default values.
95
96
```javascript { .api }
97
/**
98
* Reset global options to default values
99
*/
100
showdown.resetOptions(): void
101
```
102
103
**Usage Examples:**
104
105
```javascript
106
// Set some global options
107
showdown.setOption('tables', true);
108
showdown.setOption('strikethrough', true);
109
showdown.setOption('emoji', true);
110
111
// Reset to defaults
112
showdown.resetOptions();
113
114
// All options are now back to default values
115
const options = showdown.getOptions();
116
console.log(options.tables); // false (default)
117
console.log(options.strikethrough); // false (default)
118
```
119
120
### getDefaultOptions
121
122
Gets the default options configuration.
123
124
```javascript { .api }
125
/**
126
* Get the default options
127
* @param simple - If true, returns simplified format
128
* @returns Default options object
129
*/
130
showdown.getDefaultOptions(simple?: boolean): ConverterOptions
131
```
132
133
**Usage Examples:**
134
135
```javascript
136
// Get default options in detailed format
137
const defaultOptions = showdown.getDefaultOptions();
138
console.log(defaultOptions);
139
140
// Get default options in simple format
141
const simpleDefaults = showdown.getDefaultOptions(true);
142
console.log(simpleDefaults);
143
144
// Compare current options with defaults
145
const currentOptions = showdown.getOptions();
146
const defaults = showdown.getDefaultOptions(true);
147
148
Object.keys(defaults).forEach(key => {
149
if (currentOptions[key] !== defaults[key]) {
150
console.log(`${key} changed from ${defaults[key]} to ${currentOptions[key]}`);
151
}
152
});
153
```
154
155
## Global vs Local Options
156
157
Global options serve as defaults for new Converter instances:
158
159
```javascript
160
// Set global options
161
showdown.setOption('tables', true);
162
showdown.setOption('strikethrough', true);
163
164
// New converter inherits global options
165
const converter1 = new showdown.Converter();
166
console.log(converter1.getOption('tables')); // true
167
168
// But can be overridden locally
169
const converter2 = new showdown.Converter({ tables: false });
170
console.log(converter2.getOption('tables')); // false
171
172
// Global options unchanged
173
console.log(showdown.getOption('tables')); // true
174
```
175
176
## Option Validation
177
178
Showdown performs basic validation on option values:
179
180
```javascript
181
// Boolean options accept truthy/falsy values
182
showdown.setOption('tables', 1); // Treated as true
183
showdown.setOption('tables', ''); // Treated as false
184
185
// String options accept any value
186
showdown.setOption('prefixHeaderId', 'my-prefix-');
187
188
// Invalid option names are accepted but ignored
189
showdown.setOption('nonExistentOption', true);
190
```