A Markdown to HTML converter written in Javascript
—
Flavor management for applying preset configuration bundles that match different Markdown dialects and use cases.
Sets the global flavor, applying a preset configuration bundle.
/**
* Set the flavor showdown should use as default
* @param name - Flavor name ('vanilla', 'github', 'ghost', 'original', 'allOn')
*/
showdown.setFlavor(name: string): voidUsage Examples:
// Set GitHub Flavored Markdown compatibility
showdown.setFlavor('github');
// Set original Markdown behavior
showdown.setFlavor('original');
// Set vanilla (default) flavor
showdown.setFlavor('vanilla');
// All new converters will use the selected flavor
const converter = new showdown.Converter();Gets the currently active global flavor.
/**
* Get the currently set flavor
* @returns Current flavor name
*/
showdown.getFlavor(): stringUsage Examples:
// Check current flavor
const currentFlavor = showdown.getFlavor();
console.log('Current flavor:', currentFlavor);
// Conditional logic based on flavor
if (showdown.getFlavor() === 'github') {
console.log('Using GitHub-compatible settings');
}Gets the options configuration for a specific flavor.
/**
* Get the options of a specified flavor
* @param name - Flavor name
* @returns Flavor options object, or undefined if flavor not found
*/
showdown.getFlavorOptions(name: string): ConverterOptions | undefinedUsage Examples:
// Get GitHub flavor options
const githubOptions = showdown.getFlavorOptions('github');
console.log(githubOptions);
// Check if a flavor exists
const customOptions = showdown.getFlavorOptions('custom');
if (customOptions) {
console.log('Custom flavor is available');
} else {
console.log('Custom flavor not found');
}
// Compare flavor options
const vanillaOpts = showdown.getFlavorOptions('vanilla');
const githubOpts = showdown.getFlavorOptions('github');
console.log('Differences:', Object.keys(githubOpts).filter(
key => githubOpts[key] !== vanillaOpts[key]
));Default Showdown behavior with minimal options enabled.
showdown.setFlavor('vanilla');
// Equivalent to showdown.getDefaultOptions(true)Key characteristics:
GitHub Flavored Markdown compatibility.
showdown.setFlavor('github');Enabled options:
omitExtraWLInCodeBlocks: truesimplifiedAutoLink: trueexcludeTrailingPunctuationFromURLs: trueliteralMidWordUnderscores: truestrikethrough: truetables: truetablesHeaderId: trueghCodeBlocks: truetasklists: truedisableForced4SpacesIndentedSublists: truesimpleLineBreaks: truerequireSpaceBeforeHeadingText: trueghCompatibleHeaderId: trueghMentions: truebackslashEscapesHTMLTags: trueemoji: truesplitAdjacentBlockquotes: trueGhost platform compatibility.
showdown.setFlavor('ghost');Enabled options:
omitExtraWLInCodeBlocks: trueparseImgDimensions: truesimplifiedAutoLink: trueexcludeTrailingPunctuationFromURLs: trueliteralMidWordUnderscores: truestrikethrough: truetables: truetablesHeaderId: trueghCodeBlocks: truetasklists: truesmoothLivePreview: truesimpleLineBreaks: truerequireSpaceBeforeHeadingText: trueghMentions: falseencodeEmails: trueOriginal Markdown behavior (closest to Gruber's spec).
showdown.setFlavor('original');Key characteristics:
noHeaderId: trueghCodeBlocks: falseAll available options enabled (useful for testing).
showdown.setFlavor('allOn');Key characteristics:
trueSet once at application startup:
// In your app initialization
showdown.setFlavor('github');
// All converters throughout the app use GitHub flavor
const converter1 = new showdown.Converter();
const converter2 = new showdown.Converter();Different flavors for different contexts:
// For GitHub-compatible content
showdown.setFlavor('github');
const githubConverter = new showdown.Converter();
// For original Markdown
showdown.setFlavor('original');
const originalConverter = new showdown.Converter();
// Restore default
showdown.setFlavor('vanilla');Create custom configurations based on existing flavors:
// Start with GitHub flavor
const githubOptions = showdown.getFlavorOptions('github');
// Create custom variant
const customOptions = {
...githubOptions,
emoji: false, // Disable emoji
tables: false, // Disable tables
customOption: true // Add custom option
};
const converter = new showdown.Converter(customOptions);try {
showdown.setFlavor('nonexistent');
} catch (error) {
console.error('Invalid flavor:', error.message);
// Error: nonexistent flavor was not found
}
// Safe flavor checking
const flavorOptions = showdown.getFlavorOptions('unknown');
if (!flavorOptions) {
console.log('Flavor not available, using default');
showdown.setFlavor('vanilla');
}Install with Tessl CLI
npx tessl i tessl/npm-showdown