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
这是什么?Showdown 是一个 JavaScript 库,可在 Markdown 与 HTML 之间双向转换:既能把 Markdown 转成 HTML,也能把 HTML 转回 Markdown。
它是库还是独立应用?它是一个可嵌入你自己代码中的 JavaScript 库,同时也附带一个内置的命令行工具(CLI)。
我怎么把它添加到项目里?可以通过 NuGet 安装(Install-Package showdownjs),或直接从 jsDelivr、cdnjs、unpkg 等 CDN 加载;它既可在浏览器端运行,也可通过 Node.js 在服务器端运行。
我需要 Node.js 或其他运行环境吗?只有在服务器端使用,或想构建、测试它时才需要;它要求支持的 Node.js 版本(package engines 中为 >=20),构建和测试还需要 npm/npx。
在不可信的 Markdown 输入上使用安全吗?不安全。Showdown 默认不会对输出做净化,因此不可信的输入可能导致 XSS 攻击;你需要启用 safeMode,并且仍需将结果交给 DOMPurify 之类的净化器处理。
它支持哪些浏览器?它曾在 Firefox 1.5/2.0、Chrome 12、IE 6/7、Safari 2.0.4、Opera 8.54/9.10 等老旧浏览器上测试过,理论上应可在任何支持 ECMA 262 3rd Edition 的浏览器中运行。
Showdown 中的 Markdown flavors 是什么?flavors 是一组预设配置,用来让 Showdown 模拟各种常见的 Markdown 方言,包括 original(Gruber 规范)、vanilla、gfm(GitHub Flavored Markdown)和 commonmark。
我能给 Showdown 添加自定义语法吗?可以。Showdown 支持扩展以增加功能,既可用于客户端也可用于服务器端,并且有一个样板仓库,可用来创建你自己的扩展。
它能与 Angular 或 Vue 等框架集成吗?可以。目前有官方或社区提供的集成方案,包括 AngularJS、TypeScript(通过 DefinitelyTyped)、SystemJS/JSPM,以及 Vue(通过 vue-showdown)。
Showdown 支持 GitHub 风格的表格和任务列表吗?支持。GFM 表格和任务列表作为可选项提供(对应 tables 和 tasklists 选项),GFM 代码块则默认启用。
Creator
showdownjs
Size
10.3 MB
Stars
14.9K
Age
17y
Commits · 90 Days