CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-showdown

A Markdown to HTML converter written in Javascript

Pending
Overview
Eval results
Files

flavor-management.mddocs/

Flavor Management

Flavor management for applying preset configuration bundles that match different Markdown dialects and use cases.

Capabilities

setFlavor

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): void

Usage 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();

getFlavor

Gets the currently active global flavor.

/**
 * Get the currently set flavor
 * @returns Current flavor name
 */
showdown.getFlavor(): string

Usage 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');
}

getFlavorOptions

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 | undefined

Usage 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]
));

Available Flavors

vanilla

Default Showdown behavior with minimal options enabled.

showdown.setFlavor('vanilla');
// Equivalent to showdown.getDefaultOptions(true)

Key characteristics:

  • Basic Markdown support
  • No GitHub extensions
  • Conservative parsing
  • Maximum compatibility

github

GitHub Flavored Markdown compatibility.

showdown.setFlavor('github');

Enabled options:

  • omitExtraWLInCodeBlocks: true
  • simplifiedAutoLink: true
  • excludeTrailingPunctuationFromURLs: true
  • literalMidWordUnderscores: true
  • strikethrough: true
  • tables: true
  • tablesHeaderId: true
  • ghCodeBlocks: true
  • tasklists: true
  • disableForced4SpacesIndentedSublists: true
  • simpleLineBreaks: true
  • requireSpaceBeforeHeadingText: true
  • ghCompatibleHeaderId: true
  • ghMentions: true
  • backslashEscapesHTMLTags: true
  • emoji: true
  • splitAdjacentBlockquotes: true

ghost

Ghost platform compatibility.

showdown.setFlavor('ghost');

Enabled options:

  • omitExtraWLInCodeBlocks: true
  • parseImgDimensions: true
  • simplifiedAutoLink: true
  • excludeTrailingPunctuationFromURLs: true
  • literalMidWordUnderscores: true
  • strikethrough: true
  • tables: true
  • tablesHeaderId: true
  • ghCodeBlocks: true
  • tasklists: true
  • smoothLivePreview: true
  • simpleLineBreaks: true
  • requireSpaceBeforeHeadingText: true
  • ghMentions: false
  • encodeEmails: true

original

Original Markdown behavior (closest to Gruber's spec).

showdown.setFlavor('original');

Key characteristics:

  • noHeaderId: true
  • ghCodeBlocks: false
  • Minimal extensions
  • Strict parsing

allOn

All available options enabled (useful for testing).

showdown.setFlavor('allOn');

Key characteristics:

  • Every option set to true
  • Maximum feature set
  • May produce unexpected results
  • Primarily for development/testing

Flavor Usage Patterns

Per-Application Flavor

Set 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();

Mixed Flavor Usage

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');

Custom Flavor Creation

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);

Error Handling

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

docs

cli.md

core-conversion.md

event-system.md

extension-system.md

flavor-management.md

global-configuration.md

index.md

instance-configuration.md

tile.json