showdown README

The project's README from github.com/showdownjs/showdown. As one markdown file: README.md.

Showdown

Build Status: Linux Build Status: Windows Browserstack Tests npm version Bower version Join the chat at https://gitter.im/showdownjs/showdown Donate


Showdown is a JavaScript Bidirectional Markdown HTML converter, based on the original works by John Gruber. Showdown can be used client side (in the browser) or server side (with Node.js). Showdown can convert Markdown to HTML and HTML to Markdown.

Live DEMO

http://demo.showdownjs.eu/

As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money.

If you like our work and find our library useful, please donate through PayPal! Your contribution will be greatly appreciated and help me continue to develop this awesome library.

License

ShowdownJS (from v2.0 onwards) is released under the MIT license. Previous versions are released under BSD.

Who uses Showdown (or a fork)

Installation

Download tarball

You can download the latest release tarball directly from releases.

Bower

bower install showdown

npm (server-side)

npm install showdown

NuGet package

PM> Install-Package showdownjs

The NuGet Packages can be found here.

CDN

You can also use one of several CDNs available:

Note: replace <version tag> with an actual full length version you're interested in e.g. 1.9.0

Browser Compatibility

Showdown has been tested successfully with:

In theory, Showdown will work in any browser that supports ECMA 262 3rd Edition (JavaScript 1.5). The converter itself might even work in things that aren't web browsers, like Acrobat. No promises.

Node compatibility

Showdown is intended to work on any supported Node.js version (see the Node.js releases schedule. The code may work with previous versions of Node.js, but no accomidations are made to ensure it does.

Legacy version

If you're looking for showdown v<1.0.0, you can find it in the legacy branch.

Changelog

You can check the full changelog

Extended documentation

Check our wiki pages for examples and a more in-depth documentation.

Quick Example

Node

var showdown  = require('showdown'),
    converter = new showdown.Converter(),
    text      = '# hello, markdown!',
    html      = converter.makeHtml(text);

Browser

var converter = new showdown.Converter(),
    text      = '# hello, markdown!',
    html      = converter.makeHtml(text);

Output

Both examples should output...

    <h1 id="hello-markdown">hello, markdown!</h1>

Options

You can change some of showdown's default behavior through options.

Setting options

Options can be set:

Globally

Setting a "global" option affects all instances of showdown

showdown.setOption('optionKey', 'value');

Locally

Setting a "local" option only affects the specified Converter object. Local options can be set:

Getting an option

Showdown provides 2 methods (both local and global) to retrieve previous set options.

getOption()

// Global
var myOption = showdown.getOption('optionKey');

//Local
var myOption = converter.getOption('optionKey');

getOptions()

// Global
var showdownGlobalOptions = showdown.getOptions();

//Local
var thisConverterSpecificOptions = converter.getOptions();

Retrieve the default options

You can get showdown's default options with:

var defaultOptions = showdown.getDefaultOptions();

Valid Options

NOTE: this option replaces the removed noHeaderId, prefixHeaderId and rawHeaderId options. noHeaderId: true → headerIds: false; prefixHeaderId: 'foo' → headerIds: {prefix: 'foo'}; rawHeaderId: true → headerIds: {raw: true}.

Security options

By default Showdown follows the trusted-input model and does not sanitize (see XSS vulnerability). The options below add opt-in, defense-in-depth hardening for when the Markdown source is untrusted. They are not a replacement for a dedicated HTML sanitizer.

CommonMark options (since v3.0.0)

These options make Showdown follow the CommonMark spec. They are boolean and default to false, and are best enabled via the commonmark flavor. See the Spec compliance docs for details.

NOTE: In the CLI tool, all options are disabled by default — including those (like ghCodeBlocks) that are enabled by default in the Node and browser builds.

Flavors

You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.

Currently, the following flavors are available:

Global

showdown.setFlavor('gfm');

Instance

converter.setFlavor('gfm');

CLI Tool

Showdown also comes bundled with a Command Line Interface tool. You can check the CLI wiki page for more info

Integration with AngularJS

ShowdownJS project also provides seamlessly integration with AngularJS via a "plugin". Please visit https://github.com/showdownjs/ngShowdown for more information.

Integration with TypeScript

If you're using TypeScript you maybe want to use the types from DefinitelyTyped

Integration with SystemJS/JSPM

Integration with SystemJS can be obtained via the third party "system-md" plugin.

Integration with VueJS

To use ShowdownJS as a Vue component quickly, you can check vue-showdown.

XSS vulnerability

Showdown doesn't sanitize the input. This is by design since markdown relies on it to allow certain features to be correctly parsed into HTML. This, however, means XSS injection is quite possible.

If your Markdown source is untrusted, you should:

  1. Enable the safeMode option — it blocks dangerous URL schemes (javascript:, etc.) and escapes raw HTML tags / event handlers as defense-in-depth; and
  2. Run the generated HTML through a dedicated sanitizer such as DOMPurify before inserting it into the DOM, and serve a Content-Security-Policy. safeMode is not a full HTML sanitizer and does not replace this step; and
  3. Cap the size of untrusted input (and/or convert off the request thread with a timeout) — converting very large adversarial inputs can be CPU-intensive.

Please refer to the wiki article Markdown's XSS Vulnerability (and how to mitigate it) for more information.

Extensions

Showdown allows additional functionality to be loaded via extensions. (you can find a list of known showdown extensions here) You can also find a boilerplate, to create your own extensions in this repository

Client-side Extension Usage

<script src="showdown.js" />
<script src="twitter-extension.js" />

var converter = new showdown.Converter({ extensions: ['twitter'] });

Server-side Extension Usage

var showdown    = require('showdown'),
    myExtension = require('myExtension'),
    converter = new showdown.Converter({ extensions: ['myExtension'] });

Building

Building your clone of the repository is easy.

Prerequesites: a currently supported Node.js, npm and npx must be installed.

  1. run npm install.

  2. run npx grunt build (see Gruntfile.js). This command:

    1. Cleans the repo.
    2. Checks code quality (JSHint and ESLint).
    3. Runs tests.
    4. Creates the distributable and minified files in the dist folder.

Tests

A suite of tests is available which require Node.js. Once Node is installed, run the following command from the project root to install the dependencies:

npm install

Once installed the tests can be run from the project root using:

npm test

New test cases can easily be added. Create a markdown file (ending in .md) which contains the markdown to test. Create a .html file of the exact same name. It will automatically be tested when the tests are executed with mocha.

Contributing

If you wish to contribute please read the following quick guide.

Want a Feature?

You can request a new feature by submitting an issue. If you would like to implement a new feature feel free to issue a Pull Request.

Pull requests (PRs)

PRs are awesome. However, before you submit your pull request consider the following guidelines:

If you have time to contribute to this project, we feel obliged that you get credit for it. These rules enable us to review your PR faster and will give you appropriate credit in your GitHub profile. We thank you in advance for your contribution!

Joining the team

We're looking for members to help maintaining Showdown. Please see this issue to express interest or comment on this note.

Credits

Full credit list at https://github.com/showdownjs/showdown/blob/master/CREDITS.md

Showdown is powered by:
webstorm

showdown (showdownjs/showdown)

Searching Database…

14.9K ·GitHub
What is this?Showdown is a JavaScript library that converts Markdown to HTML and HTML back to Markdown, bidirectionally.
Is it a library or a standalone app?It is a JavaScript library you embed in your own code, though it also ships a bundled CLI tool for command-line use.
How do I add it to a project?Install it via NuGet (Install-Package showdownjs) or load it straight from a CDN like jsDelivr, cdnjs, or unpkg; it works both client-side in the browser and server-side with Node.js.
Do I need Node.js or any other runtime?Only if you use it server-side or want to build/test it; it needs a supported Node.js version (>=20 per package engines) plus npm/npx for building and testing.
Is it safe to use on untrusted Markdown input?No, by default Showdown does not sanitize output, so untrusted input can lead to XSS; you need to enable safeMode and still run the result through a sanitizer like DOMPurify.
Which browsers does it support?It's been tested on old browsers like Firefox 1.5/2.0, Chrome 12, IE 6/7, Safari 2.0.4, Opera 8.54/9.10, and should work in any browser supporting ECMA 262 3rd Edition.
What are Markdown flavors in Showdown?Flavors are presets that configure Showdown's options to mimic popular Markdown dialects, including original (Gruber's spec), vanilla, gfm (GitHub Flavored Markdown), and commonmark.
Can I extend Showdown with custom syntax?Yes, Showdown supports extensions for additional functionality, both client-side and server-side, and there's a boilerplate repository for creating your own extensions.
Does it integrate with frameworks like Angular or Vue?Yes, there are official/community integrations for AngularJS, TypeScript (via DefinitelyTyped), SystemJS/JSPM, and Vue (via vue-showdown).
Does Showdown support GitHub-style tables and tasklists?Yes, GFM tables and tasklists are supported as opt-in options (tables and tasklists), along with GFM code blocks enabled by default.
Creator
showdownjs
Size
10.3 MB
Stars
14.9K
Age
17y
Commits · 90 Days