UNPKG

19.8 kBMarkdownView Raw
1![Showdown][sd-logo]
2
3![Build Status: Linux](https://github.com/showdownjs/showdown/actions/workflows/node.js.yml/badge.svg)
4[![npm version](https://badge.fury.io/js/showdown.svg)](http://badge.fury.io/js/showdown)
5[![Bower version](https://badge.fury.io/bo/showdown.svg)](http://badge.fury.io/bo/showdown)
6[![Join the chat at https://gitter.im/showdownjs/showdown](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/showdownjs/showdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7[![Greenkeeper badge](https://badges.greenkeeper.io/showdownjs/showdown.svg)](https://greenkeeper.io/)
8[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/tiviesantos)
9
10------
11
12Showdown is a Javascript Markdown to HTML converter, based on the original works by John Gruber.
13Showdown can be used client side (in the browser) or server side (with NodeJs).
14
15## Live DEMO
16
17Check a live Demo here http://demo.showdownjs.com/
18
19## Funding
20
21As you know, ShowdownJS is a free library and it will remain free forever. However, maintaining and improving the library costs time and money.
22
23If you like our work and find our library useful, please donate through [paypal](https://www.paypal.me/tiviesantos)!!
24Your contribution will be greatly appreciated and help us continue to develop this awesome library.
25
26## License
27
28ShowdownJS v 2.0 is release under the MIT version.
29Previous versions are release under BSD.
30
31## Who uses Showdown (or a fork)
32
33 - [GoogleCloudPlatform](https://github.com/GoogleCloudPlatform)
34 - [Meteor](https://www.meteor.com/)
35 - [Stackexchange](http://stackexchange.com/) - forked as [PageDown](https://code.google.com/p/pagedown/)
36 - [docular](https://github.com/Vertafore/docular)
37 - [md-page](https://github.com/oscarmorrison/md-page)
38 - [QCObjects](https://qcobjects.dev)
39 - [and some others...](https://www.npmjs.com/browse/depended/showdown)
40
41## Installation
42
43### Download tarball
44
45You can download the latest release tarball directly from [releases][releases]
46
47### Bower
48
49 bower install showdown
50
51### npm (server-side)
52
53 npm install showdown
54
55### NuGet package
56
57 PM> Install-Package showdownjs
58
59The NuGet Packages can be [found here](https://www.nuget.org/packages/showdownjs/).
60
61### CDN
62
63You can also use one of several CDNs available:
64
65* jsDelivr
66
67 https://cdn.jsdelivr.net/npm/showdown@<version tag>/dist/showdown.min.js
68
69* cdnjs
70
71 https://cdnjs.cloudflare.com/ajax/libs/showdown/<version tag>/showdown.min.js
72
73* unpkg
74
75 https://unpkg.com/showdown/dist/showdown.min.js
76
77*Note*: replace `<version tag>` with an actual full length version you're interested in e.g. `1.9.0`
78## Browser Compatibility
79
80Showdown has been tested successfully with:
81
82 * Firefox 1.5 and 2.0
83 * Chrome 12.0
84 * Internet Explorer 6 and 7
85 * Safari 2.0.4
86 * Opera 8.54 and 9.10
87 * Netscape 8.1.2
88 * Konqueror 3.5.4
89
90In theory, Showdown will work in any browser that supports ECMA 262 3rd Edition (JavaScript 1.5).
91The converter itself might even work in things that aren't web browsers, like Acrobat. No promises.
92
93
94## Node compatibility
95
96Showdown supports node versions in the "Current", "Active" and "Maintenance" phases. Currently this includes Node 12.x, 14.x, 16.x and 17.x. See the [node release roadmap for more details](12.x, 14.x, 16.x, 17.x).
97
98Other versions of node may likely work, but they are not tested regularly.
99
100## Pervious versions
101
102If you're looking for showdown v<1.0.0, you can find it in the [**legacy branch**][legacy-branch].
103
104If you are looking for showdown 1.* you can find it in the [version_1.x][version_1.x] branch.
105
106## Changelog
107
108You can check the full [changelog][changelog]
109
110## Extended documentation
111Check our [wiki pages][wiki] for examples and a more in-depth documentation.
112
113
114## Quick Example
115
116### Node
117
118**Markdown to HTML**
119```js
120var showdown = require('showdown'),
121 converter = new showdown.Converter(),
122 text = '# hello, markdown!',
123 html = converter.makeHtml(text);
124```
125
126**HTML to Markdown**
127```js
128var showdown = require('showdown'),
129 converter = new showdown.Converter(),
130 html = '<a href="https://patreon.com/showdownjs">Please Support us!</a>',
131 md = converter.makeMarkdown(text);
132```
133
134
135### Browser
136
137```js
138var converter = new showdown.Converter(),
139 html = converter.makeHtml('# hello, markdown!'),
140 md = converter.makeMd('<a href="https://patreon.com/showdownjs">Please Support us!</a>');
141```
142
143### Output
144
145Both examples should output...
146
147```html
148 <h1 id="hellomarkdown">hello, markdown!</h1>
149```
150
151```md
152[Please Support us!](https://patreon.com/showdownjs)
153```
154
155## Options
156
157You can change some of showdown's default behavior through options.
158
159### Setting options
160
161Options can be set:
162
163#### Globally
164
165Setting a "global" option affects all instances of showdown
166
167```js
168showdown.setOption('optionKey', 'value');
169```
170
171#### Locally
172Setting a "local" option only affects the specified Converter object.
173Local options can be set:
174
175 * **through the constructor**
176 ```js
177 var converter = new showdown.Converter({optionKey: 'value'});
178 ```
179
180 * **through the setOption() method**
181 ```js
182 var converter = new showdown.Converter();
183 converter.setOption('optionKey', 'value');
184 ```
185
186### Getting an option
187
188Showdown provides 2 methods (both local and global) to retrieve previous set options.
189
190#### getOption()
191
192```js
193// Global
194var myOption = showdown.getOption('optionKey');
195
196//Local
197var myOption = converter.getOption('optionKey');
198```
199
200#### getOptions()
201
202```js
203// Global
204var showdownGlobalOptions = showdown.getOptions();
205
206//Local
207var thisConverterSpecificOptions = converter.getOptions();
208```
209
210### Retrieve the default options
211
212You can get showdown's default options with:
213```js
214var defaultOptions = showdown.getDefaultOptions();
215```
216
217### Valid Options
218
219 * **omitExtraWLInCodeBlocks**: (boolean) [default false] Omit the trailing newline in a code block. Ex:
220
221 This:
222 ```html
223 <code><pre>var foo = 'bar';
224 </pre></code>
225 ```
226 Becomes this:
227 ```html
228 <code><pre>var foo = 'bar';</pre></code>
229 ```
230
231 * **noHeaderId**: (boolean) [default false] Disable the automatic generation of header ids.
232 Setting to true overrides **prefixHeaderId**
233
234 * **customizedHeaderId**: (boolean) [default false] Use text in curly braces as header id. **(since v1.7.0)**
235 Example:
236 ```
237 ## Sample header {real-id} will use real-id as id
238 ```
239
240 * **ghCompatibleHeaderId**: (boolean) [default false] Generate header ids compatible with github style
241 (spaces are replaced with dashes and a bunch of non alphanumeric chars are removed) **(since v1.5.5)**
242
243 * **prefixHeaderId**: (string/boolean) [default false] Add a prefix to the generated header ids.
244 Passing a string will prefix that string to the header id. Setting to `true` will add a generic 'section' prefix.
245
246 * **rawPrefixHeaderId**: (boolean) [default false] Setting this option to true will prevent showdown from modifying the prefix.
247 This might result in malformed IDs (if, for instance, the " char is used in the prefix).
248 Has no effect if prefixHeaderId is set to false. **(since v 1.7.3)**
249
250 * **rawHeaderId**: (boolean) [default false] Remove only spaces, ' and " from generated header ids (including prefixes),
251 replacing them with dashes (-). WARNING: This might result in malformed ids **(since v1.7.3)**
252
253 * **parseImgDimensions**: (boolean) [default false] Enable support for setting image dimensions from within markdown syntax.
254 Examples:
255 ```
256 ![foo](foo.jpg =100x80) simple, assumes units are in px
257 ![bar](bar.jpg =100x*) sets the height to "auto"
258 ![baz](baz.jpg =80%x5em) Image with width of 80% and height of 5em
259 ```
260
261 * **headerLevelStart**: (integer) [default 1] Set the header starting level. For instance, setting this to 3 means that
262
263 ```md
264 # foo
265 ```
266 will be parsed as
267
268 ```html
269 <h3>foo</h3>
270 ```
271
272 * **simplifiedAutoLink**: (boolean) [default false] Turning this option on will enable automatic linking to urls.
273 This means that:
274
275 ```md
276 some text www.google.com
277 ```
278 will be parsed as
279 ```html
280 <p>some text <a href="www.google.com">www.google.com</a>
281 ```
282
283 * **excludeTrailingPunctuationFromURLs**: (boolean) [default false] This option excludes trailing punctuation from autolinking urls.
284 Punctuation excluded: `. ! ? ( )`. Only applies if **simplifiedAutoLink** option is set to `true`.
285
286 ```md
287 check this link www.google.com!
288 ```
289 will be parsed as
290 ```html
291 <p>check this link <a href="www.google.com">www.google.com</a>!</p>
292 ```
293
294 * **literalMidWordUnderscores**: (boolean) [default false] Turning this on will stop showdown from interpreting
295 underscores in the middle of words as `<em>` and `<strong>` and instead treat them as literal underscores.
296
297 Example:
298
299 ```md
300 some text with__underscores__in middle
301 ```
302 will be parsed as
303 ```html
304 <p>some text with__underscores__in middle</p>
305 ```
306
307 * **literalMidWordAsterisks**: (boolean) [default false] Turning this on will stop showdown from interpreting asterisks
308 in the middle of words as `<em>` and `<strong>` and instead treat them as literal asterisks.
309
310 Example:
311
312 ```md
313 some text with**underscores**in middle
314 ```
315 will be parsed as
316 ```html
317 <p>some text with**underscores**in middle</p>
318 ```
319
320 * **strikethrough**: (boolean) [default false] Enable support for strikethrough syntax.
321 `~~strikethrough~~` as `<del>strikethrough</del>`
322
323 * **tables**: (boolean) [default false] Enable support for tables syntax. Example:
324
325 ```md
326 | h1 | h2 | h3 |
327 |:------|:-------:|--------:|
328 | 100 | [a][1] | ![b][2] |
329 | *foo* | **bar** | ~~baz~~ |
330 ```
331
332 See the wiki for more info
333
334 * **tablesHeaderId**: (boolean) [default false] If enabled adds an id property to table headers tags.
335
336 * **ghCodeBlocks**: (boolean) [default true] Enable support for GFM code block style.
337
338 * **tasklists**: (boolean) [default false] Enable support for GFM tasklists. Example:
339
340 ```md
341 - [x] This task is done
342 - [ ] This is still pending
343 ```
344 * **smoothLivePreview**: (boolean) [default false] Prevents weird effects in live previews due to incomplete input
345
346 * **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template
347 strings in the midst of indented code.
348
349 * **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists
350 by 4 spaces for them to be nested, effectively reverting to the old behavior where 2 or 3 spaces were enough.
351 **(since v1.5.0)**
352
353 * **simpleLineBreaks**: (boolean) [default false] Parses line breaks as `<br>`, like GitHub does, without
354 needing 2 spaces at the end of the line **(since v1.5.1)**
355
356 ```md
357 a line
358 wrapped in two
359 ```
360
361 turns into:
362
363 ```html
364 <p>a line<br>
365 wrapped in two</p>
366 ```
367
368 * **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory **(since v1.5.3)**
369
370 * **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned **(since v1.6.0)**
371
372 * **ghMentionsLink**: (string) [default `https://github.com/{u}`] Changes the link generated by @mentions.
373 Showdown will replace `{u}` with the username. Only applies if ghMentions option is enabled.
374 Example: `@tivie` with ghMentionsOption set to `//mysite.com/{u}/profile` will result in `<a href="//mysite.com/tivie/profile">@tivie</a>`
375
376 * **encodeEmails**: (boolean) [default true] Enable e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities. (since v1.6.1)
377
378 NOTE: Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding.
379
380 * **openLinksInNewWindow**: (boolean) [default false] Open all links in new windows
381 (by adding the attribute `target="_blank"` to `<a>` tags) **(since v1.7.0)**
382
383 * **backslashEscapesHTMLTags**: (boolean) [default false] Support for HTML Tag escaping. ex: `\<div>foo\</div>` **(since v1.7.2)**
384
385 * **emoji**: (boolean) [default false] Enable emoji support. Ex: `this is a :smile: emoji`
386 For more info on available emojis, see https://github.com/showdownjs/showdown/wiki/Emojis **(since v.1.8.0)**
387
388 * **underline**: (boolean) [default false] ***EXPERIMENTAL FEATURE*** Enable support for underline.
389 Syntax is **double** or **triple** **underscores** ex: `__underlined word__`. With this option enabled, underscores are no longer parses into `<em>` and `<strong>`.
390
391 * **ellipsis**: (boolean) [default true] Replaces three dots with the ellipsis unicode character.
392
393 * **completeHTMLDocument**: (boolean) [default false] Outputs a complete html document,
394 including `<html>`, `<head>` and `<body>` tags' instead of an HTML fragment. (since v.1.8.5)
395
396 * **metadata**: (boolean) [default false] Enable support for document metadata (defined at the top of the document
397 between `«««` and `»»»` or between `---` and `---`). (since v.1.8.5)
398
399 ```js
400 var conv = new showdown.Converter({metadata: true});
401 var html = conv.makeHtml(someMd);
402 var metadata = conv.getMetadata(); // returns an object with the document metadata
403 ```
404
405 * **splitAdjacentBlockquotes**: (boolean) [default false] Split adjacent blockquote blocks.(since v.1.8.6)
406
407**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
408
409
410## Flavors
411
412You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.
413
414Currently, the following flavors are available:
415
416 * original - original markdown flavor as in [John Gruber's spec](https://daringfireball.net/projects/markdown/)
417 * vanilla - showdown base flavor (as from v1.3.1)
418 * github - GFM (GitHub Flavored Markdown)
419
420
421### Global
422```javascript
423showdown.setFlavor('github');
424```
425
426### Instance
427```javascript
428converter.setFlavor('github');
429```
430
431
432## CLI Tool
433
434Showdown also comes bundled with a Command Line Interface tool. You can check the [CLI wiki page][cli-wiki] for more info
435
436## Integration with AngularJS
437
438ShowdownJS project also provides seamlessly integration with AngularJS via a "plugin".
439Please visit https://github.com/showdownjs/ngShowdown for more information.
440
441## Integration with TypeScript
442
443If you're using TypeScript you maybe want to use the types from [DefinitelyTyped][definitely-typed]
444
445## Integration with SystemJS/JSPM
446
447Integration with SystemJS can be obtained via the third party ["system-md" plugin](https://github.com/guybedford/system-md).
448
449## Integration with VueJS
450
451To use ShowdownJS as a Vue component quickly, you can check [vue-showdown](https://vue-showdown.js.org/).
452
453## XSS vulnerability
454
455Showdown doesn't sanitize the input. This is by design since markdown relies on it to allow certain features to be correctly parsed into HTML.
456This, however, means XSS injection is quite possible.
457
458Please refer to the wiki article [Markdown's XSS Vulnerability (and how to mitigate it)][xss-wiki]
459for more information.
460
461## Extensions
462
463Showdown allows additional functionality to be loaded via extensions. (you can find a list of known showdown extensions [here][ext-wiki])
464You can also find a boilerplate, to create your own extensions in [this repository][boilerplate-repo]
465
466### Client-side Extension Usage
467
468```html
469<script src="showdown.js"></script>
470<script src="twitter-extension.js"></script>
471<script>
472var converter = new showdown.Converter({ extensions: ['twitter'] });
473</script>
474```
475
476### Server-side Extension Usage
477
478```js
479var showdown = require('showdown'),
480 myExtension = require('myExtension'),
481 converter = new showdown.Converter({ extensions: ['myExtension'] });
482```
483
484## Tests
485
486A suite of tests is available which require node.js. Once node is installed, run the following command from
487the project root to install the dependencies:
488
489 npm install
490
491Once installed the tests can be run from the project root using:
492
493 npm test
494
495New test cases can easily be added. Create a markdown file (ending in `.md`) which contains the markdown to test.
496Create a `.html` file of the exact same name. It will automatically be tested when the tests are executed with `mocha`.
497
498## Contributing
499
500If you wish to contribute please read the following quick guide.
501
502### Want a Feature?
503You can request a new feature by submitting an issue. If you would like to implement a new feature feel free to issue a
504Pull Request.
505
506
507### Pull requests (PRs)
508PRs are awesome. However, before you submit your pull request consider the following guidelines:
509
510 - Search GitHub for an open or closed Pull Request that relates to your submission. You don't want to duplicate effort.
511 - When issuing PRs that change code, make your changes in a new git branch based on master:
512
513 ```bash
514 git checkout -b my-fix-branch master
515 ```
516
517 - Documentation (i.e: README.md) changes can be made directly against master.
518 - Run the full test suite before submitting and make sure all tests pass (obviously =P).
519 - Try to follow our [**coding style rules**][coding-rules].
520 Breaking them prevents the PR to pass the tests.
521 - Refrain from fixing multiple issues in the same pull request. It's preferable to open multiple small PRs instead of one
522 hard to review big one.
523 - If the PR introduces a new feature or fixes an issue, please add the appropriate test case.
524 - We use commit notes to generate the changelog. It's extremely helpful if your commit messages adhere to the
525 [**AngularJS Git Commit Guidelines**][ng-commit-guide].
526 - If we suggest changes then:
527 - Make the required updates.
528 - Re-run the Angular test suite to ensure tests are still passing.
529 - Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
530
531 ```bash
532 git rebase master -i
533 git push origin my-fix-branch -f
534 ```
535 - After your pull request is merged, you can safely delete your branch.
536
537If you have time to contribute to this project, we feel obliged that you get credit for it.
538These rules enable us to review your PR faster and will give you appropriate credit in your GitHub profile.
539We thank you in advance for your contribution!
540
541### Joining the team
542We're looking for members to help maintaining Showdown.
543Please see [this issue](https://github.com/showdownjs/showdown/issues/114) to express interest or comment on this note.
544
545## Credits
546Full credit list at https://github.com/showdownjs/showdown/blob/master/CREDITS.md
547
548Showdown is powered by:<br/>
549[![webstorm](https://www.jetbrains.com/webstorm/documentation/docs/logo_webstorm.png)](https://www.jetbrains.com/webstorm/)
550
551
552
553[sd-logo]: https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png
554[legacy-branch]: https://github.com/showdownjs/showdown/tree/legacy
555[releases]: https://github.com/showdownjs/showdown/releases
556[changelog]: https://github.com/showdownjs/showdown/blob/master/CHANGELOG.md
557[wiki]: https://github.com/showdownjs/showdown/wiki
558[cli-wiki]: https://github.com/showdownjs/showdown/wiki/CLI-tool
559[definitely-typed]: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/showdown
560[xss-wiki]: https://github.com/showdownjs/showdown/wiki/Markdown's-XSS-Vulnerability-(and-how-to-mitigate-it)
561[ext-wiki]: https://github.com/showdownjs/showdown/wiki/extensions
562[coding-rules]: https://github.com/showdownjs/code-style/blob/master/README.md
563[ng-commit-guide]: https://github.com/showdownjs/code-style/blob/master/README.md#commit-message-convention
564[boilerplate-repo]: https://github.com/showdownjs/extension-boilerplate
565
\No newline at end of file