@ -0,0 +1,767 @@ | |||
# [1.9.0](https://github.com/showdownjs/showdown/compare/1.8.7...1.9.0) (2018-11-10) | |||
Version 1.9.0 introduces a new feature, the Markdown to HTML converter. This feature is still experimental and is a partial backport of the new Reverse Converter planned for version 2.0. | |||
### Bug Fixes | |||
* **italicsAndBold:** fix issue with consecutive spans ([#608](https://github.com/showdownjs/showdown/issues/608)) ([5c0d67e](https://github.com/showdownjs/showdown/commit/5c0d67e)), closes [#544](https://github.com/showdownjs/showdown/issues/544) | |||
* **underline:** fix issue with consecutive spans ([81edc70](https://github.com/showdownjs/showdown/commit/81edc70)) | |||
### Features | |||
* **converter.makeMarkdown:** [EXPERIMENTAL] add an HTML to MD converter ([e4b0e69](https://github.com/showdownjs/showdown/commit/e4b0e69)), closes [#388](https://github.com/showdownjs/showdown/issues/388) [#233](https://github.com/showdownjs/showdown/issues/233) | |||
<a name="1.8.7"></a> | |||
# [1.8.7](https://github.com/showdownjs/showdown/compare/1.8.6...1.8.7) (2018-10-16) | |||
### Bug Fixes | |||
* **emojis:** fix emoji excessive size ([4aca41c](https://github.com/showdownjs/showdown/commit/4aca41c)) | |||
* **gfm-codeblocks:** add support for spaces before language declaration ([24bf7b1](https://github.com/showdownjs/showdown/commit/24bf7b1)), closes [#569](https://github.com/showdownjs/showdown/issues/569) | |||
leading space no longer breaks gfm codeblocks ([828c32f](https://github.com/showdownjs/showdown/commit/828c32f)), closes [#523](https://github.com/showdownjs/showdown/issues/523) | |||
* **images:** fix js error when using image references ([980e702](https://github.com/showdownjs/showdown/commit/980e702)), closes [#585](https://github.com/showdownjs/showdown/issues/585) | |||
* **literalMidWordAsterisks:** now parses single characters enclosed by * correctly ([fe70e45](https://github.com/showdownjs/showdown/commit/fe70e45)), closes [#478](https://github.com/showdownjs/showdown/issues/478) | |||
* **mentions:** allow for usernames with dot, underscore and dash ([dfeb1e2](https://github.com/showdownjs/showdown/commit/dfeb1e2)), closes [#574](https://github.com/showdownjs/showdown/issues/574) | |||
* **nbsp:** fix replacing of nbsp with regular spaces ([8bc1f42](https://github.com/showdownjs/showdown/commit/8bc1f42)) | |||
<a name="1.8.6"></a> | |||
# [1.8.6](https://github.com/showdownjs/showdown/compare/1.8.5...1.8.6) (2017-12-22) | |||
### Features | |||
* **splitAdjacentBlockquotes:** add option to split adjacent blockquote blocks ([da328f2](https://github.com/showdownjs/showdown/commit/da328f2)), closes [#477](https://github.com/showdownjs/showdown/issues/477) | |||
<a name="1.8.5"></a> | |||
# [1.8.5](https://github.com/showdownjs/showdown/compare/1.8.4...1.8.5) (2017-12-10) | |||
### Features | |||
* **completeHTMLDocument:** add option to output a complete HTML document ([a8427c9](https://github.com/showdownjs/showdown/commit/a8427c9)) | |||
* **metadata:** add support for embedded metadata ([63d949f](https://github.com/showdownjs/showdown/commit/63d949f)), closes [#260](https://github.com/showdownjs/showdown/issues/260) | |||
<a name="1.8.4"></a> | |||
## [1.8.4](https://github.com/showdownjs/showdown/compare/1.8.3...1.8.4) (2017-12-05) | |||
### Bug Fixes | |||
* **tables:** raw html inside code tags in tables no longer breaks tables ([4ef4c5e](https://github.com/showdownjs/showdown/commit/4ef4c5e)), closes [#471](https://github.com/showdownjs/showdown/issues/471) | |||
<a name="1.8.3"></a> | |||
## [1.8.3](https://github.com/showdownjs/showdown/compare/1.8.2...1.8.3) (2017-11-28) | |||
### Bug Fixes | |||
* **literalMidWordAsterisks:** no longer treats colon as alphanumeric char ([21194c8](https://github.com/showdownjs/showdown/commit/21194c8)), closes [#461](https://github.com/showdownjs/showdown/issues/461) | |||
* **spanGamut:** code spans are hashed after parsing ([f4f63c5](https://github.com/showdownjs/showdown/commit/f4f63c5)), closes [#464](https://github.com/showdownjs/showdown/issues/464) | |||
* **tables:** pipe character in code spans no longer breaks table ([0c933a0](https://github.com/showdownjs/showdown/commit/0c933a0)), closes [#465](https://github.com/showdownjs/showdown/issues/465) | |||
<a name="1.8.2"></a> | |||
## [1.8.2](https://github.com/showdownjs/showdown/compare/1.8.1...1.8.2) (2017-11-11) | |||
### Bug Fixes | |||
* **fenced codeblocks:** add tilde as fenced code block delimiter ([c956ede](https://github.com/showdownjs/showdown/commit/c956ede)), closes [#456](https://github.com/showdownjs/showdown/issues/456) | |||
* **openLinksInNewWindow:** hash links are not affected by the option ([11936ec](https://github.com/showdownjs/showdown/commit/11936ec)), closes [#457](https://github.com/showdownjs/showdown/issues/457) | |||
<a name="1.8.1"></a> | |||
## [1.8.1](https://github.com/showdownjs/showdown/compare/1.8.0...1.8.1) (2017-11-01) | |||
### Dependencies update | |||
* **package:** update yargs to version 10.0.3 ([#447](https://github.com/showdownjs/showdown/issues/447)) ([906b26d](https://github.com/showdownjs/showdown/commit/906b26d)) | |||
### Bug Fixes | |||
* **CDNjs:** bump version to fix version mismatch with CDNjs ([#452](https://github.com/showdownjs/showdown/issues/452)) | |||
<a name="1.8.0"></a> | |||
# [1.8.0](https://github.com/showdownjs/showdown/compare/1.7.6...1.8.0) (2017-10-24) | |||
### NOTICE | |||
Don't use the CDNjs version of this release. See issue [#452](https://github.com/showdownjs/showdown/issues/452) for more details. | |||
### Bug Fixes | |||
* **autolinks:** prevent _ and * to be parsed in links ([61929bb](https://github.com/showdownjs/showdown/commit/61929bb)), closes [#444](https://github.com/showdownjs/showdown/issues/444) | |||
### Features | |||
* **ellipsis:** add auto-ellipsis support ([25f1978](https://github.com/showdownjs/showdown/commit/25f1978)) | |||
- *Example:* | |||
input | |||
```md | |||
this is an ellipsis... | |||
``` | |||
output | |||
```html | |||
<p>this is an ellipsis…</p> | |||
``` | |||
* **emoji:** add emoji support through option `emoji`([5b8f1d3](https://github.com/showdownjs/showdown/commit/5b8f1d3)), closes [#448](https://github.com/showdownjs/showdown/issues/448) | |||
- *Usage:* | |||
```js | |||
var conv = new showdown.Converter({emoji: true}); | |||
``` | |||
- *Example:* | |||
input | |||
```md | |||
this is a smile :smile: emoji | |||
``` | |||
output | |||
```html | |||
<p>this is a smile 😄 emoji</p> | |||
``` | |||
* **start ordered lists at an arbitrary number:** add support for defining the first item number of ordered lists ([9cdc35e](https://github.com/showdownjs/showdown/commit/9cdc35e)), closes [#377](https://github.com/showdownjs/showdown/issues/377) | |||
- *Example:* | |||
input | |||
```md | |||
3. foo | |||
4. bar | |||
5. baz | |||
``` | |||
output | |||
```html | |||
<ol start="3"> | |||
<li>foo</li> | |||
<li>bar</li> | |||
<li>baz</li> | |||
</ol> | |||
``` | |||
* **underline:** add EXPERIMENTAL support for underline ([084b819](https://github.com/showdownjs/showdown/commit/084b819)), closes [#450](https://github.com/showdownjs/showdown/issues/450) | |||
- *Usage:* | |||
```js | |||
var conv = new showdown.Converter({underline: true}); | |||
``` | |||
- *Example:* | |||
input | |||
```md | |||
this is __underlined__ and this is ___also underlined___ | |||
``` | |||
output | |||
```html | |||
<p>this is <u>underlined</u> and this is <u>also underlined</u></p> | |||
``` | |||
- *Note:* With this option enabled, underscore no longer parses as `<em>` or `<strong>` | |||
### BREAKING CHANGES | |||
* start ordered lists at an arbitrary number: Since showdown now supports starting ordered lists at an arbitrary number, | |||
list output may differ. | |||
<a name="1.7.6"></a> | |||
## [1.7.6](https://github.com/showdownjs/showdown/compare/1.7.5...1.7.6) (2017-10-06) | |||
### Bug Fixes | |||
* **tables:** tables are properly rendered when followed by a single linebreak and a list ([d88b095](https://github.com/showdownjs/showdown/commit/d88b095)), closes [#443](https://github.com/showdownjs/showdown/issues/443) | |||
* **tables:** trailing spaces no longer prevent table parsing ([66bdd21](https://github.com/showdownjs/showdown/commit/66bdd21)), closes [#442](https://github.com/showdownjs/showdown/issues/442) | |||
<a name="1.7.5"></a> | |||
## [1.7.5](https://github.com/showdownjs/showdown/compare/1.7.4...1.7.5) (2017-10-02) | |||
### Bug Fixes | |||
* **html-comments:** changed regex to prevent malformed long comment to freeze showdown ([3efcd10](https://github.com/showdownjs/showdown/commit/3efcd10)), closes [#439](https://github.com/showdownjs/showdown/issues/439) | |||
<a name="1.7.4"></a> | |||
## [1.7.4](https://github.com/showdownjs/showdown/compare/1.7.3...1.7.4) (2017-09-08) | |||
### Bug Fixes | |||
* **helper.isArray:** replace a.constructor === Array with Array.isArray ([466a2eb](https://github.com/showdownjs/showdown/commit/466a2eb)), closes [#425](https://github.com/showdownjs/showdown/issues/425) | |||
* **loader:** allow AMD loader to be used within Node env ([ff24bdb](https://github.com/showdownjs/showdown/commit/ff24bdb)) | |||
### Features | |||
* **base64-wrapping:** support for wrapping base64 strings ([8c593a4](https://github.com/showdownjs/showdown/commit/8c593a4)), closes [#429](https://github.com/showdownjs/showdown/issues/429) | |||
<a name="1.7.3"></a> | |||
## [1.7.3](https://github.com/showdownjs/showdown/compare/1.7.2...1.7.3) (2017-08-23) | |||
### Bug Fixes | |||
* **github flavor:** add backslashEscapesHTMLTags to GFM flavor ([5284439](https://github.com/showdownjs/showdown/commit/5284439)) | |||
* **literalMidWordAsterisks:** option no longer treats punctuation as word character ([8f05be7](https://github.com/showdownjs/showdown/commit/8f05be7)), closes [#398](https://github.com/showdownjs/showdown/issues/398) | |||
* **tables:** allow for one column table ([fef110c](https://github.com/showdownjs/showdown/commit/fef110cccb2d02b218183398d9baa0ae256a7283)), closes [#406](https://github.com/showdownjs/showdown/issues/406) | |||
### Features | |||
* **rawHeaderId:** Remove only spaces, ' and " from generated header ids ([1791cf0](https://github.com/showdownjs/showdown/commit/1791cf0)), closes [#409](https://github.com/showdownjs/showdown/issues/409) | |||
* **rawPrefixHeaderId:** add option to prevent showdown from modifying the prefix ([ff26c08](https://github.com/showdownjs/showdown/commit/ff26c08)), closes [#409](https://github.com/showdownjs/showdown/issues/409) | |||
<a name="1.7.2"></a> | |||
## [1.7.2](https://github.com/showdownjs/showdown/compare/1.7.1...1.7.2) (2017-08-05) | |||
### Bug Fixes | |||
* **githubMentions:** githubMentions now works with openLinksInNewWindow options ([1194d88](https://github.com/showdownjs/showdown/commit/1194d88)), closes [#403](https://github.com/showdownjs/showdown/issues/403) | |||
* **lists:** fix multi paragraph lists with sublists ([a2259c0](https://github.com/showdownjs/showdown/commit/a2259c0)), closes [#397](https://github.com/showdownjs/showdown/issues/397) | |||
* **tablesHeaderId:** fix mismatch of option name ([51e4693](https://github.com/showdownjs/showdown/commit/51e4693)), closes [#412](https://github.com/showdownjs/showdown/issues/412) | |||
### Features | |||
* **backslashEscapesHTMLTags:** backslash escapes HTML tags ([5a5aff6](https://github.com/showdownjs/showdown/commit/5a5aff6)), closes [#374](https://github.com/showdownjs/showdown/issues/374) | |||
<a name="1.7.1"></a> | |||
## [1.7.1](https://github.com/showdownjs/showdown/compare/1.7.0...1.7.1) (2017-06-02) | |||
Important HOTFIX | |||
### Bug Fixes | |||
* **HTML Parser:** fix nasty bug where malformed HTML would hang showdown ([6566c72](https://github.com/showdownjs/showdown/commit/6566c72)), closes [#393](https://github.com/showdownjs/showdown/issues/393) | |||
<a name="1.7.0"></a> | |||
## [1.7.0](https://github.com/showdownjs/showdown/compare/1.6.4...1.7.0) (2017-06-01) | |||
(DEPRECATED) | |||
### Bug Fixes | |||
* **anchors:** fix issue with brackets in link URL ([7ba18dd](https://github.com/showdownjs/showdown/commit/7ba18dd)), closes [#390](https://github.com/showdownjs/showdown/issues/390) | |||
* **excludeTrailingPunctuationFromURL:** add comma to punctuation list ([fa35fd5](https://github.com/showdownjs/showdown/commit/fa35fd5)), closes [#354](https://github.com/showdownjs/showdown/issues/354) | |||
* **excludeTrailingPunctuationFromURLs:** fix weird character when this option with simplifiedAutoLinks ([71acff5](https://github.com/showdownjs/showdown/commit/71acff5)), closes [#378](https://github.com/showdownjs/showdown/issues/378) | |||
* **HTML parsing:** fix HTML parsing issues with nested tags ([6fbc072](https://github.com/showdownjs/showdown/commit/6fbc072)), closes [#357](https://github.com/showdownjs/showdown/issues/357) [#387](https://github.com/showdownjs/showdown/issues/387) | |||
* **openLinksInNewWindow:** encode _ to prevent clash with em ([813f832](https://github.com/showdownjs/showdown/commit/813f832)), closes [#379](https://github.com/showdownjs/showdown/issues/379) | |||
* **package:** update yargs to version 7.0.1 ([#349](https://github.com/showdownjs/showdown/issues/349)) ([9308d7b](https://github.com/showdownjs/showdown/commit/9308d7b)) | |||
* **package:** update yargs to version 8.0.1 ([#385](https://github.com/showdownjs/showdown/issues/385)) ([5fd847b](https://github.com/showdownjs/showdown/commit/5fd847b)) | |||
* **simpleAutoLinks:** URLs with emphasis/strikethrough are parsed ([5c50675](https://github.com/showdownjs/showdown/commit/5c50675)), closes [#347](https://github.com/showdownjs/showdown/issues/347) | |||
* **tables:** pipe char can now be escaped ([1ebc195](https://github.com/showdownjs/showdown/commit/1ebc195)), closes [#345](https://github.com/showdownjs/showdown/issues/345) | |||
* **url parsing:** fix url edge case parsing in images and links ([30aa18c](https://github.com/showdownjs/showdown/commit/30aa18c)) | |||
### Features | |||
* **customizeHeaderId:** add option for customizing header ids ([94c570a](https://github.com/showdownjs/showdown/commit/94c570a)), closes [#383](https://github.com/showdownjs/showdown/issues/383) | |||
* **images:** add support for image's implicit reference syntax ([0c6c07b](https://github.com/showdownjs/showdown/commit/0c6c07b)), closes [#366](https://github.com/showdownjs/showdown/issues/366) | |||
* **literalMidWordAsterisks:** add option for mid word asterisks ([5bec8f9](https://github.com/showdownjs/showdown/commit/5bec8f9)) | |||
* **openLinksInNewWindow:** add option to open all links in a new window ([50235d6](https://github.com/showdownjs/showdown/commit/50235d6)), closes [#362](https://github.com/showdownjs/showdown/issues/362) [#337](https://github.com/showdownjs/showdown/issues/337) [#249](https://github.com/showdownjs/showdown/issues/249) [#247](https://github.com/showdownjs/showdown/issues/247) [#222](https://github.com/showdownjs/showdown/issues/222) | |||
<a name="1.6.4"></a> | |||
## [1.6.4](https://github.com/showdownjs/showdown/compare/1.6.3...1.6.4) (2017-02-06) | |||
### Bug Fixes | |||
* **encodeAmpsAndAngles:** fix > and < encoding ([7f43b79](https://github.com/showdownjs/showdown/commit/7f43b79)), closes [#236](https://github.com/showdownjs/showdown/issues/236) | |||
* **encodeEmail:** now produces valid emails ([605d8b7](https://github.com/showdownjs/showdown/commit/605d8b7)), closes [#340](https://github.com/showdownjs/showdown/issues/340) | |||
* **flavor: github:** new version of github does not use prefix 'user-content' in headers ([368f0b6](https://github.com/showdownjs/showdown/commit/368f0b6)) | |||
* **hashCodeTags:** escape code tags ([41cb3f6](https://github.com/showdownjs/showdown/commit/41cb3f6)), closes [#339](https://github.com/showdownjs/showdown/issues/339) | |||
* **italicsAndBold:** fix double emphasis edge case ([1832b7f](https://github.com/showdownjs/showdown/commit/1832b7f)) | |||
* **paragraph:** workaround QML bug ([f7a429e](https://github.com/showdownjs/showdown/commit/f7a429e)), closes [#246](https://github.com/showdownjs/showdown/issues/246) [#338](https://github.com/showdownjs/showdown/issues/338) | |||
* **prefixHeaderId:** make `prefixHeaderId` string be parsed along the generated id ([f641a7d](https://github.com/showdownjs/showdown/commit/f641a7d)) | |||
### Features | |||
* **flavor: ghost:** add Ghost flavor ([6374b5b](https://github.com/showdownjs/showdown/commit/6374b5b)) | |||
* **flavor: original:** add John Gruber's markdown flavor ([6374b5b](https://github.com/showdownjs/showdown/commit/6374b5b)) | |||
<a name="1.6.3"></a> | |||
## [1.6.3](https://github.com/showdownjs/showdown/compare/1.6.2...1.6.3) (2017-01-30) | |||
### Bug Fixes | |||
* **codeSpans:** add - and = to escaped chars inside code spans ([4243a31](https://github.com/showdownjs/showdown/commit/4243a31)) | |||
* **italicsAndBold:** fix inconsistency in italicsAndBold parsing ([a4f05d4](https://github.com/showdownjs/showdown/commit/a4f05d4)), closes [#332](https://github.com/showdownjs/showdown/issues/332) | |||
* **literalMidWordUnderscores:** fix inconsistent behavior of emphasis and strong with literalMidWordUndescores ([0292ae0](https://github.com/showdownjs/showdown/commit/0292ae0)), closes [#333](https://github.com/showdownjs/showdown/issues/333) | |||
* **paragraphs:** fix empty lines generating empty paragraphs ([54bf744](https://github.com/showdownjs/showdown/commit/54bf744)), closes [#334](https://github.com/showdownjs/showdown/issues/334) | |||
* **strikethrough:** fix strikethrough being wrongly parsed inside codeSpans ([169cbe8](https://github.com/showdownjs/showdown/commit/169cbe8)) | |||
### Features | |||
* **events:** add events to all subparsers ([7d63a3e](https://github.com/showdownjs/showdown/commit/7d63a3e)) | |||
<a name="1.6.2"></a> | |||
## [1.6.2](https://github.com/showdownjs/showdown/compare/1.6.1...1.6.2) (2017-01-29) | |||
### Bug Fixes | |||
* **escapeSpecialCharsWithinTagAttributes:** add ~ and = to escaped chars ([bfcc0e4](https://github.com/showdownjs/showdown/commit/bfcc0e4)) | |||
* **strikethrough:** allow escaping tilde char ([24d47d7](https://github.com/showdownjs/showdown/commit/24d47d7)), closes [#331](https://github.com/showdownjs/showdown/issues/331) | |||
### Features | |||
* **ghMentionsLink:** add ability to define the generated url in @mentions ([a4c24c9](https://github.com/showdownjs/showdown/commit/a4c24c9)) | |||
<a name="1.6.1"></a> | |||
## [1.6.1](https://github.com/showdownjs/showdown/compare/1.6.0...1.6.1) (2017-01-28) | |||
### Bug Fixes | |||
* **simplifiedAutoLink:** fix missing spaces before and after email addresses ([5190b6a](https://github.com/showdownjs/showdown/commit/5190b6a)), closes [#330](https://github.com/showdownjs/showdown/issues/330) | |||
### Features | |||
* **encodeEmail:** add option to enable/disable mail obfuscation ([90c52b8](https://github.com/showdownjs/showdown/commit/90c52b8)) | |||
### Notes | |||
This release also improves performance a bit (around 8%) | |||
<a name="1.6.0"></a> | |||
## [1.6.0](https://github.com/showdownjs/showdown/compare/1.5.5...1.6.0) (2017-01-09) | |||
### Bug Fixes | |||
* **ghCompatibleHeaderId:** improve the number of removed chars ([d499feb](https://github.com/showdownjs/showdown/commit/d499feb)) | |||
* **IE8:** fix for IE8 error on using isUndefined function ([561dc5f](https://github.com/showdownjs/showdown/commit/561dc5f)), closes [#280](https://github.com/showdownjs/showdown/issues/280) | |||
* **options:** fix ghCompatibleHeaderId that was set as string instead of boolean ([de7c37e](https://github.com/showdownjs/showdown/commit/de7c37e)) | |||
* **simpleLineBreaks:** fix simpleLineBreaks option not working with non-ASCII chars and markdown delimiters ([b1c458a](https://github.com/showdownjs/showdown/commit/b1c458a)), closes [#318](https://github.com/showdownjs/showdown/issues/318) [#323](https://github.com/showdownjs/showdown/issues/323) | |||
### Features | |||
* **CLI:** add -q (quiet) and -m (mute) mode to CLI ([f3b86f0](https://github.com/showdownjs/showdown/commit/f3b86f0)) | |||
* **CLI:flavor:** add flavor option to CLI ([2d6cd1e](https://github.com/showdownjs/showdown/commit/2d6cd1e)) | |||
* **getFlavor:** add getFlavor method to showdown and Converter ([0eaf105](https://github.com/showdownjs/showdown/commit/0eaf105)) | |||
* **ghMentions:** add support for github's @mentions ([f2671c0](https://github.com/showdownjs/showdown/commit/f2671c0)), closes [#51](https://github.com/showdownjs/showdown/issues/51) | |||
### BREAKING CHANGES: | |||
* CLI tool now uses the same option defaults as showdown main library. This mean | |||
the default flavor is vanilla and ghCodeBlocks options is enabled by default. | |||
To update, add `--ghCodeBlocks="false"` to the command. | |||
<a name="1.5.5"></a> | |||
## [1.5.5](https://github.com/showdownjs/showdown/compare/1.5.4...1.5.5) (2016-12-30) | |||
### Features | |||
* **ghCompatibleHeaderId:** generate header ids compatible with github ([db97a90](https://github.com/showdownjs/showdown/commit/db97a90)), closes [#320](https://github.com/showdownjs/showdown/issues/320) [#321](https://github.com/showdownjs/showdown/issues/321) | |||
<a name="1.5.4"></a> | |||
## [1.5.4](https://github.com/showdownjs/showdown/compare/1.5.3...1.5.4) (2016-12-21) | |||
### Bug Fixes | |||
* **horizontal rule:** revert backwards incompatibility change ([113f5f6](https://github.com/showdownjs/showdown/commit/113f5f6)), closes [#317](https://github.com/showdownjs/showdown/issues/317) | |||
* **simpleLineBreaks:** fix simpleLineBreak option breaking lists html ([ed4c33f](https://github.com/showdownjs/showdown/commit/ed4c33f)), closes [#316](https://github.com/showdownjs/showdown/issues/316) | |||
<a name="1.5.3"></a> | |||
## [1.5.3](https://github.com/showdownjs/showdown/compare/1.5.2...1.5.3) (2016-12-19) | |||
### Bug Fixes | |||
* parser slowness with certain inputs ([da8fb53](https://github.com/showdownjs/showdown/commit/da8fb53)), closes [#315](https://github.com/showdownjs/showdown/issues/315) | |||
### Features | |||
* **requireSpaceBeforeHeadingText:** option to make space between `#` and header text mandatory ([5d19877](https://github.com/showdownjs/showdown/commit/5d19877)), closes [#277](https://github.com/showdownjs/showdown/issues/277) | |||
<a name="1.5.2"></a> | |||
## [1.5.2](https://github.com/showdownjs/showdown/compare/1.5.1...1.5.2) (2016-12-17) | |||
### Bug Fixes | |||
* **listeners:** fix listeners typo ([f0d25b7](https://github.com/showdownjs/showdown/commit/f0d25b7)), closes [#290](https://github.com/showdownjs/showdown/issues/290) | |||
* **lists:** lines with multiple dashes being parsed as multilists ([10b3410](https://github.com/showdownjs/showdown/commit/10b3410)), closes [#312](https://github.com/showdownjs/showdown/issues/312) | |||
* **nbsp:** nbsp are replaced with simple spaces ([6e90f7c](https://github.com/showdownjs/showdown/commit/6e90f7c)) | |||
<a name="1.5.1"></a> | |||
## [1.5.1](https://github.com/showdownjs/showdown/compare/1.5.0...1.5.1) (2016-12-01) | |||
### Features | |||
* **simpleLineBreaks:** option that parses linebreaks as <br />. This option enables linebreaks to always be treated as `<br />` tags | |||
without needing to add spaces in front of the line, the same way GitHub does. ([0942b5e](https://github.com/showdownjs/showdown/commit/0942b5e)), closes [#206](https://github.com/showdownjs/showdown/issues/206) | |||
* **excludeTrailingPunctuationFromURLs:** option that excludes trailing punctuation from auto linked URLs. ([d2fc2a0](https://github.com/showdownjs/showdown/commit/d2fc2a0)), closes [#266](https://github.com/showdownjs/showdown/issues/266) [#308](https://github.com/showdownjs/showdown/issues/308) | |||
<a name="1.5.0"></a> | |||
## [1.5.0](https://github.com/showdownjs/showdown/compare/1.4.4...1.5.0) (2016-11-11) | |||
### Bug Fixes | |||
* **lists:** enforce 4 space indentation in sublists ([d51be6e](https://github.com/showdownjs/showdown/commit/d51be6e)) | |||
* **lists:** fix sublists inconsistent behavior ([9cfe8b1](https://github.com/showdownjs/showdown/commit/9cfe8b1)), closes [#299](https://github.com/showdownjs/showdown/issues/299) | |||
### Features | |||
* **disableForced4SpacesIndentedSublists:** option that disables the requirement of indenting nested sublists by 4 spaces. The option is disabled by default ([0be39bc](https://github.com/showdownjs/showdown/commit/0be39bc)) | |||
### BREAKING CHANGES | |||
* syntax for sublists is now more restrictive. Before, sublists SHOULD be indented by 4 spaces, but indenting at least 2 spaces would work. | |||
Now, sublists MUST be indented 4 spaces or they won't work. | |||
With this input: | |||
```md | |||
* one | |||
* two | |||
* three | |||
``` | |||
Before (output): | |||
```html | |||
<ul> | |||
<li>one | |||
<ul> | |||
<li>two | |||
<ul><li>three</li></ul> | |||
<li> | |||
</ul> | |||
</li> | |||
<ul> | |||
``` | |||
After (output): | |||
```html | |||
<ul> | |||
<li>one</li> | |||
<li>two | |||
<ul><li>three</li></ul> | |||
</li> | |||
</ul> | |||
``` | |||
To migrate either fix source md files or activate the option `disableForced4SpacesIndentedSublists`: | |||
```md | |||
showdown.setOption('disableForced4SpacesIndentedSublists', true); | |||
``` | |||
<a name="1.4.4"></a> | |||
## [1.4.4](https://github.com/showdownjs/showdown/compare/1.4.3...1.4.4) (2016-11-02) | |||
### Bug Fixes | |||
* make some regexes a bit faster and make tab char equivalent to 4 spaces ([b7e7560](https://github.com/showdownjs/showdown/commit/b7e7560)) | |||
* **double linebreaks:** fix double linebreaks in html output ([f97e072](https://github.com/showdownjs/showdown/commit/f97e072)), closes [#291](https://github.com/showdownjs/showdown/issues/291) | |||
* **lists linebreaks:** fix lists linebreaks in html output ([2b813cd](https://github.com/showdownjs/showdown/commit/2b813cd)), closes [#291](https://github.com/showdownjs/showdown/issues/291) | |||
* **parser:** fix issue with comments inside nested code blocks ([799abea](https://github.com/showdownjs/showdown/commit/799abea)), closes [#288](https://github.com/showdownjs/showdown/issues/288) | |||
<a name="1.4.3"></a> | |||
## [1.4.3](https://github.com/showdownjs/showdown/compare/1.4.2...1.4.3) (2016-08-19) | |||
### Bug Fixes | |||
* **bower:** fix sourceMappingURL errors in bower by including source ([9b5a233](https://github.com/showdownjs/showdown/commit/9b5a233)), closes [#200](https://github.com/showdownjs/showdown/issues/200) | |||
* **comments:** Fix html comment parser ([238726c](https://github.com/showdownjs/showdown/commit/238726c)), closes [#276](https://github.com/showdownjs/showdown/issues/276) | |||
* **ie8 compatibility:** Improve ie8 compatibility ([984942e](https://github.com/showdownjs/showdown/commit/984942e)), closes [#275](https://github.com/showdownjs/showdown/issues/275) [#271](https://github.com/showdownjs/showdown/issues/271) | |||
* **simplifiedAutoLink:** fix simplified autolink to match GFM behavior ([0cc55b0](https://github.com/showdownjs/showdown/commit/0cc55b0)), closes [#284](https://github.com/showdownjs/showdown/issues/284) [#285](https://github.com/showdownjs/showdown/issues/285) | |||
<a name="1.4.2"></a> | |||
## [1.4.2](https://github.com/showdownjs/showdown/compare/1.4.1...1.4.2) (2016-06-21) | |||
### Bug Fixes | |||
* **image-parser:** fix ref style imgs after inline style imgs not parsing correctly ([73206b0](https://github.com/showdownjs/showdown/commit/73206b0)), closes [#261](https://github.com/showdownjs/showdown/issues/261) | |||
* **tables:** add check for undefined on text due to failing to parse tables ([6e30a48](https://github.com/showdownjs/showdown/commit/6e30a48)), author [stewartmckee](https://github.com/stewartmckee), closes [#257](https://github.com/showdownjs/showdown/pull/247) | |||
### Features | |||
* **smart-indent-fix:** fix for es6 indentation problems ([261f127](https://github.com/showdownjs/showdown/commit/261f127)), closes [#259](https://github.com/showdownjs/showdown/issues/259) | |||
<a name="1.4.1"></a> | |||
## [1.4.1](https://github.com/showdownjs/showdown/compare/1.4.0...1.4.1) (2016-05-17) | |||
### Bug Fixes | |||
* **tables:** fix table heading separators requiring 3 dashes instead of 2 ([ddaacfc](https://github.com/showdownjs/showdown/commit/ddaacfc)), closes [#256](https://github.com/showdownjs/showdown/issues/256) | |||
<a name="1.4.0"></a> | |||
## [1.4.0](https://github.com/showdownjs/showdown/compare/1.3.0...1.4.0) (2016-05-13) | |||
### Bug Fixes | |||
* **hashHTMLBlock:** fix issue with html breaking markdown parsing ([2746949](https://github.com/showdownjs/showdown/commit/2746949)), closes [#220](https://github.com/showdownjs/showdown/issues/220) | |||
* **HTMLParser:** fix code tags parsing ([71a5873](https://github.com/showdownjs/showdown/commit/71a5873)), closes [#231](https://github.com/showdownjs/showdown/issues/231) | |||
* **HTMLParser:** fix ghCodeBlocks being parsed inside code tags ([7d0436d](https://github.com/showdownjs/showdown/commit/7d0436d)), closes [#229](https://github.com/showdownjs/showdown/issues/229) | |||
* **strikethrough:** Fix strikethrough issue with escaped chars ([5669317](https://github.com/showdownjs/showdown/commit/5669317)), closes [#214](https://github.com/showdownjs/showdown/issues/214) | |||
* **tables:** fix tables to match github's md spec ([f58f014](https://github.com/showdownjs/showdown/commit/f58f014)), closes [#230](https://github.com/showdownjs/showdown/issues/230) | |||
### Features | |||
* **markdown="1":** enable parsing markdown inside HTML blocks ([c97f1dc](https://github.com/showdownjs/showdown/commit/c97f1dc)), closes [#178](https://github.com/showdownjs/showdown/issues/178) | |||
<a name="1.3.0"></a> | |||
## [1.3.0](https://github.com/showdownjs/showdown/compare/1.2.3...1.3.0) (2015-10-19) | |||
### Bug Fixes | |||
* **literalMidWordUnderscores:** fix different behavior with asterisks ([e86aea8](https://github.com/showdownjs/showdown/commit/e86aea8)), closes [#198](https://github.com/showdownjs/showdown/issues/198) | |||
* **simpleautolink:** fix mail simpleAutoLink to ignore urls with @ symbol ([8ebb25e](https://github.com/showdownjs/showdown/commit/8ebb25e)), closes [#204](https://github.com/showdownjs/showdown/issues/204) | |||
### Features | |||
* **eventDispatcher:** add an event dispatcher to converter ([2734326](https://github.com/showdownjs/showdown/commit/2734326)) | |||
* **hashHTMLSpans:** add support for hashing span elements ([3097bd4](https://github.com/showdownjs/showdown/commit/3097bd4)), closes [#196](https://github.com/showdownjs/showdown/issues/196) [#175](https://github.com/showdownjs/showdown/issues/175) | |||
<a name"1.2.3"></a> | |||
## [1.2.3](https://github.com/showdownjs/showdown/compare/1.2.2...1.2.3) (2015-08-27) | |||
### Bug Fixes | |||
* **blockGamut:** fix for headings inside blockquotes ([3df70624](http://github.com/showdownjs/showdown/commit/3df70624), closes [#191](http://github.com/showdownjs/showdown/issues/191)) | |||
* **blockQuote:** fix 'github style codeblocks' not being parsed inside 'blockquote' ([ed2cf595](http://github.com/showdownjs/showdown/commit/ed2cf595), closes [#192](http://github.com/showdownjs/showdown/issues/192)) | |||
* **simpleAutoLinks:** fix emails being treated as simple urls ([7dc3fb1d](http://github.com/showdownjs/showdown/commit/7dc3fb1d), closes [#187](http://github.com/showdownjs/showdown/issues/187)) | |||
* **tables:** fix md tables being parsed inside indented code blocks. ([50256233](http://github.com/showdownjs/showdown/commit/50256233), closes [#193](http://github.com/showdownjs/showdown/issues/193)) | |||
<a name"1.2.2"></a> | |||
## [1.2.2](https://github.com/showdownjs/showdown/compare/1.2.1...1.2.2) (2015-08-02) | |||
### Bug Fixes | |||
* **lists:** fix github code blocks not being parsed inside lists ([7720c88b](http://github.com/showdownjs/showdown/commit/7720c88b), closes [#142](http://github.com/showdownjs/showdown/issues/142), [#183](http://github.com/showdownjs/showdown/issues/183), [#184](http://github.com/showdownjs/showdown/issues/184)) | |||
<a name"1.2.1"></a> | |||
## [1.2.1](https://github.com/showdownjs/showdown/compare/1.2.0...1.2.1) (2015-07-22) | |||
### Features | |||
* **smoothLivePreview:** fix weird effects due to parsing incomplete input ([62ba3733](http://github.com/showdownjs/showdown/commit/62ba3733)) | |||
* **subParsers/githubCodeBlock:** add extra language class to conform to html5 spec ([b7f5e32](http://github.com/showdownjs/showdown/commit/b7f5e32)) | |||
### Bug Fixes | |||
* **tables:** | |||
* fix undefined error in malformed tables ([6176977](http://github.com/showdownjs/showdown/commit/6176977)) | |||
* add support for md span elements in table headers ([789dc18](http://github.com/showdownjs/showdown/commit/789dc18)), closes [#179](http://github.com/showdownjs/showdown/issues/179) | |||
* **italicsAndBold:** | |||
* fix broken em/strong tags when used with literalMidWordUnderscores ([7ee2017](http://github.com/showdownjs/showdown/commit/7ee2017)), closes [#179](http://github.com/showdownjs/showdown/issues/179) | |||
* fix underscores not being correctly parsed when used in conjunction with literalMidWordsUnderscores option ([c9e85f1](http://github.com/showdownjs/showdown/commit/c9e85f1)) | |||
* **codeSpans:** Fix issue with code html tags not being correctly escaped ([5f043ca](http://github.com/showdownjs/showdown/commit/5f043ca)) | |||
* **images:** fix alt attribute not being escaped correctly ([542194e](http://github.com/showdownjs/showdown/commit/542194e)) | |||
<a name"1.2.0"></a> | |||
## [1.2.0](https://github.com/showdownjs/showdown/compare/1.1.0...1.2.0) (2015-07-13) | |||
This release moves some of the most popular extensions (such as table-extension and github-extension) to core. | |||
Also introduces a simple cli tool that you can use to quickly convert markdown files into html. | |||
### Bug Fixes | |||
* **headerLevelStart:** fix for NaN error when specifying a non number as headerLevelStart param ([be72b487](http://github.com/showdownjs/showdown/commit/be72b487)) | |||
### Features | |||
* **CLI:** simple cli tool (ALPHA) ([f6a33e40](http://github.com/showdownjs/showdown/commit/f6a33e40)) | |||
* **flavours:** add markdown presets/flavors ([7e55bceb](http://github.com/showdownjs/showdown/commit/7e55bceb), closes [#164](http://github.com/showdownjs/showdown/issues/164)) | |||
* **ghCodeBlocks:** add option to disable GH codeblocks ([c33f9888](http://github.com/showdownjs/showdown/commit/c33f9888)) | |||
* **literalMidWordUnderscores:** add support for GFM literal midword underscores ([0c0cd7db](http://github.com/showdownjs/showdown/commit/0c0cd7db)) | |||
* **simplifiedAutoLink:** add support for GFM autolinks ([cff02372](http://github.com/showdownjs/showdown/commit/cff02372)) | |||
* **strikethrough:** add support for GFM strikethrough ([43e9448d](http://github.com/showdownjs/showdown/commit/43e9448d)) | |||
* **tables:** add support for GFM tables ([3a924e3c](http://github.com/showdownjs/showdown/commit/3a924e3c)) | |||
* **tasklists:** add support for GFM tasklists ([dc72403a](http://github.com/showdownjs/showdown/commit/dc72403a)) | |||
<a name"1.1.0"></a> | |||
## [1.1.0](https://github.com/showdownjs/showdown/compare/1.0.2...1.1.0) (2015-06-18) | |||
### Bug Fixes | |||
* **converter.js:** add error if the passed constructor argument is not an object ([d86ed450](http://github.com/showdownjs/showdown/commit/d86ed450)) | |||
* **output modifiers:** fix for output modifiers running twice ([dcbdc61e](http://github.com/showdownjs/showdown/commit/dcbdc61e)) | |||
### Features | |||
* **headerLevelStart:** add support for setting the header starting level ([b84ac67d](http://github.com/showdownjs/showdown/commit/b84ac67d), closes [#69](http://github.com/showdownjs/showdown/issues/69)) | |||
* **image dimensions:** add support for setting image dimensions within markdown syntax ([af82c2b6](http://github.com/showdownjs/showdown/commit/af82c2b6), closes [#143](http://github.com/showdownjs/showdown/issues/143)) | |||
* **noHeaderId:** add option to suppress automatic generation of ids in headers ([7ac893e9](http://github.com/showdownjs/showdown/commit/7ac893e9)) | |||
* **showdown.getDefaultOptions:** add method to retrieve default global options keypairs ([2de53a7d](http://github.com/showdownjs/showdown/commit/2de53a7d)) | |||
### Breaking Changes | |||
* Deprecates `showdown.extensions` property. To migrate, extensions should use the new method `showdown.extension(<ext name>, <extension>)` to register. | |||
For more information on the new extension loading mechanism, please check the wiki pages. | |||
([4ebd0caa](http://github.com/showdownjs/showdown/commit/4ebd0caa)) | |||
<a name"1.0.2"></a> | |||
## [1.0.2](https://github.com/showdownjs/showdown/compare/1.0.1...1.0.2) (2015-05-28) | |||
### Bug Fixes | |||
* **Gruntfile.js** add missing comma in footer. This bug prevented concatenating other js scripts and libraries | |||
with showdown([5315508](http://github.com/showdownjs/showdown/commit/5315508). Credits to Alexandre Courtiol. | |||
<a name"1.0.1"></a> | |||
## [1.0.1](https://github.com/showdownjs/showdown/compare/1.0.0...1.0.1) (2015-05-27) | |||
### Bug Fixes | |||
* **bower.json:** update bower.json main attribute to point to dist directory ([bc3a092f](http://github.com/showdownjs/showdown/commit/bc3a092f)) | |||
<a name"1.0.0"></a> | |||
## [1.0.0](https://github.com/showdownjs/showdown/compare/0.3.4...1.0.0) (2015-05-27) | |||
### Release Information | |||
This is a major code refactor with some big changes such as: | |||
- showdown.js file was split in several files, called sub-parsers. This should improve code maintainability. | |||
- angular integration was removed from core and move to its own repository, similar to what was done with extensions | |||
- A new extension registering system is on the "cooks" that should reduce errors when using extensions. The old mechanism | |||
is kept so old extensions should be compatible. | |||
### Bug Fixes | |||
* **extensions:** support for old extension loading mechanism ([95ed7c68](http://github.com/showdownjs/showdown/commit/95ed7c68)) | |||
* **helpers:** fix wrong function call 'escapeCharacters' due to old strayed code ([18ba4e75](http://github.com/showdownjs/showdown/commit/18ba4e75)) | |||
* **showdown.js:** | |||
- fix showdown extension loader ([a38c76d2](http://github.com/showdownjs/showdown/commit/a38c76d2)), | |||
closes [#50](http://github.com/showdownjs/showdown/issues/50),[#56](http://github.com/showdownjs/showdown/issues/56), | |||
[#104](http://github.com/showdownjs/showdown/issues/104), [#108](http://github.com/showdownjs/showdown/issues/108), | |||
[#109](http://github.com/showdownjs/showdown/issues/109), [#111](http://github.com/showdownjs/showdown/issues/111), | |||
[#118](http://github.com/showdownjs/showdown/issues/118), [#122](http://github.com/showdownjs/showdown/issues/122) | |||
- add unique id prefix and suffix to headers ([c367a4b9](http://github.com/showdownjs/showdown/commit/c367a4b9), closes [#81](http://github.com/showdownjs/showdown/issues/81), [#82](http://github.com/showdownjs/showdown/issues/82)) | |||
* **options.omitExtraWLInCodeBlocks:** fix for options.omitExtraWLInCodeBlocks only applying in gitHub flavoured code b ([e6f40e19](http://github.com/showdownjs/showdown/commit/e6f40e19)) | |||
* **showdown:** fix for options merging into globalOptions ([ddd6011d](http://github.com/showdownjs/showdown/commit/ddd6011d), closes [#153](http://github.com/showdownjs/showdown/issues/153)) | |||
### Features | |||
* **registerExtension():** new extension loading mechanism. Now extensions can be registered using this function. | |||
The system, however, is not final and will probably be changed until the final version([0fd10cb] (http://github.com/showdownjs/showdown/commit/0fd10cb)) | |||
* **allowBlockIndents:** indented inline block elements can now be parsed as markdown ([f6326b84](http://github.com/showdownjs/showdown/commit/f6326b84)) | |||
* **omitExtraWLInCodeBlocks:** add option to omit extra newline at the end of codeblocks ([141e3f5](http://github.com/showdownjs/showdown/commit/141e3f5)) | |||
* **prefixHeaderId:** add options to prefix header ids to prevent id clash ([141e3f5](http://github.com/showdownjs/showdown/commit/141e3f5)) | |||
* **Converter.options:** add getOption(), setOption() and getOptions() to Converter object ([db6f79b0](http://github.com/showdownjs/showdown/commit/db6f79b0)) | |||
### Breaking Changes | |||
* **NAMESPACE:** showdown's namespace changed. | |||
To migrate your code you should update all references to `Showdown` with `showdown`. | |||
* **Converter:** converter reference changed from `converter` to `Converter`. | |||
To migrate you should update all references to `Showdown.converter` with `showdown.Converter` | |||
* **angular:** angular integration was removed from core and now lives in it's own [repository](http://github.com/showdownjs/angular/). | |||
If you're using angular integration, you should install ng-showdown. Ex: `bower install ng-showdown` | |||
* **extensions:** showdown extensions were removed from core package and now live in their own repository. See the [project's github page](https://github.com/showdownjs) for available extensions |
@ -0,0 +1,74 @@ | |||
Contributing | |||
============ | |||
If you wish to contribute please read the following quick guide. | |||
# Issues (bug reporting) | |||
Generally, bug reports should be in the following format: | |||
1. Description (Brief description of the problem) | |||
2. Input (input that is causing problems) | |||
3. Expected Output (Output that is expected) | |||
4. Actual Output (Actual showdown output) | |||
ex: | |||
**Description:** | |||
Double asterisks do not parse as bold | |||
**Input:** | |||
hello **world**! | |||
**Expected output:** | |||
<p>hello <b>world</b>! | |||
**Actual Output:** | |||
<p>hello **world**!</p> | |||
# 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: | |||
- Search GitHub for an open or closed Pull Request that relates to your submission. You don't want to duplicate effort. | |||
- When issuing PRs that change code, make your changes in a new git branch based on develop: | |||
```bash | |||
git checkout -b my-fix-branch develop | |||
``` | |||
- Run the full test suite before submitting and make sure all tests pass (obviously =P). | |||
- Try to follow our [**coding style rules**](https://github.com/showdownjs/code-style/blob/master/README.md). | |||
Breaking them prevents the PR to pass the tests. | |||
- Refrain from fixing multiple issues in the same pull request. It's preferable to open multiple small PRs instead of one | |||
hard to review big one. Also, don't reuse old forks (or PRs) to fix new issues. | |||
- If the PR introduces a new feature or fixes an issue, please add the appropriate test case. | |||
- We use commit notes to generate the changelog. It's extremely helpful if your commit messages adhere to the | |||
[**AngularJS Git Commit Guidelines**](https://github.com/showdownjs/code-style/blob/master/README.md#commit-message-convention). | |||
- If we suggest changes then: | |||
- Make the required updates. | |||
- Re-run the Angular test suite to ensure tests are still passing. | |||
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request): | |||
```bash | |||
git rebase develop -i | |||
git push origin my-fix-branch -f | |||
``` | |||
- After your pull request is merged, you can safely delete your branch. | |||
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](https://github.com/showdownjs/showdown/issues/114) to express interest or comment on this note. |
@ -0,0 +1,52 @@ | |||
Credits | |||
======= | |||
- Showdown v2 | |||
* [Estevão Santos](https://github.com/tivie) | |||
- Showdown v1 | |||
* [Estevão Santos](https://github.com/tivie) | |||
* [Pascal Deschênes](https://github.com/pdeschen) | |||
- Showdown v0 | |||
* [Corey Innis](http://github.com/coreyti):<br/> | |||
Original GitHub project maintainer | |||
* [Remy Sharp](https://github.com/remy/):<br/> | |||
CommonJS-compatibility and more | |||
* [Konstantin Käfer](https://github.com/kkaefer/):<br/> | |||
CommonJS packaging | |||
* [Roger Braun](https://github.com/rogerbraun):<br/> | |||
Github-style code blocks | |||
* [Dominic Tarr](https://github.com/dominictarr):<br/> | |||
Documentation | |||
* [Cat Chen](https://github.com/CatChen):<br/> | |||
Export fix | |||
* [Titus Stone](https://github.com/tstone):<br/> | |||
Mocha tests, extension mechanism, and bug fixes | |||
* [Rob Sutherland](https://github.com/roberocity):<br/> | |||
The idea that lead to extensions | |||
* [Pavel Lang](https://github.com/langpavel):<br/> | |||
Code cleanup | |||
* [Ben Combee](https://github.com/unwiredben):<br/> | |||
Regex optimization | |||
* [Adam Backstrom](https://github.com/abackstrom):<br/> | |||
WebKit bugfix | |||
* [Pascal Deschênes](https://github.com/pdeschen):<br/> | |||
Grunt support, extension fixes + additions, packaging improvements, documentation | |||
* [Estevão Santos](https://github.com/tivie)<br/> | |||
Bug fixing and late maintainer | |||
* [Hannah Wolfe](https://github.com/ErisDS)<br/> | |||
Bug fixes | |||
* [Alexandre Courtiol](https://github.com/acourtiol)<br/> | |||
Bug fixes and build optimization | |||
* [Karthik Balakrishnan](https://github.com/torcellite)<br/> | |||
Support for table alignment | |||
* [rheber](https://github.com/rheber)<br/> | |||
Cli | |||
- Original Project | |||
* [John Gruber](http://daringfireball.net/projects/markdown/)<br/> | |||
Author of Markdown | |||
* [John Fraser](http://attacklab.net/)<br/> | |||
Author of Showdown |
@ -0,0 +1,57 @@ | |||
We would like to thank everyone that contributed to this library. If you find our library useful and wish to donate as well, you can do so [through patreon](https://www.patreon.com/showdownjs) or directly [through paypal](https://www.paypal.me/tiviesantos)!! Your contribution will be greatly appreciated. | |||
# Sponsors | |||
## Platinum Supporters | |||
## Gold Supporters | |||
## Silver Supporters | |||
# Patron Supporters | |||
## Awesome Supporter | |||
## Cool Supporter | |||
## Supporter | |||
- Ricardo Jordão | |||
- Tiago Silva | |||
--- | |||
# One Time Donors | |||
- [**Learn on demand Systems**](http://www.learnondemandsystems.com/) (1000$) | |||
- **Nothing AG** (25€) | |||
> Thank you for developing Showdown :) | |||
- **Sam Huffman** (15$) | |||
> Thanks for the great work on showdown.js! I've been looking for a good solution to serve wiki-like text to a browser and render as | |||
HTML but nearly gave up after mixed success with wikitext. Your library gets me very close to where I want to be. | |||
- **Maya Lekova** (10$) | |||
> Great work with the showdown library! I just used it and it worked exactly the way I expected | |||
(given a complex inline HTML inside the Markdown, which renders fine with other viewers). | |||
The other libraries I've tried (markdown-it and marked) produced a lot of bogus output. Y | |||
our library saved me at least half a day, thanks! Good luck :) | |||
- **Lin Wang** (10$) | |||
- **Walter Schnell** (10$) | |||
- **ivanhjc** (5$) | |||
- **Asbjørn Ulsberg** (5$) | |||
> Thanks for the ShowdownJS support! | |||
- **Juan Marcelo Russo** (1$) |
@ -0,0 +1,21 @@ | |||
MIT License | |||
Copyright (c) 2018 ShowdownJS | |||
Permission is hereby granted, free of charge, to any person obtaining a copy | |||
of this software and associated documentation files (the "Software"), to deal | |||
in the Software without restriction, including without limitation the rights | |||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |||
copies of the Software, and to permit persons to whom the Software is | |||
furnished to do so, subject to the following conditions: | |||
The above copyright notice and this permission notice shall be included in all | |||
copies or substantial portions of the Software. | |||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
SOFTWARE. |
@ -0,0 +1,526 @@ | |||
![Showdown][sd-logo] | |||
[](https://travis-ci.org/showdownjs/showdown) | |||
[](https://ci.appveyor.com/project/tivie/showdown/branch/master) | |||
[](http://badge.fury.io/js/showdown) | |||
[](http://badge.fury.io/bo/showdown) | |||
[](https://gitter.im/showdownjs/showdown?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | |||
[](https://greenkeeper.io/) | |||
[](https://www.paypal.me/tiviesantos) | |||
------ | |||
Showdown is a Javascript Markdown to HTML converter, based on the original works by John Gruber. | |||
Showdown can be used client side (in the browser) or server side (with NodeJs). | |||
## Live DEMO | |||
Check a live Demo here http://demo.showdownjs.com/ | |||
## [](https://www.patreon.com/bePatron?u=11141581) | |||
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 [patreon](https://www.patreon.com/showdownjs) or directly through [paypal](https://www.paypal.me/tiviesantos)!! Your contribution will be greatly appreciated and help me continue to develop this awesome library. | |||
## License | |||
ShowdownJS v 2.0 is release under the MIT version. | |||
Previous versions are release under BSD. | |||
## Who uses Showdown (or a fork) | |||
- [GoogleCloudPlatform](https://github.com/GoogleCloudPlatform) | |||
- [Meteor](https://www.meteor.com/) | |||
- [Stackexchange](http://stackexchange.com/) - forked as [PageDown](https://code.google.com/p/pagedown/) | |||
- [docular](https://github.com/Vertafore/docular) | |||
- [md-page](https://github.com/oscarmorrison/md-page) | |||
- [QCObjects](https://qcobjects.dev) | |||
- [and some others...](https://www.npmjs.com/browse/depended/showdown) | |||
## Installation | |||
### Download tarball | |||
You can download the latest release tarball directly from [releases][releases] | |||
### Bower | |||
bower install showdown | |||
### npm (server-side) | |||
npm install showdown | |||
### NuGet package | |||
PM> Install-Package showdownjs | |||
The NuGet Packages can be [found here](https://www.nuget.org/packages/showdownjs/). | |||
### CDN | |||
You can also use one of several CDNs available: | |||
* jsDelivr | |||
https://cdn.jsdelivr.net/npm/showdown@<version tag>/dist/showdown.min.js | |||
* cdnjs | |||
https://cdnjs.cloudflare.com/ajax/libs/showdown/<version tag>/showdown.min.js | |||
* unpkg | |||
https://unpkg.com/showdown/dist/showdown.min.js | |||
*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: | |||
* Firefox 1.5 and 2.0 | |||
* Chrome 12.0 | |||
* Internet Explorer 6 and 7 | |||
* Safari 2.0.4 | |||
* Opera 8.54 and 9.10 | |||
* Netscape 8.1.2 | |||
* Konqueror 3.5.4 | |||
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 has been tested with node 0.8 and 0.10. However, it should work with previous versions, such as node 0.6. | |||
## Legacy version | |||
If you're looking for showdown v<1.0.0, you can find it in the [**legacy branch**][legacy-branch]. | |||
## Changelog | |||
You can check the full [changelog][changelog] | |||
## Extended documentation | |||
Check our [wiki pages][wiki] for examples and a more in-depth documentation. | |||
## Quick Example | |||
### Node | |||
```js | |||
var showdown = require('showdown'), | |||
converter = new showdown.Converter(), | |||
text = '# hello, markdown!', | |||
html = converter.makeHtml(text); | |||
``` | |||
### Browser | |||
```js | |||
var converter = new showdown.Converter(), | |||
text = '# hello, markdown!', | |||
html = converter.makeHtml(text); | |||
``` | |||
### Output | |||
Both examples should output... | |||
```html | |||
<h1 id="hellomarkdown">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 | |||
```js | |||
showdown.setOption('optionKey', 'value'); | |||
``` | |||
#### Locally | |||
Setting a "local" option only affects the specified Converter object. | |||
Local options can be set: | |||
* **through the constructor** | |||
```js | |||
var converter = new showdown.Converter({optionKey: 'value'}); | |||
``` | |||
* **through the setOption() method** | |||
```js | |||
var converter = new showdown.Converter(); | |||
converter.setOption('optionKey', 'value'); | |||
``` | |||
### Getting an option | |||
Showdown provides 2 methods (both local and global) to retrieve previous set options. | |||
#### getOption() | |||
```js | |||
// Global | |||
var myOption = showdown.getOption('optionKey'); | |||
//Local | |||
var myOption = converter.getOption('optionKey'); | |||
``` | |||
#### getOptions() | |||
```js | |||
// Global | |||
var showdownGlobalOptions = showdown.getOptions(); | |||
//Local | |||
var thisConverterSpecificOptions = converter.getOptions(); | |||
``` | |||
### Retrieve the default options | |||
You can get showdown's default options with: | |||
```js | |||
var defaultOptions = showdown.getDefaultOptions(); | |||
``` | |||
### Valid Options | |||
* **omitExtraWLInCodeBlocks**: (boolean) [default false] Omit the trailing newline in a code block. Ex: | |||
This: | |||
```html | |||
<code><pre>var foo = 'bar'; | |||
</pre></code> | |||
``` | |||
Becomes this: | |||
```html | |||
<code><pre>var foo = 'bar';</pre></code> | |||
``` | |||
* **noHeaderId**: (boolean) [default false] Disable the automatic generation of header ids. | |||
Setting to true overrides **prefixHeaderId** | |||
* **customizedHeaderId**: (boolean) [default false] Use text in curly braces as header id. **(since v1.7.0)** | |||
Example: | |||
``` | |||
## Sample header {real-id} will use real-id as id | |||
``` | |||
* **ghCompatibleHeaderId**: (boolean) [default false] Generate header ids compatible with github style | |||
(spaces are replaced with dashes and a bunch of non alphanumeric chars are removed) **(since v1.5.5)** | |||
* **prefixHeaderId**: (string/boolean) [default false] Add a prefix to the generated header ids. | |||
Passing a string will prefix that string to the header id. Setting to `true` will add a generic 'section' prefix. | |||
* **rawPrefixHeaderId**: (boolean) [default false] Setting this option to true will prevent showdown from modifying the prefix. | |||
This might result in malformed IDs (if, for instance, the " char is used in the prefix). | |||
Has no effect if prefixHeaderId is set to false. **(since v 1.7.3)** | |||
* **rawHeaderId**: (boolean) [default false] Remove only spaces, ' and " from generated header ids (including prefixes), | |||
replacing them with dashes (-). WARNING: This might result in malformed ids **(since v1.7.3)** | |||
* **headerLevelStart**: (integer) [default 1] Set the header starting level. For instance, setting this to 3 means that | |||
```md | |||
# foo | |||
``` | |||
will be parsed as | |||
```html | |||
<h3>foo</h3> | |||
``` | |||
* **parseImgDimensions**: (boolean) [default false] Enable support for setting image dimensions from within markdown syntax. | |||
Examples: | |||
``` | |||
 simple, assumes units are in px | |||
 sets the height to "auto" | |||
 Image with width of 80% and height of 5em | |||
``` | |||
* **simplifiedAutoLink**: (boolean) [default false] Turning this option on will enable automatic linking to urls. | |||
This means that: | |||
```md | |||
some text www.google.com | |||
``` | |||
will be parsed as | |||
```html | |||
<p>some text <a href="www.google.com">www.google.com</a> | |||
``` | |||
* ~~**excludeTrailingPunctuationFromURLs**: (boolean) [default false] This option excludes trailing punctuation from autolinking urls. | |||
Punctuation excluded: `. ! ? ( )`. Only applies if **simplifiedAutoLink** option is set to `true`.~~ | |||
* **literalMidWordUnderscores**: (boolean) [default false] Turning this on will stop showdown from interpreting | |||
underscores in the middle of words as `<em>` and `<strong>` and instead treat them as literal underscores. | |||
Example: | |||
```md | |||
some text with__underscores__in middle | |||
``` | |||
will be parsed as | |||
```html | |||
<p>some text with__underscores__in middle</p> | |||
``` | |||
* ~~**literalMidWordAsterisks**: (boolean) [default false] Turning this on will stop showdown from interpreting asterisks | |||
in the middle of words as `<em>` and `<strong>` and instead treat them as literal asterisks.~~ | |||
* **strikethrough**: (boolean) [default false] Enable support for strikethrough syntax. | |||
`~~strikethrough~~` as `<del>strikethrough</del>` | |||
* **tables**: (boolean) [default false] Enable support for tables syntax. Example: | |||
```md | |||
| h1 | h2 | h3 | | |||
|:------|:-------:|--------:| | |||
| 100 | [a][1] | ![b][2] | | |||
| *foo* | **bar** | ~~baz~~ | | |||
``` | |||
See the wiki for more info | |||
* **tablesHeaderId**: (boolean) [default false] If enabled adds an id property to table headers tags. | |||
* **ghCodeBlocks**: (boolean) [default true] Enable support for GFM code block style. | |||
* **tasklists**: (boolean) [default false] Enable support for GFM tasklists. Example: | |||
```md | |||
- [x] This task is done | |||
- [ ] This is still pending | |||
``` | |||
* **smoothLivePreview**: (boolean) [default false] Prevents weird effects in live previews due to incomplete input | |||
* **smartIndentationFix**: (boolean) [default false] Tries to smartly fix indentation problems related to es6 template | |||
strings in the midst of indented code. | |||
* **disableForced4SpacesIndentedSublists**: (boolean) [default false] Disables the requirement of indenting sublists | |||
by 4 spaces for them to be nested, effectively reverting to the old behavior where 2 or 3 spaces were enough. | |||
**(since v1.5.0)** | |||
* **simpleLineBreaks**: (boolean) [default false] Parses line breaks as `<br>`, without | |||
needing 2 spaces at the end of the line **(since v1.5.1)** | |||
```md | |||
a line | |||
wrapped in two | |||
``` | |||
turns into: | |||
```html | |||
<p>a line<br> | |||
wrapped in two</p> | |||
``` | |||
* **requireSpaceBeforeHeadingText**: (boolean) [default false] Makes adding a space between `#` and the header text mandatory **(since v1.5.3)** | |||
* **ghMentions**: (boolean) [default false] Enables github @mentions, which link to the username mentioned **(since v1.6.0)** | |||
* **ghMentionsLink**: (string) [default `https://github.com/{u}`] Changes the link generated by @mentions. | |||
Showdown will replace `{u}` with the username. Only applies if ghMentions option is enabled. | |||
Example: `@tivie` with ghMentionsOption set to `//mysite.com/{u}/profile` will result in `<a href="//mysite.com/tivie/profile">@tivie</a>` | |||
* **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) | |||
NOTE: Prior to version 1.6.1, emails would always be obfuscated through dec and hex encoding. | |||
* **openLinksInNewWindow**: (boolean) [default false] Open all links in new windows | |||
(by adding the attribute `target="_blank"` to `<a>` tags) **(since v1.7.0)** | |||
* **backslashEscapesHTMLTags**: (boolean) [default false] Support for HTML Tag escaping. ex: `\<div>foo\</div>` **(since v1.7.2)** | |||
* **emoji**: (boolean) [default false] Enable emoji support. Ex: `this is a :smile: emoji` | |||
For more info on available emojis, see https://github.com/showdownjs/showdown/wiki/Emojis **(since v.1.8.0)** | |||
* **underline**: (boolean) [default false] ***EXPERIMENTAL FEATURE*** Enable support for underline. | |||
Syntax is **double** or **triple** **underscores** ex: `__underlined word__`. With this option enabled, underscores are no longer parses into `<em>` and `<strong>`. | |||
* **completeHTMLDocument**: (boolean) [default false] Outputs a complete html document, | |||
including `<html>`, `<head>` and `<body>` tags' instead of an HTML fragment. (since v.1.8.5) | |||
* **metadata**: (boolean) [default false] Enable support for document metadata (defined at the top of the document | |||
between `«««` and `»»»` or between `---` and `---`). (since v.1.8.5) | |||
```js | |||
var conv = new showdown.Converter({metadata: true}); | |||
var html = conv.makeHtml(someMd); | |||
var metadata = conv.getMetadata(); // returns an object with the document metadata | |||
``` | |||
* **splitAdjacentBlockquotes**: (boolean) [default false] Split adjacent blockquote blocks.(since v.1.8.6) | |||
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool. | |||
## 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: | |||
* original - original markdown flavor as in [John Gruber's spec](https://daringfireball.net/projects/markdown/) | |||
* vanilla - showdown base flavor (as from v1.3.1) | |||
* github - GFM (GitHub Flavored Markdown) | |||
### Global | |||
```javascript | |||
showdown.setFlavor('github'); | |||
``` | |||
### Instance | |||
```javascript | |||
converter.setFlavor('github'); | |||
``` | |||
## CLI Tool | |||
Showdown also comes bundled with a Command Line Interface tool. You can check the [CLI wiki page][cli-wiki] 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][definitely-typed] | |||
## Integration with SystemJS/JSPM | |||
Integration with SystemJS can be obtained via the third party ["system-md" plugin](https://github.com/guybedford/system-md). | |||
## Integration with VueJS | |||
To use ShowdownJS as a Vue component quickly, you can check [vue-showdown](https://vue-showdown.js.org/). | |||
## 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. | |||
Please refer to the wiki article [Markdown's XSS Vulnerability (and how to mitigate it)][xss-wiki] | |||
for more information. | |||
## Extensions | |||
Showdown allows additional functionality to be loaded via extensions. (you can find a list of known showdown extensions [here][ext-wiki]) | |||
You can also find a boilerplate, to create your own extensions in [this repository][boilerplate-repo] | |||
### Client-side Extension Usage | |||
```js | |||
<script src="showdown.js" /> | |||
<script src="twitter-extension.js" /> | |||
var converter = new showdown.Converter({ extensions: ['twitter'] }); | |||
``` | |||
### Server-side Extension Usage | |||
```js | |||
var showdown = require('showdown'), | |||
myExtension = require('myExtension'), | |||
converter = new showdown.Converter({ extensions: ['myExtension'] }); | |||
``` | |||
## 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: | |||
- Search GitHub for an open or closed Pull Request that relates to your submission. You don't want to duplicate effort. | |||
- When issuing PRs that change code, make your changes in a new git branch based on master: | |||
```bash | |||
git checkout -b my-fix-branch master | |||
``` | |||
- Documentation (i.e: README.md) changes can be made directly against master. | |||
- Run the full test suite before submitting and make sure all tests pass (obviously =P). | |||
- Try to follow our [**coding style rules**][coding-rules]. | |||
Breaking them prevents the PR to pass the tests. | |||
- Refrain from fixing multiple issues in the same pull request. It's preferable to open multiple small PRs instead of one | |||
hard to review big one. | |||
- If the PR introduces a new feature or fixes an issue, please add the appropriate test case. | |||
- We use commit notes to generate the changelog. It's extremely helpful if your commit messages adhere to the | |||
[**AngularJS Git Commit Guidelines**][ng-commit-guide]. | |||
- If we suggest changes then: | |||
- Make the required updates. | |||
- Re-run the Angular test suite to ensure tests are still passing. | |||
- Rebase your branch and force push to your GitHub repository (this will update your Pull Request): | |||
```bash | |||
git rebase master -i | |||
git push origin my-fix-branch -f | |||
``` | |||
- After your pull request is merged, you can safely delete your branch. | |||
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](https://github.com/showdownjs/showdown/issues/114) 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:<br/> | |||
[](https://www.jetbrains.com/webstorm/) | |||
[sd-logo]: https://raw.githubusercontent.com/showdownjs/logo/master/dist/logo.readme.png | |||
[legacy-branch]: https://github.com/showdownjs/showdown/tree/legacy | |||
[releases]: https://github.com/showdownjs/showdown/releases | |||
[changelog]: https://github.com/showdownjs/showdown/blob/master/CHANGELOG.md | |||
[wiki]: https://github.com/showdownjs/showdown/wiki | |||
[cli-wiki]: https://github.com/showdownjs/showdown/wiki/CLI-tool | |||
[definitely-typed]: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/showdown | |||
[xss-wiki]: https://github.com/showdownjs/showdown/wiki/Markdown's-XSS-Vulnerability-(and-how-to-mitigate-it) | |||
[ext-wiki]: https://github.com/showdownjs/showdown/wiki/extensions | |||
[coding-rules]: https://github.com/showdownjs/code-style/blob/master/README.md | |||
[ng-commit-guide]: https://github.com/showdownjs/code-style/blob/master/README.md#commit-message-convention | |||
[boilerplate-repo]: https://github.com/showdownjs/extension-boilerplate |
@ -0,0 +1,140 @@ | |||
# ROADMAP TO VERSION 2.0 | |||
## Options | |||
- [ ] **ghCompatibleHeaderId** (removal) | |||
Will be removed and **will become the default behavior**. | |||
- [ ] **customizedHeaderId** (removal) | |||
This option introduced non compliant syntax so it really belongs in an extension. | |||
The new **listener extension system** allows users to directly modify and customize | |||
the HTML and add any attributes they wish. | |||
- [ ] **rawPrefixHeaderId** (removal) | |||
This option will be superseeded by the option `rawHeaderId`. So basically activating `rawHeaderId` will make | |||
showdown only to replace spaces, ', ", > and < with dashes (-) from generated header ids, including prefixes. | |||
- [X] **literalMidWordAsterisks** (removal) | |||
This option is weird, hard to maintain and really... makes little sense. | |||
- [X] **excludeTrailingPunctuationFromURLs** (removal) | |||
This option will be removed and will be the default behavior from now on. | |||
- [ ] **strikethrough** (change) | |||
Will be enabled by default | |||
- [ ] **disableForced4SpacesIndentedSublists** (to think/postpone) | |||
This was only a temporary option for backwards compatibility reason. However, most flavours support lists indented | |||
with 2 spaces, so it puts us in a tight spot, specially since some markdown beautifiers out there insist in | |||
indenting lists with 2 spaces, probably in a misguided try to follow the CommonMark spec. | |||
The CommonMark spec is, IMHO, a bit confusing for users regarding this, since list sub-blocks (and lists) | |||
are determined by the spaces from the start of the line and the first character after the list mark. And the proof | |||
are the MD beautifiers out there, which misinterpreted the spec and made a mess | |||
Showdown syntax is actually easier (and fully compliant with the original spec): if you indent something 4 spaces, | |||
it becomes a sub-block. Since lists are blocks, you must indent it 4 spaces for it to become a sub-block. | |||
Regardless, we kinda have 2 solutions: | |||
- Drop support for 2 space indentation (and make a lot of users confused since GFM, CommonMark and others allow this) | |||
- Create a new list subparser that can be turned on with an option, like gfmListStyle | |||
(but postpones even more the alpha 2.0 release since the list subparser is probably the hardest thing to rewrite) | |||
Tough choices... | |||
- [ ] **simpleLineBreaks** (change) | |||
Will be removed from Github Flavor since github only does this in comments (which is weird...) | |||
- [ ] **openLinksInNewWindow** (removal) | |||
Will be removed in favor of the new listener extension, which will allow users to manipulate HTML tags attributes | |||
directly. | |||
- [ ] Revamp the option system | |||
Revamp the option system so that it becomes more simple. Right now, it's really confusing. And option names are weird | |||
too. The idea is to pass options to the constructor under an option object, that can have hierarchical structure. | |||
Ex: | |||
```js | |||
var conv = new showdown.Converter({ | |||
options: { | |||
links: { | |||
autoLinks: true | |||
}, | |||
headings: { | |||
startLevel: 2 | |||
} | |||
} | |||
}); | |||
``` | |||
## Legacy Code Removal | |||
- [ ] Legacy extension support | |||
Old extensions that inject directly into extensions object property will no longer be supported | |||
- [ ] HTML and OUTPUT extensions | |||
HTML and OTP extensions will be dropped in favor of Listener Extensions. We might even give them a new name | |||
## Subparsers | |||
- [X] **Anchors**: Revamp the anchors subparser so it calls strikethrough, bold, italic and underline directly | |||
- [X] **autoLinks**: Fix some lingering bugs and issues with autolinks | |||
## Priority Bugs | |||
- [X] **#355**: *simplifiedAutoLink URLs inside parenthesis followed by another character are not parsed correctly* | |||
- [X] **#534**: *Multiple parentheses () in url link is not parsed correctly* | |||
- [ ] **#367**: *sublists rendering with 2 spaces* - related to disableForced4SpacesIndentedSublists option... | |||
- [ ] **#537**: *master branch doesn't work in a web worker* | |||
## CLI | |||
- [ ] Refactor the CLI | |||
- [ ] **#381**: *Support for src and dst directories in showdown cli* | |||
- [ ] **#584**: *Fails to read from stdin* | |||
- [ ] **#554**: *CLI not working with jsdom v10* | |||
## Other stuff | |||
- [X] Regexp rewrite for more performance oompf | |||
- [ ] Full unit testing | |||
- [ ] Better error reporting | |||
## Stuff that probably won't make it to v2.0 | |||
- [ ] **#486**: *A backslash at the end of the line is a hard line break* | |||
- [ ] **#548**: *anchors and images of subParser are errors when they are specific strings* | |||
- [ ] **#549**: *Strange parsing issue with `<pre><code>`* | |||
- [ ] Rethink the global variable | |||
## NEW Features | |||
### Event system | |||
- [X] Listener system revamp | |||
- [ ] Standardize events for all event types | |||
- [ ] Unit testing | |||
- [ ] Functional testing | |||
This should address: | |||
- **#567**: Allow not making header ids lowercase | |||
- **#540**: Add complete class to the tasklist list element | |||
### MD to HTML conversion | |||
- [X] Basic support | |||
- [X] Basic functional testcase | |||
- [ ] Advanced support for all showdown MD features | |||
- [ ] Advanced functional testcase | |||
- [ ] Unit testing | |||
## Documentation (for v2.0) | |||
- [ ] Options | |||
- [ ] Extensions (and the new event system) | |||
- [ ] Cookbook (with stuff for backwards compatibility, specially regarding removed options) |
@ -0,0 +1,2 @@ | |||
#!/usr/bin/env node | |||
require('../src/cli/cli'); |
@ -0,0 +1,32 @@ | |||
{ | |||
"name": "showdown", | |||
"description": "A Markdown to HTML converter written in Javascript", | |||
"homepage": "https://github.com/showdownjs/showdown", | |||
"authors": [ | |||
"Estevão Santos (https://github.com/tivie)", | |||
"Pascal Deschênes (https://github.com/pdeschen)" | |||
], | |||
"main": ["dist/showdown.js"], | |||
"ignore": [ | |||
".editorconfig", | |||
".gitattributes", | |||
".gitignore", | |||
".jscs.json", | |||
".jshintignore", | |||
".jshintrc", | |||
".travis.yml", | |||
"Gruntfile.js", | |||
"package.json", | |||
"test/*" | |||
], | |||
"repository": { | |||
"type": "git", | |||
"url": "https://github.com/showdownjs/showdown.git" | |||
}, | |||
"keywords": [ | |||
"markdown", | |||
"md", | |||
"mdown" | |||
], | |||
"license": "https://github.com/showdownjs/showdown/blob/master/license.txt" | |||
} |
@ -0,0 +1,149 @@ | |||
# Event System | |||
## Introduction | |||
## The Event Object | |||
## Events | |||
Events are raised when a subparser is run (or about to be run). | |||
Within a subparser, the events always follow a certain order (sequence). For instance, **.before** events always run before **.captureStart**. | |||
Each subparser raises several events sequentially: | |||
1. **.start**: **always runs** except it subparser is disabled | |||
Raised when the **subparser has started**, but no capturing or any modification to the text was done. | |||
**Always runs** (except if the subparser is deactivated through options). | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|-----------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The full text that was passed to the subparser | | |||
| output | string | write | The full text with modification that will be passed along the chain| | |||
| regex | null | | | | |||
| matches | null | | | | |||
Usually you would want to use this event if you wish to change the input to the subparser | |||
2. **.captureStart**: *might not be run*; | |||
Raised when a regex match is found and a capture was successful. Some normalization and modification | |||
of the regex captured groups might be performed. | |||
Might not be run if no regex match is found. | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|-----------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The captured text | | |||
| output | string | write | The text that will be passed to the subparser/other listeners | | |||
| regex | RegExp | readonly | Regular Expression used to capture groups | | |||
| matches | object | read/write | Matches groups. Changes to this object are reflected in the output | | |||
Usually you would want to use this event if you wish to modify a certain subparser behavior. | |||
Exs: remove all title attributes from links; change indentation of code blocks; etc... | |||
3. **.captureEnd**: *might not be run*; | |||
Raised after the modifications to the captured text are done but before the replacement is introduced in the document. | |||
Might not be run if no regex match is found. | |||
***Properties***: | |||
| property | type | access | description | | |||
|------------|-----------|------------|--------------------------------------------------------------------------------| | |||
| input | string | read | The captured text | | |||
| output | string | write | The text that will be passed to the subparser/other listeners | | |||
| regex | RegExp | readonly | Regular Expression used to capture groups | | |||
| matches | object | read/write | Keypairs of matches groups. Changes to this object are reflected in the output | | |||
| attributes | object | read/write | Attributes to add to the HTML output | | |||
4. **.beforeHash**: *might not be run*; | |||
Raised before the output is hashed. | |||
Always run (except if the subparser was deactivated through options), even if no hashing is performed. | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|------------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The captured text | | |||
| output | string | write | The text that will be passed to the subparser/other listeners | | |||
| regex | null | | | | |||
| matches | null | | | | |||
Usually you would want to use this event if you wish change the subparser output before it is hashed | |||
5. **.end**: *always runs*; | |||
Raised when the subparser has finished its work and is about to exit. | |||
Always runs (except if the subparser is deactivated through options). | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|-----------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The partial/full text with the subparser modifications | | |||
| output | string | write | The text that will be passed to other subparsers | | |||
| regex | null | | | | |||
| matches | null | | | | |||
Usually you would want to use this event if you wish change the subparser hashed output | |||
### Special Events | |||
There are some special events that are useful for *"positioning"* a listener extension in the main chain of events. | |||
Usually these extensions introduce new syntax that, due to precedence | |||
These events are always guaranteed to be called, regardless of options or circumstances. | |||
1. **.before_{subparserName}**: *always runs* | |||
Raised just before the **{subparserName} is about to be entered**. | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|-----------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The full text that was passed to the subparser | | |||
| output | string | write | The full text with modification that will be passed along the chain| | |||
| regex | null | | | | |||
| matches | null | | | | |||
2. **.after**.{subparserName}: *always runs*; | |||
Raised when the **{subparserName} has exited** and before the next one is called. | |||
***Properties***: | |||
| property | type | access | description | | |||
|----------|-----------|------------|--------------------------------------------------------------------| | |||
| input | string | read | The partial/full text with the subparser modifications | | |||
| output | string | write | The text that will be passed to other subparsers | | |||
| regex | null | | | | |||
| matches | null | | | | |||
### Notes | |||
- There are 2 main differences between **before.{subparserName}** and **{subparserName}.start**. | |||
1. **before.{subparserName}** is always guaranteed to be called, even if the subparser is disabled, | |||
while **{subparserName}.start** doesn't. | |||
ex: `makehtml.before.strikethrough` is always called even if the option `strikethrough` is false | |||
2. **before.{subparserName}** is only raised once in a span context while **{subparserName}.start** is raised | |||
everytime **{subparserName}** is called. | |||
As a rule of thumb, | |||
## Events List |
@ -0,0 +1,9 @@ | |||
# Index | |||
1. Options | |||
2. Subparsers | |||
3. [Event System](event_system.md) | |||
1. [Introduction](event_system.md#introduction) | |||
2. [The Event Object](event_system.md#the-event-object) | |||
3. [Events](event_system.md#events) | |||
4. [Events List](event_system.md#events-list) |
@ -0,0 +1,69 @@ | |||
{ | |||
"name": "showdown", | |||
"version": "2.0.0-alpha1", | |||
"description": "A Markdown to HTML converter written in Javascript", | |||
"author": "Estevão Santos", | |||
"homepage": "http://showdownjs.com/", | |||
"keywords": [ | |||
"markdown", | |||
"converter" | |||
], | |||
"contributors": [ | |||
"John Gruber", | |||
"John Fraser", | |||
"Corey Innis", | |||
"Remy Sharp", | |||
"Konstantin Käfer", | |||
"Roger Braun", | |||
"Dominic Tarr", | |||
"Cat Chen", | |||
"Titus Stone", | |||
"Rob Sutherland", | |||
"Pavel Lang", | |||
"Ben Combee", | |||
"Adam Backstrom", | |||
"Pascal Deschênes", | |||
"Estevão Santos" | |||
], | |||
"repository": { | |||
"type": "git", | |||
"url": "https://github.com/showdownjs/showdown.git", | |||
"web": "https://github.com/showdownjs/showdown" | |||
}, | |||
"license": "BSD-3-Clause", | |||
"main": "./dist/showdown.js", | |||
"scripts": { | |||
"test": "grunt test" | |||
}, | |||
"bin": { | |||
"showdown": "bin/showdown.js" | |||
}, | |||
"files": [ | |||
"bin", | |||
"dist" | |||
], | |||
"devDependencies": { | |||
"chai": "4.1.x", | |||
"grunt": "^1.0.3", | |||
"grunt-contrib-clean": "1.1.x", | |||
"grunt-contrib-concat": "1.0.x", | |||
"grunt-contrib-jshint": "1.1.x", | |||
"grunt-contrib-uglify": "~3.3.0", | |||
"grunt-conventional-changelog": "6.1.x", | |||
"grunt-conventional-github-releaser": "1.0.x", | |||
"grunt-endline": "0.6.x", | |||
"grunt-eslint": "19.0.x", | |||
"grunt-simple-mocha": "0.4.x", | |||
"load-grunt-tasks": "3.5.x", | |||
"performance-now": "2.0.x", | |||
"quiet-grunt": "0.2.x", | |||
"semver": "5.4.x", | |||
"semver-sort": "0.0.x", | |||
"sinon": "^5.1.1", | |||
"source-map-support": "^0.5.9" | |||
}, | |||
"dependencies": { | |||
"jsdom": "^11.0.0", | |||
"yargs": "14.2.0" | |||
} | |||
} |
@ -0,0 +1,45 @@ | |||
/** | |||
* Created by tivie | |||
*/ | |||
'use strict'; | |||
var yargs = require('yargs'); | |||
yargs | |||
.version() | |||
.alias('v', 'version') | |||
.option('h', { | |||
alias: 'help', | |||
description: 'Show help' | |||
}) | |||
.option('q', { | |||
alias: 'quiet', | |||
description: 'Quiet mode. Only print errors', | |||
type: 'boolean', | |||
default: false | |||
}) | |||
.option('m', { | |||
alias: 'mute', | |||
description: 'Mute mode. Does not print anything', | |||
type: 'boolean', | |||
default: false | |||
}) | |||
.usage('Usage: showdown <command> [options]') | |||
.demand(1, 'You must provide a valid command') | |||
.command('makehtml', 'Converts markdown into html') | |||
.example('showdown makehtml -i foo.md -o bar.html', 'Converts \'foo.md\' to \'bar.html\'') | |||
.wrap(yargs.terminalWidth()); | |||
var argv = yargs.argv, | |||
command = argv._[0]; | |||
if (command === 'makehtml') { | |||
require('./makehtml.cmd.js').run(); | |||
} else { | |||
yargs.showHelp(); | |||
} | |||
if (argv.help) { | |||
yargs.showHelp(); | |||
} | |||
process.exit(0); |
@ -0,0 +1,195 @@ | |||
var yargs = require('yargs'), | |||
fs = require('fs'), | |||
Messenger = require('./messenger.js'), | |||
showdown = require('../../dist/showdown'), | |||
showdownOptions = showdown.getDefaultOptions(false); | |||
yargs.reset() | |||
.usage('Usage: showdown makehtml [options]') | |||
.example('showdown makehtml -i', 'Reads from stdin and outputs to stdout') | |||
.example('showdown makehtml -i foo.md -o bar.html', 'Reads \'foo.md\' and writes to \'bar.html\'') | |||
.example('showdown makehtml -i --flavor="github"', 'Parses stdin using GFM style') | |||
.version() | |||
.alias('v', 'version') | |||
.config('c') | |||
.alias('c', 'config') | |||
.help('h') | |||
.alias('h', 'help') | |||
.option('i', { | |||
alias : 'input', | |||
describe: 'Input source. Usually a md file. If omitted or empty, reads from stdin', | |||
type: 'string' | |||
}) | |||
.option('o', { | |||
alias : 'output', | |||
describe: 'Output target. Usually a html file. If omitted or empty, writes to stdout', | |||
type: 'string', | |||
default: false | |||
}) | |||
.option('u', { | |||
alias : 'encoding', | |||
describe: 'Input encoding', | |||
type: 'string' | |||
}) | |||
.option('a', { | |||
alias : 'append', | |||
describe: 'Append data to output instead of overwriting', | |||
type: 'string', | |||
default: false | |||
}) | |||
.option('e', { | |||
alias : 'extensions', | |||
describe: 'Load the specified extensions. Should be valid paths to node compatible extensions', | |||
type: 'array' | |||
}) | |||
.option('p', { | |||
alias : 'flavor', | |||
describe: 'Run with a predetermined flavor of options. Default is vanilla', | |||
type: 'string' | |||
}) | |||
.option('q', { | |||
alias: 'quiet', | |||
description: 'Quiet mode. Only print errors', | |||
type: 'boolean', | |||
default: false | |||
}) | |||
.option('m', { | |||
alias: 'mute', | |||
description: 'Mute mode. Does not print anything', | |||
type: 'boolean', | |||
default: false | |||
}); | |||
// load showdown default options | |||
for (var opt in showdownOptions) { | |||
if (showdownOptions.hasOwnProperty(opt)) { | |||
if (showdownOptions[opt].defaultValue === false) { | |||
showdownOptions[opt].default = null; | |||
} else { | |||
showdownOptions[opt].default = showdownOptions[opt].defaultValue; | |||
} | |||
yargs.option(opt, showdownOptions[opt]); | |||
} | |||
} | |||
function run () { | |||
'use strict'; | |||
var argv = yargs.argv, | |||
readMode = (!argv.i || argv.i === '') ? 'stdin' : 'file', | |||
writeMode = (!argv.o || argv.o === '') ? 'stdout' : 'file', | |||
msgMode = (writeMode === 'file') ? 'stdout' : 'stderr', | |||
/** | |||
* MSG object | |||
* @type {Messenger} | |||
*/ | |||
messenger = new Messenger(msgMode, argv.q, argv.m), | |||
read = (readMode === 'stdin') ? readFromStdIn : readFromFile, | |||
write = (writeMode === 'stdout') ? writeToStdOut : writeToFile, | |||
enc = argv.encoding || 'utf8', | |||
flavor = argv.p, | |||
append = argv.a || false, | |||
options = parseOptions(flavor), | |||
converter = new showdown.Converter(options), | |||
md, html; | |||
// Load extensions | |||
if (argv.e) { | |||
messenger.printMsg('Loading extensions'); | |||
for (var i = 0; i < argv.e.length; ++i) { | |||
try { | |||
var ext = require(argv.e[i]); | |||
converter.addExtension(ext, argv.e[i]); | |||
} catch (e) { | |||
messenger.printError('Could not load extension ' + argv.e[i] + '. Reason:'); | |||
messenger.errorExit(e); | |||
} | |||
} | |||
} | |||
messenger.printMsg('...'); | |||
// read the input | |||
messenger.printMsg('Reading data from ' + readMode + '...'); | |||
md = read(enc); | |||
// process the input | |||
messenger.printMsg('Parsing markdown...'); | |||
html = converter.makeHtml(md); | |||
// write the output | |||
messenger.printMsg('Writing data to ' + writeMode + '...'); | |||
write(html, append); | |||
messenger.okExit(); | |||
function parseOptions (flavor) { | |||
var options = {}, | |||
flavorOpts = showdown.getFlavorOptions(flavor) || {}; | |||
// if flavor is not undefined, let's tell the user we're loading that preset | |||
if (flavor) { | |||
messenger.printMsg('Loading ' + flavor + ' flavor.'); | |||
} | |||
for (var opt in argv) { | |||
if (argv.hasOwnProperty(opt)) { | |||
// first we load the default options | |||
if (showdownOptions.hasOwnProperty(opt) && showdownOptions[opt].default !== null) { | |||
options[opt] = showdownOptions[opt].default; | |||
} | |||
// we now override defaults with flavor, if a flavor was indeed passed | |||
if (flavorOpts.hasOwnProperty(opt)) { | |||
options[opt] = flavorOpts[opt]; | |||
} | |||
// lastly we override with explicit passed options | |||
// being careful not to pass CLI specific options, such as -v, -h or --extensions | |||
if (showdownOptions.hasOwnProperty(opt)) { | |||
if (argv[opt] === true) { | |||
messenger.printMsg('Enabling option ' + opt); | |||
options[opt] = argv[opt]; | |||
} else if (argv[opt] === false) { | |||
options[opt] = argv[opt]; | |||
} | |||
} | |||
} | |||
} | |||
return options; | |||
} | |||
function readFromStdIn () { | |||
try { | |||
var size = fs.fstatSync(process.stdin.fd).size; | |||
return size > 0 ? fs.readSync(process.stdin.fd, size)[0] : ''; | |||
} catch (e) { | |||
var err = new Error('Could not read from stdin, reason: ' + e.message); | |||
messenger.errorExit(err); | |||
} | |||
} | |||
function readFromFile (encoding) { | |||
try { | |||
return fs.readFileSync(argv.i, encoding); | |||
} catch (err) { | |||
messenger.errorExit(err); | |||
} | |||
} | |||
function writeToStdOut (html) { | |||
return process.stdout.write(html); | |||
} | |||
function writeToFile (html, append) { | |||
// If a flag is passed, it means we should append instead of overwriting. | |||
// Only works with files, obviously | |||
var write = (append) ? fs.appendFileSync : fs.writeFileSync; | |||
try { | |||
write(argv.o, html); | |||
} catch (err) { | |||
messenger.errorExit(err); | |||
} | |||
} | |||
} | |||
module.exports = exports = { | |||
run: run | |||
}; |
@ -0,0 +1,40 @@ | |||
function Messenger (writeMode, supress, mute) { | |||
'use strict'; | |||
writeMode = writeMode || 'stderr'; | |||
supress = (!!supress || !!mute); | |||
mute = !!mute; | |||
this._print = (writeMode === 'stdout') ? console.log : console.error; | |||
this.errorExit = function (e) { | |||
if (!mute) { | |||
console.error('ERROR: ' + e.message); | |||
console.error('Run \'showdown <command> -h\' for help'); | |||
} | |||
process.exit(1); | |||
}; | |||
this.okExit = function () { | |||
if (!mute) { | |||
this._print('\n'); | |||
this._print('DONE!'); | |||
} | |||
process.exit(0); | |||
}; | |||
this.printMsg = function (msg) { | |||
if (supress || mute || !msg) { | |||
return; | |||
} | |||
this._print(msg); | |||
}; | |||
this.printError = function (msg) { | |||
if (mute) { | |||
return; | |||
} | |||
console.error(msg); | |||
}; | |||
} | |||
module.exports = Messenger; |
@ -0,0 +1,602 @@ | |||
/** | |||
* Created by Estevao on 31-05-2015. | |||
*/ | |||
/** | |||
* Showdown Converter class | |||
* @class | |||
* @param {object} [converterOptions] | |||
* @returns {Converter} | |||
*/ | |||
showdown.Converter = function (converterOptions) { | |||
'use strict'; | |||
var | |||
/** | |||
* Options used by this converter | |||
* @private | |||
* @type {{}} | |||
*/ | |||
options = {}, | |||
/** | |||
* Language extensions used by this converter | |||
* @private | |||
* @type {Array} | |||
*/ | |||
langExtensions = [], | |||
/** | |||
* Output modifiers extensions used by this converter | |||
* @private | |||
* @type {Array} | |||
*/ | |||
outputModifiers = [], | |||
/** | |||
* Event listeners | |||
* @private | |||
* @type {{}} | |||
*/ | |||
listeners = {}, | |||
/** | |||
* The flavor set in this converter | |||
*/ | |||
setConvFlavor = setFlavor, | |||
/** | |||
* Metadata of the document | |||
* @type {{parsed: {}, raw: string, format: string}} | |||
*/ | |||
metadata = { | |||
parsed: {}, | |||
raw: '', | |||
format: '' | |||
}; | |||
_constructor(); | |||
/** | |||
* Converter constructor | |||
* @private | |||
*/ | |||
function _constructor () { | |||
converterOptions = converterOptions || {}; | |||
for (var gOpt in globalOptions) { | |||
if (globalOptions.hasOwnProperty(gOpt)) { | |||
options[gOpt] = globalOptions[gOpt]; | |||
} | |||
} | |||
// Merge options | |||
if (typeof converterOptions === 'object') { | |||
for (var opt in converterOptions) { | |||
if (converterOptions.hasOwnProperty(opt)) { | |||
options[opt] = converterOptions[opt]; | |||
} | |||
} | |||
} else { | |||
throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions + | |||
' was passed instead.'); | |||
} | |||
if (options.extensions) { | |||
showdown.helper.forEach(options.extensions, _parseExtension); | |||
} | |||
} | |||
/** | |||
* Parse extension | |||
* @param {*} ext | |||
* @param {string} [name=''] | |||
* @private | |||
*/ | |||
function _parseExtension (ext, name) { | |||
name = name || null; | |||
// If it's a string, the extension was previously loaded | |||
if (showdown.helper.isString(ext)) { | |||
ext = showdown.helper.stdExtName(ext); | |||
name = ext; | |||
// LEGACY_SUPPORT CODE | |||
if (showdown.extensions[ext]) { | |||
console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' + | |||
'Please inform the developer that the extension should be updated!'); | |||
legacyExtensionLoading(showdown.extensions[ext], ext); | |||
return; | |||
// END LEGACY SUPPORT CODE | |||
} else if (!showdown.helper.isUndefined(extensions[ext])) { | |||
ext = extensions[ext]; | |||
} else { | |||
throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.'); | |||
} | |||
} | |||
if (typeof ext === 'function') { | |||
ext = ext(); | |||
} | |||
if (!showdown.helper.isArray(ext)) { | |||
ext = [ext]; | |||
} | |||
var validExt = validate(ext, name); | |||
if (!validExt.valid) { | |||
throw Error(validExt.error); | |||
} | |||
for (var i = 0; i < ext.length; ++i) { | |||
switch (ext[i].type) { | |||
case 'lang': | |||
langExtensions.push(ext[i]); | |||
break; | |||
case 'output': | |||
outputModifiers.push(ext[i]); | |||
break; | |||
} | |||
if (ext[i].hasOwnProperty('listeners')) { | |||
for (var ln in ext[i].listeners) { | |||
if (ext[i].listeners.hasOwnProperty(ln)) { | |||
listen(ln, ext[i].listeners[ln]); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* LEGACY_SUPPORT | |||
* @param {*} ext | |||
* @param {string} name | |||
*/ | |||
function legacyExtensionLoading (ext, name) { | |||
if (typeof ext === 'function') { | |||
ext = ext(new showdown.Converter()); | |||
} | |||
if (!showdown.helper.isArray(ext)) { | |||
ext = [ext]; | |||
} | |||
var valid = validate(ext, name); | |||
if (!valid.valid) { | |||
throw Error(valid.error); | |||
} | |||
for (var i = 0; i < ext.length; ++i) { | |||
switch (ext[i].type) { | |||
case 'lang': | |||
langExtensions.push(ext[i]); | |||
break; | |||
case 'output': | |||
outputModifiers.push(ext[i]); | |||
break; | |||
default:// should never reach here | |||
throw Error('Extension loader error: Type unrecognized!!!'); | |||
} | |||
} | |||
} | |||
/** | |||
* Listen to an event | |||
* @param {string} name | |||
* @param {function} callback | |||
*/ | |||
function listen (name, callback) { | |||
if (!showdown.helper.isString(name)) { | |||
throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given'); | |||
} | |||
if (typeof callback !== 'function') { | |||
throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given'); | |||
} | |||
name = name.toLowerCase(); | |||
if (!listeners.hasOwnProperty(name)) { | |||
listeners[name] = []; | |||
} | |||
listeners[name].push(callback); | |||
} | |||
function rTrimInputText (text) { | |||
var rsp = text.match(/^\s*/)[0].length, | |||
rgx = new RegExp('^\s{0,' + rsp + '}', 'gm'); | |||
return text.replace(rgx, ''); | |||
} | |||
/** | |||
* | |||
* @param {string} evtName Event name | |||
* @param {string} text Text | |||
* @param {{}} options Converter Options | |||
* @param {{}} globals Converter globals | |||
* @param {{}} pParams extra params for event | |||
* @returns showdown.helper.Event | |||
* @private | |||
*/ | |||
this._dispatch = function dispatch (evtName, text, options, globals, pParams) { | |||
evtName = evtName.toLowerCase(); | |||
var params = pParams || {}; | |||
params.converter = this; | |||
params.text = text; | |||
params.options = options; | |||
params.globals = globals; | |||
var event = new showdown.helper.Event(evtName, text, params); | |||
if (listeners.hasOwnProperty(evtName)) { | |||
for (var ei = 0; ei < listeners[evtName].length; ++ei) { | |||
var nText = listeners[evtName][ei](event); | |||
if (nText && typeof nText !== 'undefined') { | |||
event.setText(nText); | |||
} | |||
} | |||
} | |||
return event; | |||
}; | |||
/** | |||
* Listen to an event | |||
* @param {string} name | |||
* @param {function} callback | |||
* @returns {showdown.Converter} | |||
*/ | |||
this.listen = function (name, callback) { | |||
listen(name, callback); | |||
return this; | |||
}; | |||
/** | |||
* Converts a markdown string into HTML string | |||
* @param {string} text | |||
* @returns {*} | |||
*/ | |||
this.makeHtml = function (text) { | |||
//check if text is not falsy | |||
if (!text) { | |||
return text; | |||
} | |||
var globals = { | |||
gHtmlBlocks: [], | |||
gHtmlMdBlocks: [], | |||
gHtmlSpans: [], | |||
gUrls: {}, | |||
gTitles: {}, | |||
gDimensions: {}, | |||
gListLevel: 0, | |||
hashLinkCounts: {}, | |||
langExtensions: langExtensions, | |||
outputModifiers: outputModifiers, | |||
converter: this, | |||
ghCodeBlocks: [], | |||
metadata: { | |||
parsed: {}, | |||
raw: '', | |||
format: '' | |||
} | |||
}; | |||
// This lets us use ¨ trema as an escape char to avoid md5 hashes | |||
// The choice of character is arbitrary; anything that isn't | |||
// magic in Markdown will work. | |||
text = text.replace(/¨/g, '¨T'); | |||
// Replace $ with ¨D | |||
// RegExp interprets $ as a special character | |||
// when it's in a replacement string | |||
text = text.replace(/$/g, '¨D'); | |||
// Standardize line endings | |||
text = text.replace(/\r\n/g, '\n'); // DOS to Unix | |||
text = text.replace(/\r/g, '\n'); // Mac to Unix | |||
// Stardardize line spaces | |||
text = text.replace(/\u00A0/g, ' '); | |||
if (options.smartIndentationFix) { | |||
text = rTrimInputText(text); | |||
} | |||
// Make sure text begins and ends with a couple of newlines: | |||
text = '\n\n' + text + '\n\n'; | |||
// detab | |||
text = showdown.subParser('makehtml.detab')(text, options, globals); | |||
/** | |||
* Strip any lines consisting only of spaces and tabs. | |||
* This makes subsequent regexs easier to write, because we can | |||
* match consecutive blank lines with /\n+/ instead of something | |||
* contorted like /[ \t]*\n+/ | |||
*/ | |||
text = text.replace(/^[ \t]+$/mg, ''); | |||
//run languageExtensions | |||
showdown.helper.forEach(langExtensions, function (ext) { | |||
text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals); | |||
}); | |||
// run the sub parsers | |||
text = showdown.subParser('makehtml.metadata')(text, options, globals); | |||
text = showdown.subParser('makehtml.hashPreCodeTags')(text, options, globals); | |||
text = showdown.subParser('makehtml.githubCodeBlocks')(text, options, globals); | |||
text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals); | |||
text = showdown.subParser('makehtml.hashCodeTags')(text, options, globals); | |||
text = showdown.subParser('makehtml.stripLinkDefinitions')(text, options, globals); | |||
text = showdown.subParser('makehtml.blockGamut')(text, options, globals); | |||
text = showdown.subParser('makehtml.unhashHTMLSpans')(text, options, globals); | |||
text = showdown.subParser('makehtml.unescapeSpecialChars')(text, options, globals); | |||
// attacklab: Restore dollar signs | |||
text = text.replace(/¨D/g, '$$'); | |||
// attacklab: Restore tremas | |||
text = text.replace(/¨T/g, '¨'); | |||
// render a complete html document instead of a partial if the option is enabled | |||
text = showdown.subParser('makehtml.completeHTMLDocument')(text, options, globals); | |||
// Run output modifiers | |||
showdown.helper.forEach(outputModifiers, function (ext) { | |||
text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals); | |||
}); | |||
// update metadata | |||
metadata = globals.metadata; | |||
return text; | |||
}; | |||
/** | |||
* Converts an HTML string into a markdown string | |||
* @param src | |||
* @returns {string} | |||
*/ | |||
this.makeMarkdown = function (src) { | |||
// replace \r\n with \n | |||
src = src.replace(/\r\n/g, '\n'); | |||
src = src.replace(/\r/g, '\n'); // old macs | |||
// due to an edge case, we need to find this: > < | |||
// to prevent removing of non silent white spaces | |||
// ex: <em>this is</em> <strong>sparta</strong> | |||
src = src.replace(/>[ \t]+</, '>¨NBSP;<'); | |||
var doc = showdown.helper.document.createElement('div'); | |||
doc.innerHTML = src; | |||
var globals = { | |||
preList: substitutePreCodeTags(doc) | |||
}; | |||
// remove all newlines and collapse spaces | |||
clean(doc); | |||
// some stuff, like accidental reference links must now be escaped | |||
// TODO | |||
// doc.innerHTML = doc.innerHTML.replace(/\[[\S\t ]]/); | |||
var nodes = doc.childNodes, | |||
mdDoc = ''; | |||
for (var i = 0; i < nodes.length; i++) { | |||
mdDoc += showdown.subParser('makeMarkdown.node')(nodes[i], globals); | |||
} | |||
function clean (node) { | |||
for (var n = 0; n < node.childNodes.length; ++n) { | |||
var child = node.childNodes[n]; | |||
if (child.nodeType === 3) { | |||
if (!/\S/.test(child.nodeValue)) { | |||
node.removeChild(child); | |||
--n; | |||
} else { | |||
child.nodeValue = child.nodeValue.split('\n').join(' '); | |||
child.nodeValue = child.nodeValue.replace(/(\s)+/g, '$1'); | |||
} | |||
} else if (child.nodeType === 1) { | |||
clean(child); | |||
} | |||
} | |||
} | |||
// find all pre tags and replace contents with placeholder | |||
// we need this so that we can remove all indentation from html | |||
// to ease up parsing | |||
function substitutePreCodeTags (doc) { | |||
var pres = doc.querySelectorAll('pre'), | |||
presPH = []; | |||
for (var i = 0; i < pres.length; ++i) { | |||
if (pres[i].childElementCount === 1 && pres[i].firstChild.tagName.toLowerCase() === 'code') { | |||
var content = pres[i].firstChild.innerHTML.trim(), | |||
language = pres[i].firstChild.getAttribute('data-language') || ''; | |||
// if data-language attribute is not defined, then we look for class language-* | |||
if (language === '') { | |||
var classes = pres[i].firstChild.className.split(' '); | |||
for (var c = 0; c < classes.length; ++c) { | |||
var matches = classes[c].match(/^language-(.+)$/); | |||
if (matches !== null) { | |||
language = matches[1]; | |||
break; | |||
} | |||
} | |||
} | |||
// unescape html entities in content | |||
content = showdown.helper.unescapeHTMLEntities(content); | |||
presPH.push(content); | |||
pres[i].outerHTML = '<precode language="' + language + '" precodenum="' + i.toString() + '"></precode>'; | |||
} else { | |||
presPH.push(pres[i].innerHTML); | |||
pres[i].innerHTML = ''; | |||
pres[i].setAttribute('prenum', i.toString()); | |||
} | |||
} | |||
return presPH; | |||
} | |||
return mdDoc; | |||
}; | |||
/** | |||
* Set an option of this Converter instance | |||
* @param {string} key | |||
* @param {*} value | |||
*/ | |||
this.setOption = function (key, value) { | |||
options[key] = value; | |||
}; | |||
/** | |||
* Get the option of this Converter instance | |||
* @param {string} key | |||
* @returns {*} | |||
*/ | |||
this.getOption = function (key) { | |||
return options[key]; | |||
}; | |||
/** | |||
* Get the options of this Converter instance | |||
* @returns {{}} | |||
*/ | |||
this.getOptions = function () { | |||
return options; | |||
}; | |||
/** | |||
* Add extension to THIS converter | |||
* @param {{}} extension | |||
* @param {string} [name=null] | |||
*/ | |||
this.addExtension = function (extension, name) { | |||
name = name || null; | |||
_parseExtension(extension, name); | |||
}; | |||
/** | |||
* Use a global registered extension with THIS converter | |||
* @param {string} extensionName Name of the previously registered extension | |||
*/ | |||
this.useExtension = function (extensionName) { | |||
_parseExtension(extensionName); | |||
}; | |||
/** | |||
* Set the flavor THIS converter should use | |||
* @param {string} name | |||
*/ | |||
this.setFlavor = function (name) { | |||
if (!flavor.hasOwnProperty(name)) { | |||
throw Error(name + ' flavor was not found'); | |||
} | |||
var preset = flavor[name]; | |||
setConvFlavor = name; | |||
for (var option in preset) { | |||
if (preset.hasOwnProperty(option)) { | |||
options[option] = preset[option]; | |||
} | |||
} | |||
}; | |||
/** | |||
* Get the currently set flavor of this converter | |||
* @returns {string} | |||
*/ | |||
this.getFlavor = function () { | |||
return setConvFlavor; | |||
}; | |||
/** | |||
* Remove an extension from THIS converter. | |||
* Note: This is a costly operation. It's better to initialize a new converter | |||
* and specify the extensions you wish to use | |||
* @param {Array} extension | |||
*/ | |||
this.removeExtension = function (extension) { | |||
if (!showdown.helper.isArray(extension)) { | |||
extension = [extension]; | |||
} | |||
for (var a = 0; a < extension.length; ++a) { | |||
var ext = extension[a]; | |||
for (var i = 0; i < langExtensions.length; ++i) { | |||
if (langExtensions[i] === ext) { | |||
langExtensions[i].splice(i, 1); | |||
} | |||
} | |||
for (var ii = 0; ii < outputModifiers.length; ++i) { | |||
if (outputModifiers[ii] === ext) { | |||
outputModifiers[ii].splice(i, 1); | |||
} | |||
} | |||
} | |||
}; | |||
/** | |||
* Get all extension of THIS converter | |||
* @returns {{language: Array, output: Array}} | |||
*/ | |||
this.getAllExtensions = function () { | |||
return { | |||
language: langExtensions, | |||
output: outputModifiers | |||
}; | |||
}; | |||
/** | |||
* Get the metadata of the previously parsed document | |||
* @param raw | |||
* @returns {string|{}} | |||
*/ | |||
this.getMetadata = function (raw) { | |||
if (raw) { | |||
return metadata.raw; | |||
} else { | |||
return metadata.parsed; | |||
} | |||
}; | |||
/** | |||
* Get the metadata format of the previously parsed document | |||
* @returns {string} | |||
*/ | |||
this.getMetadataFormat = function () { | |||
return metadata.format; | |||
}; | |||
/** | |||
* Private: set a single key, value metadata pair | |||
* @param {string} key | |||
* @param {string} value | |||
*/ | |||
this._setMetadataPair = function (key, value) { | |||
metadata.parsed[key] = value; | |||
}; | |||
/** | |||
* Private: set metadata format | |||
* @param {string} format | |||
*/ | |||
this._setMetadataFormat = function (format) { | |||
metadata.format = format; | |||
}; | |||
/** | |||
* Private: set metadata raw text | |||
* @param {string} raw | |||
*/ | |||
this._setMetadataRaw = function (raw) { | |||
metadata.raw = raw; | |||
}; | |||
}; |
@ -0,0 +1,17 @@ | |||
var root = this; | |||
// AMD Loader | |||
if (typeof define === 'function' && define.amd) { | |||
define(function () { | |||
'use strict'; | |||
return showdown; | |||
}); | |||
// CommonJS/nodeJS Loader | |||
} else if (typeof module !== 'undefined' && module.exports) { | |||
module.exports = showdown; | |||
// Regular Browser loader | |||
} else { | |||
root.showdown = showdown; | |||
} |
@ -0,0 +1,187 @@ | |||
/** | |||
* Created by Tivie on 13-07-2015. | |||
*/ | |||
function getDefaultOpts (simple) { | |||
'use strict'; | |||
var defaultOptions = { | |||
omitExtraWLInCodeBlocks: { | |||
defaultValue: false, | |||
describe: 'Omit the default extra whiteline added to code blocks', | |||
type: 'boolean' | |||
}, | |||
noHeaderId: { | |||
defaultValue: false, | |||
describe: 'Turn on/off generated header id', | |||
type: 'boolean' | |||
}, | |||
prefixHeaderId: { | |||
defaultValue: false, | |||
describe: 'Add a prefix to the generated header ids. Passing a string will prefix that string to the header id. Setting to true will add a generic \'section-\' prefix', | |||
type: 'string' | |||
}, | |||
rawPrefixHeaderId: { | |||
defaultValue: false, | |||
describe: 'Setting this option to true will prevent showdown from modifying the prefix. This might result in malformed IDs (if, for instance, the " char is used in the prefix)', | |||
type: 'boolean' | |||
}, | |||
ghCompatibleHeaderId: { | |||
defaultValue: false, | |||
describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)', | |||
type: 'boolean' | |||
}, | |||
rawHeaderId: { | |||
defaultValue: false, | |||
describe: 'Remove only spaces, \' and " from generated header ids (including prefixes), replacing them with dashes (-). WARNING: This might result in malformed ids', | |||
type: 'boolean' | |||
}, | |||
headerLevelStart: { | |||
defaultValue: false, | |||
describe: 'The header blocks level start', | |||
type: 'integer' | |||
}, | |||
parseImgDimensions: { | |||
defaultValue: false, | |||
describe: 'Turn on/off image dimension parsing', | |||
type: 'boolean' | |||
}, | |||
simplifiedAutoLink: { | |||
defaultValue: false, | |||
describe: 'Turn on/off GFM autolink style', | |||
type: 'boolean' | |||
}, | |||
literalMidWordUnderscores: { | |||
defaultValue: false, | |||
describe: 'Parse midword underscores as literal underscores', | |||
type: 'boolean' | |||
}, | |||
literalMidWordAsterisks: { | |||
defaultValue: false, | |||
describe: 'Parse midword asterisks as literal asterisks', | |||
type: 'boolean' | |||
}, | |||
strikethrough: { | |||
defaultValue: false, | |||
describe: 'Turn on/off strikethrough support', | |||
type: 'boolean' | |||
}, | |||
tables: { | |||
defaultValue: false, | |||
describe: 'Turn on/off tables support', | |||
type: 'boolean' | |||
}, | |||
tablesHeaderId: { | |||
defaultValue: false, | |||
describe: 'Add an id to table headers', | |||
type: 'boolean' | |||
}, | |||
ghCodeBlocks: { | |||
defaultValue: true, | |||
describe: 'Turn on/off GFM fenced code blocks support', | |||
type: 'boolean' | |||
}, | |||
tasklists: { | |||
defaultValue: false, | |||
describe: 'Turn on/off GFM tasklist support', | |||
type: 'boolean' | |||
}, | |||
smoothLivePreview: { | |||
defaultValue: false, | |||
describe: 'Prevents weird effects in live previews due to incomplete input', | |||
type: 'boolean' | |||
}, | |||
smartIndentationFix: { | |||
defaultValue: false, | |||
description: 'Tries to smartly fix indentation in es6 strings', | |||
type: 'boolean' | |||
}, | |||
disableForced4SpacesIndentedSublists: { | |||
defaultValue: false, | |||
description: 'Disables the requirement of indenting nested sublists by 4 spaces', | |||
type: 'boolean' | |||
}, | |||
simpleLineBreaks: { | |||
defaultValue: false, | |||
description: 'Parses simple line breaks as <br> (GFM Style)', | |||
type: 'boolean' | |||
}, | |||
requireSpaceBeforeHeadingText: { | |||
defaultValue: false, | |||
description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)', | |||
type: 'boolean' | |||
}, | |||
ghMentions: { | |||
defaultValue: false, | |||
description: 'Enables github @mentions', | |||
type: 'boolean' | |||
}, | |||
ghMentionsLink: { | |||
defaultValue: 'https://github.com/{u}', | |||
description: 'Changes the link generated by @mentions. Only applies if ghMentions option is enabled.', | |||
type: 'string' | |||
}, | |||
encodeEmails: { | |||
defaultValue: true, | |||
description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities', | |||
type: 'boolean' | |||
}, | |||
openLinksInNewWindow: { | |||
defaultValue: false, | |||
description: 'Open all links in new windows', | |||
type: 'boolean' | |||
}, | |||
backslashEscapesHTMLTags: { | |||
defaultValue: false, | |||
description: 'Support for HTML Tag escaping. ex: \<div>foo\</div>', | |||
type: 'boolean' | |||
}, | |||
emoji: { | |||
defaultValue: false, | |||
description: 'Enable emoji support. Ex: `this is a :smile: emoji`', | |||
type: 'boolean' | |||
}, | |||
underline: { | |||
defaultValue: false, | |||
description: 'Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `<em>` and `<strong>`', | |||
type: 'boolean' | |||
}, | |||
completeHTMLDocument: { | |||
defaultValue: false, | |||
description: 'Outputs a complete html document, including `<html>`, `<head>` and `<body>` tags', | |||
type: 'boolean' | |||
}, | |||
metadata: { | |||
defaultValue: false, | |||
description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).', | |||
type: 'boolean' | |||
}, | |||
splitAdjacentBlockquotes: { | |||
defaultValue: false, | |||
description: 'Split adjacent blockquote blocks', | |||
type: 'boolean' | |||
} | |||
}; | |||
if (simple === false) { | |||
return JSON.parse(JSON.stringify(defaultOptions)); | |||
} | |||
var ret = {}; | |||
for (var opt in defaultOptions) { | |||
if (defaultOptions.hasOwnProperty(opt)) { | |||
ret[opt] = defaultOptions[opt].defaultValue; | |||
} | |||
} | |||
return ret; | |||
} | |||
function allOptionsOn () { | |||
'use strict'; | |||
var options = getDefaultOpts(true), | |||
ret = {}; | |||
for (var opt in options) { | |||
if (options.hasOwnProperty(opt)) { | |||
ret[opt] = true; | |||
} | |||
} | |||
return ret; | |||
} |
@ -0,0 +1,379 @@ | |||
/** | |||
* Created by Tivie on 06-01-2015. | |||
*/ | |||
// Private properties | |||
var showdown = {}, | |||
parsers = {}, | |||
extensions = {}, | |||
globalOptions = getDefaultOpts(true), | |||
setFlavor = 'vanilla', | |||
flavor = { | |||
github: { | |||
omitExtraWLInCodeBlocks: true, | |||
simplifiedAutoLink: 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 | |||
}, | |||
original: { | |||
noHeaderId: true, | |||
ghCodeBlocks: false | |||
}, | |||
ghost: { | |||
omitExtraWLInCodeBlocks: true, | |||
parseImgDimensions: true, | |||
simplifiedAutoLink: true, | |||
literalMidWordUnderscores: true, | |||
strikethrough: true, | |||
tables: true, | |||
tablesHeaderId: true, | |||
ghCodeBlocks: true, | |||
tasklists: true, | |||
smoothLivePreview: true, | |||
simpleLineBreaks: true, | |||
requireSpaceBeforeHeadingText: true, | |||
ghMentions: false, | |||
encodeEmails: true | |||
}, | |||
vanilla: getDefaultOpts(true), | |||
allOn: allOptionsOn() | |||
}; | |||
/** | |||
* helper namespace | |||
* @type {{}} | |||
*/ | |||
showdown.helper = {}; | |||
/** | |||
* TODO LEGACY SUPPORT CODE | |||
* @type {{}} | |||
*/ | |||
showdown.extensions = {}; | |||
/** | |||
* Set a global option | |||
* @static | |||
* @param {string} key | |||
* @param {*} value | |||
* @returns {showdown} | |||
*/ | |||
showdown.setOption = function (key, value) { | |||
'use strict'; | |||
globalOptions[key] = value; | |||
return this; | |||
}; | |||
/** | |||
* Get a global option | |||
* @static | |||
* @param {string} key | |||
* @returns {*} | |||
*/ | |||
showdown.getOption = function (key) { | |||
'use strict'; | |||
return globalOptions[key]; | |||
}; | |||
/** | |||
* Get the global options | |||
* @static | |||
* @returns {{}} | |||
*/ | |||
showdown.getOptions = function () { | |||
'use strict'; | |||
return globalOptions; | |||
}; | |||
/** | |||
* Reset global options to the default values | |||
* @static | |||
*/ | |||
showdown.resetOptions = function () { | |||
'use strict'; | |||
globalOptions = getDefaultOpts(true); | |||
}; | |||
/** | |||
* Set the flavor showdown should use as default | |||
* @param {string} name | |||
*/ | |||
showdown.setFlavor = function (name) { | |||
'use strict'; | |||
if (!flavor.hasOwnProperty(name)) { | |||
throw Error(name + ' flavor was not found'); | |||
} | |||
showdown.resetOptions(); | |||
var preset = flavor[name]; | |||
setFlavor = name; | |||
for (var option in preset) { | |||
if (preset.hasOwnProperty(option)) { | |||
globalOptions[option] = preset[option]; | |||
} | |||
} | |||
}; | |||
/** | |||
* Get the currently set flavor | |||
* @returns {string} | |||
*/ | |||
showdown.getFlavor = function () { | |||
'use strict'; | |||
return setFlavor; | |||
}; | |||
/** | |||
* Get the options of a specified flavor. Returns undefined if the flavor was not found | |||
* @param {string} name Name of the flavor | |||
* @returns {{}|undefined} | |||
*/ | |||
showdown.getFlavorOptions = function (name) { | |||
'use strict'; | |||
if (flavor.hasOwnProperty(name)) { | |||
return flavor[name]; | |||
} | |||
}; | |||
/** | |||
* Get the default options | |||
* @static | |||
* @param {boolean} [simple=true] | |||
* @returns {{}} | |||
*/ | |||
showdown.getDefaultOptions = function (simple) { | |||
'use strict'; | |||
return getDefaultOpts(simple); | |||
}; | |||
/** | |||
* Get or set a subParser | |||
* | |||
* subParser(name) - Get a registered subParser | |||
* subParser(name, func) - Register a subParser | |||
* @static | |||
* @param {string} name | |||
* @param {function} [func] | |||
* @returns {*} | |||
*/ | |||
showdown.subParser = function (name, func) { | |||
'use strict'; | |||
if (showdown.helper.isString(name)) { | |||
if (typeof func !== 'undefined') { | |||
parsers[name] = func; | |||
} else { | |||
if (parsers.hasOwnProperty(name)) { | |||
return parsers[name]; | |||
} else { | |||
throw Error('SubParser named ' + name + ' not registered!'); | |||
} | |||
} | |||
} else { | |||
throw Error('showdown.subParser function first argument must be a string (the name of the subparser)'); | |||
} | |||
}; | |||
/** | |||
* Gets or registers an extension | |||
* @static | |||
* @param {string} name | |||
* @param {object|function=} ext | |||
* @returns {*} | |||
*/ | |||
showdown.extension = function (name, ext) { | |||
'use strict'; | |||
if (!showdown.helper.isString(name)) { | |||
throw Error('Extension \'name\' must be a string'); | |||
} | |||
name = showdown.helper.stdExtName(name); | |||
// Getter | |||
if (showdown.helper.isUndefined(ext)) { | |||
if (!extensions.hasOwnProperty(name)) { | |||
throw Error('Extension named ' + name + ' is not registered!'); | |||
} | |||
return extensions[name]; | |||
// Setter | |||
} else { | |||
// Expand extension if it's wrapped in a function | |||
if (typeof ext === 'function') { | |||
ext = ext(); | |||
} | |||
// Ensure extension is an array | |||
if (!showdown.helper.isArray(ext)) { | |||
ext = [ext]; | |||
} | |||
var validExtension = validate(ext, name); | |||
if (validExtension.valid) { | |||
extensions[name] = ext; | |||
} else { | |||
throw Error(validExtension.error); | |||
} | |||
} | |||
}; | |||
/** | |||
* Gets all extensions registered | |||
* @returns {{}} | |||
*/ | |||
showdown.getAllExtensions = function () { | |||
'use strict'; | |||
return extensions; | |||
}; | |||
/** | |||
* Remove an extension | |||
* @param {string} name | |||
*/ | |||
showdown.removeExtension = function (name) { | |||
'use strict'; | |||
delete extensions[name]; | |||
}; | |||
/** | |||
* Removes all extensions | |||
*/ | |||
showdown.resetExtensions = function () { | |||
'use strict'; | |||
extensions = {}; | |||
}; | |||
/** | |||
* Validate extension | |||
* @param {array} extension | |||
* @param {string} name | |||
* @returns {{valid: boolean, error: string}} | |||
*/ | |||
function validate (extension, name) { | |||
'use strict'; | |||
var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension', | |||
ret = { | |||
valid: true, | |||
error: '' | |||
}; | |||
if (!showdown.helper.isArray(extension)) { | |||
extension = [extension]; | |||
} | |||
for (var i = 0; i < extension.length; ++i) { | |||
var baseMsg = errMsg + ' sub-extension ' + i + ': ', | |||
ext = extension[i]; | |||
if (typeof ext !== 'object') { | |||
ret.valid = false; | |||
ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given'; | |||
return ret; | |||
} | |||
if (!showdown.helper.isString(ext.type)) { | |||
ret.valid = false; | |||
ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given'; | |||
return ret; | |||
} | |||
var type = ext.type = ext.type.toLowerCase(); | |||
// normalize extension type | |||
if (type === 'language') { | |||
type = ext.type = 'lang'; | |||
} | |||
if (type === 'html') { | |||
type = ext.type = 'output'; | |||
} | |||
if (type !== 'lang' && type !== 'output' && type !== 'listener') { | |||
ret.valid = false; | |||
ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"'; | |||
return ret; | |||
} | |||
if (type === 'listener') { | |||
if (showdown.helper.isUndefined(ext.listeners)) { | |||
ret.valid = false; | |||
ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"'; | |||
return ret; | |||
} | |||
} else { | |||
if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) { | |||
ret.valid = false; | |||
ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method'; | |||
return ret; | |||
} | |||
} | |||
if (ext.listeners) { | |||
if (typeof ext.listeners !== 'object') { | |||
ret.valid = false; | |||
ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given'; | |||
return ret; | |||
} | |||
for (var ln in ext.listeners) { | |||
if (ext.listeners.hasOwnProperty(ln)) { | |||
if (typeof ext.listeners[ln] !== 'function') { | |||
ret.valid = false; | |||
ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln + | |||
' must be a function but ' + typeof ext.listeners[ln] + ' given'; | |||
return ret; | |||
} | |||
} | |||
} | |||
} | |||
if (ext.filter) { | |||
if (typeof ext.filter !== 'function') { | |||
ret.valid = false; | |||
ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given'; | |||
return ret; | |||
} | |||
} else if (ext.regex) { | |||
if (showdown.helper.isString(ext.regex)) { | |||
ext.regex = new RegExp(ext.regex, 'g'); | |||
} | |||
if (!(ext.regex instanceof RegExp)) { | |||
ret.valid = false; | |||
ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given'; | |||
return ret; | |||
} | |||
if (showdown.helper.isUndefined(ext.replace)) { | |||
ret.valid = false; | |||
ret.error = baseMsg + '"regex" extensions must implement a replace string or function'; | |||
return ret; | |||
} | |||
} | |||
} | |||
return ret; | |||
} | |||
/** | |||
* Validate extension | |||
* @param {object} ext | |||
* @returns {boolean} | |||
*/ | |||
showdown.validateExtension = function (ext) { | |||
'use strict'; | |||
var validateExtension = validate(ext, null); | |||
if (!validateExtension.valid) { | |||
console.warn(validateExtension.error); | |||
return false; | |||
} | |||
return true; | |||
}; |
@ -0,0 +1,32 @@ | |||
/** | |||
* These are all the transformations that form block-level | |||
* tags like paragraphs, headers, and list items. | |||
*/ | |||
showdown.subParser('makehtml.blockGamut', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals).getText(); | |||
// we parse blockquotes first so that we can have headings and hrs | |||
// inside blockquotes | |||
text = showdown.subParser('makehtml.blockQuotes')(text, options, globals); | |||
text = showdown.subParser('makehtml.headers')(text, options, globals); | |||
// Do Horizontal Rules: | |||
text = showdown.subParser('makehtml.horizontalRule')(text, options, globals); | |||
text = showdown.subParser('makehtml.lists')(text, options, globals); | |||
text = showdown.subParser('makehtml.codeBlocks')(text, options, globals); | |||
text = showdown.subParser('makehtml.tables')(text, options, globals); | |||
// We already ran _HashHTMLBlocks() before, in Markdown(), but that | |||
// was to escape raw HTML in the original Markdown source. This time, | |||
// we're escaping the markup we've just created, so that we don't wrap | |||
// <p> tags around block-level tags. | |||
text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals); | |||
text = showdown.subParser('makehtml.paragraphs')(text, options, globals); | |||
text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,42 @@ | |||
showdown.subParser('makehtml.blockQuotes', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals).getText(); | |||
// add a couple extra lines after the text and endtext mark | |||
text = text + '\n\n'; | |||
var rgx = /(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm; | |||
if (options.splitAdjacentBlockquotes) { | |||
rgx = /^ {0,3}>[\s\S]*?(?:\n\n)/gm; | |||
} | |||
text = text.replace(rgx, function (bq) { | |||
// attacklab: hack around Konqueror 3.5.4 bug: | |||
// "----------bug".replace(/^-/g,"") == "bug" | |||
bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting | |||
// attacklab: clean up hack | |||
bq = bq.replace(/¨0/g, ''); | |||
bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines | |||
bq = showdown.subParser('makehtml.githubCodeBlocks')(bq, options, globals); | |||
bq = showdown.subParser('makehtml.blockGamut')(bq, options, globals); // recurse | |||
bq = bq.replace(/(^|\n)/g, '$1 '); | |||
// These leading spaces screw with <pre> content, so we need to fix that: | |||
bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) { | |||
var pre = m1; | |||
// attacklab: hack around Konqueror 3.5.4 bug: | |||
pre = pre.replace(/^ /mg, '¨0'); | |||
pre = pre.replace(/¨0/g, ''); | |||
return pre; | |||
}); | |||
return showdown.subParser('makehtml.hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals); | |||
}); | |||
text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,38 @@ | |||
/** | |||
* Process Markdown `<pre><code>` blocks. | |||
*/ | |||
showdown.subParser('makehtml.codeBlocks', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals).getText(); | |||
// sentinel workarounds for lack of \A and \Z, safari\khtml bug | |||
text += '¨0'; | |||
var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=¨0))/g; | |||
text = text.replace(pattern, function (wholeMatch, m1, m2) { | |||
var codeblock = m1, | |||
nextChar = m2, | |||
end = '\n'; | |||
codeblock = showdown.subParser('makehtml.outdent')(codeblock, options, globals); | |||
codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals); | |||
codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals); | |||
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines | |||
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines | |||
if (options.omitExtraWLInCodeBlocks) { | |||
end = ''; | |||
} | |||
codeblock = '<pre><code>' + codeblock + end + '</code></pre>'; | |||
return showdown.subParser('makehtml.hashBlock')(codeblock, options, globals) + nextChar; | |||
}); | |||
// strip sentinel | |||
text = text.replace(/¨0/, ''); | |||
text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,48 @@ | |||
/** | |||
* | |||
* * Backtick quotes are used for <code></code> spans. | |||
* | |||
* * You can use multiple backticks as the delimiters if you want to | |||
* include literal backticks in the code span. So, this input: | |||
* | |||
* Just type ``foo `bar` baz`` at the prompt. | |||
* | |||
* Will translate to: | |||
* | |||
* <p>Just type <code>foo `bar` baz</code> at the prompt.</p> | |||
* | |||
* There's no arbitrary limit to the number of backticks you | |||
* can use as delimters. If you need three consecutive backticks | |||
* in your code, use four for delimiters, etc. | |||
* | |||
* * You can use spaces to get literal backticks at the edges: | |||
* | |||
* ... type `` `bar` `` ... | |||
* | |||
* Turns to: | |||
* | |||
* ... type <code>`bar`</code> ... | |||
*/ | |||
showdown.subParser('makehtml.codeSpans', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals).getText(); | |||
if (typeof(text) === 'undefined') { | |||
text = ''; | |||
} | |||
text = text.replace(/(^|[^\])(`+)([^\r]*?[^`])\2(?!`)/gm, | |||
function (wholeMatch, m1, m2, m3) { | |||
var c = m3; | |||
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace | |||
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace | |||
c = showdown.subParser('makehtml.encodeCode')(c, options, globals); | |||
c = m1 + '<code>' + c + '</code>'; | |||
c = showdown.subParser('makehtml.hashHTMLSpans')(c, options, globals); | |||
return c; | |||
} | |||
); | |||
text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,62 @@ | |||
/** | |||
* Create a full HTML document from the processed markdown | |||
*/ | |||
showdown.subParser('makehtml.completeHTMLDocument', function (text, options, globals) { | |||
'use strict'; | |||
if (!options.completeHTMLDocument) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals).getText(); | |||
var doctype = 'html', | |||
doctypeParsed = '<!DOCTYPE HTML>\n', | |||
title = '', | |||
charset = '<meta charset="utf-8">\n', | |||
lang = '', | |||
metadata = ''; | |||
if (typeof globals.metadata.parsed.doctype !== 'undefined') { | |||
doctypeParsed = '<!DOCTYPE ' + globals.metadata.parsed.doctype + '>\n'; | |||
doctype = globals.metadata.parsed.doctype.toString().toLowerCase(); | |||
if (doctype === 'html' || doctype === 'html5') { | |||
charset = '<meta charset="utf-8">'; | |||
} | |||
} | |||
for (var meta in globals.metadata.parsed) { | |||
if (globals.metadata.parsed.hasOwnProperty(meta)) { | |||
switch (meta.toLowerCase()) { | |||
case 'doctype': | |||
break; | |||
case 'title': | |||
title = '<title>' + globals.metadata.parsed.title + '</title>\n'; | |||
break; | |||
case 'charset': | |||
if (doctype === 'html' || doctype === 'html5') { | |||
charset = '<meta charset="' + globals.metadata.parsed.charset + '">\n'; | |||
} else { | |||
charset = '<meta name="charset" content="' + globals.metadata.parsed.charset + '">\n'; | |||
} | |||
break; | |||
case 'language': | |||
case 'lang': | |||
lang = ' lang="' + globals.metadata.parsed[meta] + '"'; | |||
metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n'; | |||
break; | |||
default: | |||
metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n'; | |||
} | |||
} | |||
} | |||
text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>'; | |||
text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,33 @@ | |||
/** | |||
* Convert all tabs to spaces | |||
*/ | |||
showdown.subParser('makehtml.detab', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.detab.before', text, options, globals).getText(); | |||
// expand first n-1 tabs | |||
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width | |||
// replace the nth with two sentinels | |||
text = text.replace(/\t/g, '¨A¨B'); | |||
// use the sentinel to anchor our regex so it doesn't explode | |||
text = text.replace(/¨B(.+?)¨A/g, function (wholeMatch, m1) { | |||
var leadingText = m1, | |||
numSpaces = 4 - leadingText.length % 4; // g_tab_width | |||
// there *must* be a better way to do this: | |||
for (var i = 0; i < numSpaces; i++) { | |||
leadingText += ' '; | |||
} | |||
return leadingText; | |||
}); | |||
// clean up sentinels | |||
text = text.replace(/¨A/g, ' '); // g_tab_width | |||
text = text.replace(/¨B/g, ''); | |||
text = globals.converter._dispatch('makehtml.detab.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,11 @@ | |||
showdown.subParser('makehtml.ellipsis', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals).getText(); | |||
text = text.replace(/\.\.\./g, '…'); | |||
text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,27 @@ | |||
/** | |||
* Turn emoji codes into emojis | |||
* | |||
* List of supported emojis: https://github.com/showdownjs/showdown/wiki/Emojis | |||
*/ | |||
showdown.subParser('makehtml.emoji', function (text, options, globals) { | |||
'use strict'; | |||
if (!options.emoji) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals).getText(); | |||
var emojiRgx = /:([\S]+?):/g; | |||
text = text.replace(emojiRgx, function (wm, emojiCode) { | |||
if (showdown.helper.emojis.hasOwnProperty(emojiCode)) { | |||
return showdown.helper.emojis[emojiCode]; | |||
} | |||
return wm; | |||
}); | |||
text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,23 @@ | |||
/** | |||
* Smart processing for ampersands and angle brackets that need to be encoded. | |||
*/ | |||
showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals).getText(); | |||
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: | |||
// http://bumppo.net/projects/amputator/ | |||
text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&'); | |||
// Encode naked <'s | |||
text = text.replace(/<(?![a-z\/?$!])/gi, '<'); | |||
// Encode < | |||
text = text.replace(/</g, '<'); | |||
// Encode > | |||
text = text.replace(/>/g, '>'); | |||
text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,21 @@ | |||
/** | |||
* Returns the string, with after processing the following backslash escape sequences. | |||
* | |||
* attacklab: The polite way to do this is with the new escapeCharacters() function: | |||
* | |||
* text = escapeCharacters(text,"\",true); | |||
* text = escapeCharacters(text,"`*_{}[]()>#+-.!",true); | |||
* | |||
* ...but we're sidestepping its use of the (slow) RegExp constructor | |||
* as an optimization for Firefox. This function gets called a LOT. | |||
*/ | |||
showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals).getText(); | |||
text = text.replace(/\(\)/g, showdown.helper.escapeCharactersCallback); | |||
text = text.replace(/\([`*_{} |
|||
text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,23 @@ | |||
/** | |||
* Encode/escape certain characters inside Markdown code runs. | |||
* The point is that in code, these characters are literals, | |||
* and lose their special Markdown meanings. | |||
*/ | |||
showdown.subParser('makehtml.encodeCode', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals).getText(); | |||
// Encode all ampersands; HTML entities are not | |||
// entities within a Markdown code span. | |||
text = text | |||
.replace(/&/g, '&') | |||
// Do the angle bracket song and dance: | |||
.replace(/</g, '<') | |||
.replace(/>/g, '>') | |||
// Now, escape characters that are magic in Markdown: | |||
.replace(/([*_{} |
|||
text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,26 @@ | |||
/** | |||
* Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they | |||
* don't conflict with their use in Markdown for code, italics and strong. | |||
*/ | |||
showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals).getText(); | |||
// Build a regex to find HTML tags. | |||
var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi, | |||
comments = /<!(--(?:(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>/gi; | |||
text = text.replace(tags, function (wholeMatch) { | |||
return wholeMatch | |||
.replace(/(.)<\/?code>(?=.)/g, '$1`') | |||
.replace(/([\`*_~=|])/g, showdown.helper.escapeCharactersCallback); | |||
}); | |||
text = text.replace(comments, function (wholeMatch) { | |||
return wholeMatch | |||
.replace(/([\`*_~=|])/g, showdown.helper.escapeCharactersCallback); | |||
}); | |||
text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,46 @@ | |||
/** | |||
* Handle github codeblocks prior to running HashHTML so that | |||
* HTML contained within the codeblock gets escaped properly | |||
* Example: | |||
* ```ruby | |||
* def hello_world(x) | |||
* puts "Hello, #{x}" | |||
* end | |||
* ``` | |||
*/ | |||
showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals) { | |||
'use strict'; | |||
// early exit if option is not enabled | |||
if (!options.ghCodeBlocks) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals).getText(); | |||
text += '¨0'; | |||
text = text.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g, function (wholeMatch, delim, language, codeblock) { | |||
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n'; | |||
// First parse the github code block | |||
codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals); | |||
codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals); | |||
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines | |||
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace | |||
codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>'; | |||
codeblock = showdown.subParser('makehtml.hashBlock')(codeblock, options, globals); | |||
// Since GHCodeblocks can be false positives, we need to | |||
// store the primitive text and the parsed text in a global var, | |||
// and then return a token | |||
return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n'; | |||
}); | |||
// attacklab: strip sentinel | |||
text = text.replace(/¨0/, ''); | |||
return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals).getText(); | |||
}); |
@ -0,0 +1,8 @@ | |||
showdown.subParser('makehtml.hashBlock', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals).getText(); | |||
text = text.replace(/(^\n+|\n+$)/g, ''); | |||
text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n'; | |||
text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,18 @@ | |||
/** | |||
* Hash and escape <code> elements that should not be parsed as markdown | |||
*/ | |||
showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals).getText(); | |||
var repFunc = function (wholeMatch, match, left, right) { | |||
var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right; | |||
return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C'; | |||
}; | |||
// Hash naked <code> | |||
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\b[^>]*>', '</code>', 'gim'); | |||
text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,19 @@ | |||
showdown.subParser('makehtml.hashElement', function (text, options, globals) { | |||
'use strict'; | |||
return function (wholeMatch, m1) { | |||
var blockText = m1; | |||
// Undo double lines | |||
blockText = blockText.replace(/\n\n/g, '\n'); | |||
blockText = blockText.replace(/^\n/, ''); | |||
// strip trailing blank lines | |||
blockText = blockText.replace(/\n+$/g, ''); | |||
// Replace the element text with a marker ("¨KxK" where x is its key) | |||
blockText = '\n\n¨K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n'; | |||
return blockText; | |||
}; | |||
}); |
@ -0,0 +1,98 @@ | |||
showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals).getText(); | |||
var blockTags = [ | |||
'pre', | |||
'div', | |||
'h1', | |||
'h2', | |||
'h3', | |||
'h4', | |||
'h5', | |||
'h6', | |||
'blockquote', | |||
'table', | |||
'dl', | |||
'ol', | |||
'ul', | |||
'script', | |||
'noscript', | |||
'form', | |||
'fieldset', | |||
'iframe', | |||
'math', | |||
'style', | |||
'section', | |||
'header', | |||
'footer', | |||
'nav', | |||
'article', | |||
'aside', | |||
'address', | |||
'audio', | |||
'canvas', | |||
'figure', | |||
'hgroup', | |||
'output', | |||
'video', | |||
'p' | |||
], | |||
repFunc = function (wholeMatch, match, left, right) { | |||
var txt = wholeMatch; | |||
// check if this html element is marked as markdown | |||
// if so, it's contents should be parsed as markdown | |||
if (left.search(/\bmarkdown\b/) !== -1) { | |||
txt = left + globals.converter.makeHtml(match) + right; | |||
} | |||
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n'; | |||
}; | |||
if (options.backslashEscapesHTMLTags) { | |||
// encode backslash escaped HTML tags | |||
text = text.replace(/\<(\/?[^>]+?)>/g, function (wm, inside) { | |||
return '<' + inside + '>'; | |||
}); | |||
} | |||
// hash HTML Blocks | |||
for (var i = 0; i < blockTags.length; ++i) { | |||
var opTagPos, | |||
rgx1 = new RegExp('^ {0,3}(<' + blockTags[i] + '\b[^>]*>)', 'im'), | |||
patLeft = '<' + blockTags[i] + '\b[^>]*>', | |||
patRight = '</' + blockTags[i] + '>'; | |||
// 1. Look for the first position of the first opening HTML tag in the text | |||
while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) { | |||
// if the HTML tag is \ escaped, we need to escape it and break | |||
//2. Split the text in that position | |||
var subTexts = showdown.helper.splitAtIndex(text, opTagPos), | |||
//3. Match recursively | |||
newSubText1 = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im'); | |||
// prevent an infinite loop | |||
if (newSubText1 === subTexts[1]) { | |||
break; | |||
} | |||
text = subTexts[0].concat(newSubText1); | |||
} | |||
} | |||
// HR SPECIAL CASE | |||
text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, | |||
showdown.subParser('makehtml.hashElement')(text, options, globals)); | |||
// Special case for standalone HTML comments | |||
text = showdown.helper.replaceRecursiveRegExp(text, function (txt) { | |||
return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n'; | |||
}, '^ {0,3}<!--', '-->', 'gm'); | |||
// PHP and ASP-style processor instructions (<?...?> and <%...%>) | |||
text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, | |||
showdown.subParser('makehtml.hashElement')(text, options, globals)); | |||
text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,58 @@ | |||
/** | |||
* Hash span elements that should not be parsed as markdown | |||
*/ | |||
showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals).getText(); | |||
// Hash Self Closing tags | |||
text = text.replace(/<[^>]+?\/>/gi, function (wm) { | |||
return showdown.helper._hashHTMLSpan(wm, globals); | |||
}); | |||
// Hash tags without properties | |||
text = text.replace(/<([^>]+?)>[\s\S]*?<\/\1>/g, function (wm) { | |||
return showdown.helper._hashHTMLSpan(wm, globals); | |||
}); | |||
// Hash tags with properties | |||
text = text.replace(/<([^>]+?)\s[^>]+?>[\s\S]*?<\/\1>/g, function (wm) { | |||
return showdown.helper._hashHTMLSpan(wm, globals); | |||
}); | |||
// Hash self closing tags without /> | |||
text = text.replace(/<[^>]+?>/gi, function (wm) { | |||
return showdown.helper._hashHTMLSpan(wm, globals); | |||
}); | |||
text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* Unhash HTML spans | |||
*/ | |||
showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals).getText(); | |||
for (var i = 0; i < globals.gHtmlSpans.length; ++i) { | |||
var repText = globals.gHtmlSpans[i], | |||
// limiter to prevent infinite loop (assume 10 as limit for recurse) | |||
limit = 0; | |||
while (/¨C(\d+)C/.test(repText)) { | |||
var num = RegExp.$1; | |||
repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]); | |||
if (limit === 10) { | |||
console.error('maximum nesting of 10 spans reached!!!'); | |||
break; | |||
} | |||
++limit; | |||
} | |||
text = text.replace('¨C' + i + 'C', repText); | |||
} | |||
text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,19 @@ | |||
/** | |||
* Hash and escape <pre><code> elements that should not be parsed as markdown | |||
*/ | |||
showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals).getText(); | |||
var repFunc = function (wholeMatch, match, left, right) { | |||
// encode html entities | |||
var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right; | |||
return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n'; | |||
}; | |||
// Hash <pre><code> | |||
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\b[^>]*>\s*<code\b[^>]*>', '^ {0,3}</code>\s*</pre>', 'gim'); | |||
text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,126 @@ | |||
showdown.subParser('makehtml.headers', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.headers.before', text, options, globals).getText(); | |||
var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart), | |||
// Set text-style headers: | |||
// Header 1 | |||
// ======== | |||
// | |||
// Header 2 | |||
// -------- | |||
// | |||
setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm, | |||
setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm; | |||
text = text.replace(setextRegexH1, function (wholeMatch, m1) { | |||
var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals), | |||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"', | |||
hLevel = headerLevelStart, | |||
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>'; | |||
return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals); | |||
}); | |||
text = text.replace(setextRegexH2, function (matchFound, m1) { | |||
var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals), | |||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"', | |||
hLevel = headerLevelStart + 1, | |||
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>'; | |||
return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals); | |||
}); | |||
// atx-style headers: | |||
// # Header 1 | |||
// ## Header 2 | |||
// ## Header 2 with closing hashes ## | |||
// ... | |||
// ###### Header 6 | |||
// | |||
var atxStyle = (options.requireSpaceBeforeHeadingText) ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm; | |||
text = text.replace(atxStyle, function (wholeMatch, m1, m2) { | |||
var hText = m2; | |||
if (options.customizedHeaderId) { | |||
hText = m2.replace(/\s?\{([^{]+?)}\s*$/, ''); | |||
} | |||
var span = showdown.subParser('makehtml.spanGamut')(hText, options, globals), | |||
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"', | |||
hLevel = headerLevelStart - 1 + m1.length, | |||
header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>'; | |||
return showdown.subParser('makehtml.hashBlock')(header, options, globals); | |||
}); | |||
function headerId (m) { | |||
var title, | |||
prefix; | |||
// It is separate from other options to allow combining prefix and customized | |||
if (options.customizedHeaderId) { | |||
var match = m.match(/\{([^{]+?)}\s*$/); | |||
if (match && match[1]) { | |||
m = match[1]; | |||
} | |||
} | |||
title = m; | |||
// Prefix id to prevent causing inadvertent pre-existing style matches. | |||
if (showdown.helper.isString(options.prefixHeaderId)) { | |||
prefix = options.prefixHeaderId; | |||
} else if (options.prefixHeaderId === true) { | |||
prefix = 'section-'; | |||
} else { | |||
prefix = ''; | |||
} | |||
if (!options.rawPrefixHeaderId) { | |||
title = prefix + title; | |||
} | |||
if (options.ghCompatibleHeaderId) { | |||
title = title | |||
.replace(/ /g, '-') | |||
// replace previously escaped chars (&, ¨ and $) | |||
.replace(/&/g, '') | |||
.replace(/¨T/g, '') | |||
.replace(/¨D/g, '') | |||
// replace rest of the chars (&~$ are repeated as they might have been escaped) | |||
// borrowed from github's redcarpet (some they should produce similar results) | |||
.replace(/[&+$,\/:;=?@"#{}|^¨~ |
|||
.toLowerCase(); | |||
} else if (options.rawHeaderId) { | |||
title = title | |||
.replace(/ /g, '-') | |||
// replace previously escaped chars (&, ¨ and $) | |||
.replace(/&/g, '&') | |||
.replace(/¨T/g, '¨') | |||
.replace(/¨D/g, '$') | |||
// replace " and ' | |||
.replace(/["']/g, '-') | |||
.toLowerCase(); | |||
} else { | |||
title = title | |||
.replace(/[^\w]/g, '') | |||
.toLowerCase(); | |||
} | |||
if (options.rawPrefixHeaderId) { | |||
title = prefix + title; | |||
} | |||
if (globals.hashLinkCounts[title]) { | |||
title = title + '-' + (globals.hashLinkCounts[title]++); | |||
} else { | |||
globals.hashLinkCounts[title] = 1; | |||
} | |||
return title; | |||
} | |||
text = globals.converter._dispatch('makehtml.headers.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,18 @@ | |||
/** | |||
* Turn Markdown horizontal rule shortcuts into <hr /> tags. | |||
* | |||
* Any 3 or more unindented consecutive hyphens, asterisks or underscores with or without a space beetween them | |||
* in a single line is considered a horizontal rule | |||
*/ | |||
showdown.subParser('makehtml.horizontalRule', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals).getText(); | |||
var key = showdown.subParser('makehtml.hashBlock')('<hr />', options, globals); | |||
text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key); | |||
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key); | |||
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key); | |||
text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,104 @@ | |||
/** | |||
* Turn Markdown image shortcuts into <img> tags. | |||
*/ | |||
showdown.subParser('makehtml.images', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.images.before', text, options, globals).getText(); | |||
var inlineRegExp = /! |
|||
crazyRegExp = /! |
|||
base64RegExp = /! |
|||
referenceRegExp = /! |
|||
refShortcutRegExp = /! |
|||
function writeImageTagBase64 (wholeMatch, altText, linkId, url, width, height, m5, title) { | |||
url = url.replace(/\s/g, ''); | |||
return writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title); | |||
} | |||
function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) { | |||
var gUrls = globals.gUrls, | |||
gTitles = globals.gTitles, | |||
gDims = globals.gDimensions; | |||
linkId = linkId.toLowerCase(); | |||
if (!title) { | |||
title = ''; | |||
} | |||
// Special case for explicit empty url | |||
if (wholeMatch.search(/ |
|||
url = ''; | |||
} else if (url === '' || url === null) { | |||
if (linkId === '' || linkId === null) { | |||
// lower-case and turn embedded newlines into spaces | |||
linkId = altText.toLowerCase().replace(/ ?\n/g, ' '); | |||
} | |||
url = '#' + linkId; | |||
if (!showdown.helper.isUndefined(gUrls[linkId])) { | |||
url = gUrls[linkId]; | |||
if (!showdown.helper.isUndefined(gTitles[linkId])) { | |||
title = gTitles[linkId]; | |||
} | |||
if (!showdown.helper.isUndefined(gDims[linkId])) { | |||
width = gDims[linkId].width; | |||
height = gDims[linkId].height; | |||
} | |||
} else { | |||
return wholeMatch; | |||
} | |||
} | |||
altText = altText | |||
.replace(/"/g, '"') | |||
//altText = showdown.helper.escapeCharacters(altText, '*_', false); | |||
.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
//url = showdown.helper.escapeCharacters(url, '*_', false); | |||
url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
var result = '<img src="' + url + '" alt="' + altText + '"'; | |||
if (title && showdown.helper.isString(title)) { | |||
title = title | |||
.replace(/"/g, '"') | |||
//title = showdown.helper.escapeCharacters(title, '*_', false); | |||
.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
result += ' title="' + title + '"'; | |||
} | |||
if (width && height) { | |||
width = (width === '*') ? 'auto' : width; | |||
height = (height === '*') ? 'auto' : height; | |||
result += ' width="' + width + '"'; | |||
result += ' height="' + height + '"'; | |||
} | |||
result += ' />'; | |||
return result; | |||
} | |||
// First, handle reference-style labeled images: ![alt text][id] | |||
text = text.replace(referenceRegExp, writeImageTag); | |||
// Next, handle inline images:  | |||
// base64 encoded images | |||
text = text.replace(base64RegExp, writeImageTagBase64); | |||
// cases with crazy urls like ./image/cat1).png | |||
text = text.replace(crazyRegExp, writeImageTag); | |||
// normal cases | |||
text = text.replace(inlineRegExp, writeImageTag); | |||
// handle reference-style shortcuts: ![img text] | |||
text = text.replace(refShortcutRegExp, writeImageTag); | |||
text = globals.converter._dispatch('makehtml.images.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,66 @@ | |||
showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals).getText(); | |||
// it's faster to have 3 separate regexes for each case than have just one | |||
// because of backtracing, in some cases, it could lead to an exponential effect | |||
// called "catastrophic backtrace". Ominous! | |||
function parseInside (txt, left, right) { | |||
return left + txt + right; | |||
} | |||
// Parse underscores | |||
if (options.literalMidWordUnderscores) { | |||
text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) { | |||
return parseInside (txt, '<strong><em>', '</em></strong>'); | |||
}); | |||
text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) { | |||
return parseInside (txt, '<strong>', '</strong>'); | |||
}); | |||
text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) { | |||
return parseInside (txt, '<em>', '</em>'); | |||
}); | |||
} else { | |||
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm; | |||
}); | |||
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm; | |||
}); | |||
text = text.replace(/_([^\s_][\s\S]*?)_/g, function (wm, m) { | |||
// !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it) | |||
return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm; | |||
}); | |||
} | |||
// Now parse asterisks | |||
/* | |||
if (options.literalMidWordAsterisks) { | |||
text = text.replace(/([^*]|^)\B\*\*\*(\S[\s\S]+?)\*\*\*\B(?!\*)/g, function (wm, lead, txt) { | |||
return parseInside (txt, lead + '<strong><em>', '</em></strong>'); | |||
}); | |||
text = text.replace(/([^*]|^)\B\*\*(\S[\s\S]+?)\*\*\B(?!\*)/g, function (wm, lead, txt) { | |||
return parseInside (txt, lead + '<strong>', '</strong>'); | |||
}); | |||
text = text.replace(/([^*]|^)\B\*(\S[\s\S]+?)\*\B(?!\*)/g, function (wm, lead, txt) { | |||
return parseInside (txt, lead + '<em>', '</em>'); | |||
}); | |||
} else { | |||
*/ | |||
text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm; | |||
}); | |||
text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm; | |||
}); | |||
text = text.replace(/\*([^\s*][\s\S]*?)\*/g, function (wm, m) { | |||
// !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it) | |||
return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm; | |||
}); | |||
//} | |||
text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,419 @@ | |||
//// | |||
// makehtml/links.js | |||
// Copyright (c) 2018 ShowdownJS | |||
// | |||
// Transforms MD links into `<a>` html anchors | |||
// | |||
// A link contains link text (the visible text), a link destination (the URI that is the link destination), and | |||
// optionally a link title. There are two basic kinds of links in Markdown. | |||
// In inline links the destination and title are given immediately after the link text. | |||
// In reference links the destination and title are defined elsewhere in the document. | |||
// | |||
// ***Author:*** | |||
// - Estevão Soares dos Santos (Tivie) <https://github.com/tivie> | |||
//// | |||
(function () { | |||
/** | |||
* Helper function: Wrapper function to pass as second replace parameter | |||
* | |||
* @param {RegExp} rgx | |||
* @param {string} evtRootName | |||
* @param {{}} options | |||
* @param {{}} globals | |||
* @returns {Function} | |||
*/ | |||
function replaceAnchorTag (rgx, evtRootName, options, globals, emptyCase) { | |||
emptyCase = !!emptyCase; | |||
return function (wholeMatch, text, id, url, m5, m6, title) { | |||
// bail we we find 2 newlines somewhere | |||
if (/\n\n/.test(wholeMatch)) { | |||
return wholeMatch; | |||
} | |||
var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, text, id, url, title, options, globals); | |||
return writeAnchorTag(evt, options, globals, emptyCase); | |||
}; | |||
} | |||
/** | |||
* TODO Normalize this | |||
* Helper function: Create a capture event | |||
* @param {RegExp} rgx | |||
* @param {String} evtName Event name | |||
* @param {String} wholeMatch | |||
* @param {String} text | |||
* @param {String} id | |||
* @param {String} url | |||
* @param {String} title | |||
* @param {{}} options | |||
* @param {{}} globals | |||
* @returns {showdown.helper.Event|*} | |||
*/ | |||
function createEvent (rgx, evtName, wholeMatch, text, id, url, title, options, globals) { | |||
return globals.converter._dispatch(evtName, wholeMatch, options, globals, { | |||
regexp: rgx, | |||
matches: { | |||
wholeMatch: wholeMatch, | |||
text: text, | |||
id: id, | |||
url: url, | |||
title: title | |||
} | |||
}); | |||
} | |||
/** | |||
* Helper Function: Normalize and write an anchor tag based on passed parameters | |||
* @param evt | |||
* @param options | |||
* @param globals | |||
* @param {boolean} emptyCase | |||
* @returns {string} | |||
*/ | |||
function writeAnchorTag (evt, options, globals, emptyCase) { | |||
var wholeMatch = evt.getMatches().wholeMatch; | |||
var text = evt.getMatches().text; | |||
var id = evt.getMatches().id; | |||
var url = evt.getMatches().url; | |||
var title = evt.getMatches().title; | |||
var target = ''; | |||
if (!title) { | |||
title = ''; | |||
} | |||
id = (id) ? id.toLowerCase() : ''; | |||
if (emptyCase) { | |||
url = ''; | |||
} else if (!url) { | |||
if (!id) { | |||
// lower-case and turn embedded newlines into spaces | |||
id = text.toLowerCase().replace(/ ?\n/g, ' '); | |||
} | |||
url = '#' + id; | |||
if (!showdown.helper.isUndefined(globals.gUrls[id])) { | |||
url = globals.gUrls[id]; | |||
if (!showdown.helper.isUndefined(globals.gTitles[id])) { | |||
title = globals.gTitles[id]; | |||
} | |||
} else { | |||
return wholeMatch; | |||
} | |||
} | |||
//url = showdown.helper.escapeCharacters(url, '*_:~', false); // replaced line to improve performance | |||
url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
if (title !== '' && title !== null) { | |||
title = title.replace(/"/g, '"'); | |||
//title = showdown.helper.escapeCharacters(title, '*_', false); // replaced line to improve performance | |||
title = title.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
title = ' title="' + title + '"'; | |||
} | |||
// optionLinksInNewWindow only applies | |||
// to external links. Hash links (#) open in same page | |||
if (options.openLinksInNewWindow && !/^#/.test(url)) { | |||
// escaped _ | |||
target = ' rel="noopener noreferrer" target="¨E95Eblank"'; | |||
} | |||
// Text can be a markdown element, so we run through the appropriate parsers | |||
text = showdown.subParser('makehtml.codeSpans')(text, options, globals); | |||
text = showdown.subParser('makehtml.emoji')(text, options, globals); | |||
text = showdown.subParser('makehtml.underline')(text, options, globals); | |||
text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals); | |||
text = showdown.subParser('makehtml.strikethrough')(text, options, globals); | |||
text = showdown.subParser('makehtml.ellipsis')(text, options, globals); | |||
text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals); | |||
//evt = createEvent(rgx, evtRootName + '.captureEnd', wholeMatch, text, id, url, title, options, globals); | |||
var result = '<a href="' + url + '"' + title + target + '>' + text + '</a>'; | |||
//evt = createEvent(rgx, evtRootName + '.beforeHash', wholeMatch, text, id, url, title, options, globals); | |||
result = showdown.subParser('makehtml.hashHTMLSpans')(result, options, globals); | |||
return result; | |||
} | |||
var evtRootName = 'makehtml.links'; | |||
/** | |||
* Turn Markdown link shortcuts into XHTML <a> tags. | |||
*/ | |||
showdown.subParser('makehtml.links', function (text, options, globals) { | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
// 1. Handle reference-style links: [link text] [id] | |||
text = showdown.subParser('makehtml.links.reference')(text, options, globals); | |||
// 2. Handle inline-style links: [link text](url "optional title") | |||
text = showdown.subParser('makehtml.links.inline')(text, options, globals); | |||
// 3. Handle reference-style shortcuts: [link text] | |||
// These must come last in case there's a [link text][1] or [link text](/foo) | |||
text = showdown.subParser('makehtml.links.referenceShortcut')(text, options, globals); | |||
// 4. Handle angle brackets links -> `<http://example.com/>` | |||
// Must come after links, because you can use < and > delimiters in inline links like [this](<url>). | |||
text = showdown.subParser('makehtml.links.angleBrackets')(text, options, globals); | |||
// 5. Handle GithubMentions (if option is enabled) | |||
text = showdown.subParser('makehtml.links.ghMentions')(text, options, globals); | |||
// 6. Handle <a> tags and img tags | |||
text = text.replace(/<a\s[^>]*>[\s\S]*<\/a>/g, function (wholeMatch) { | |||
return showdown.helper._hashHTMLSpan(wholeMatch, globals); | |||
}); | |||
text = text.replace(/<img\s[^>]*\/?>/g, function (wholeMatch) { | |||
return showdown.helper._hashHTMLSpan(wholeMatch, globals); | |||
}); | |||
// 7. Handle naked links (if option is enabled) | |||
text = showdown.subParser('makehtml.links.naked')(text, options, globals); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.inline', function (text, options, globals) { | |||
var evtRootName = evtRootName + '.inline'; | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
// 1. Look for empty cases: []() and [empty]() and []("title") | |||
var rgxEmpty = /\[(.*?)]()()()() |
|||
text = text.replace(rgxEmpty, replaceAnchorTag(rgxEmpty, evtRootName, options, globals, true)); | |||
// 2. Look for cases with crazy urls like ./image/cat1).png | |||
var rgxCrazy = / |
|||
text = text.replace(rgxCrazy, replaceAnchorTag(rgxCrazy, evtRootName, options, globals)); | |||
// 3. inline links with no title or titles wrapped in ' or ": | |||
// [text](url.com) || [text](<url.com>) || [text](url.com "title") || [text](<url.com> "title") | |||
//var rgx2 = / |
|||
var rgx2 = /\[([\S ]*?)]\s?() |
|||
text = text.replace(rgx2, replaceAnchorTag(rgx2, evtRootName, options, globals)); | |||
// 4. inline links with titles wrapped in (): [foo](bar.com (title)) | |||
var rgx3 = /\[([\S ]*?)]\s?() |
|||
text = text.replace(rgx3, replaceAnchorTag(rgx3, evtRootName, options, globals)); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.reference', function (text, options, globals) { | |||
var evtRootName = evtRootName + '.reference'; | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
var rgx = / |
|||
text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals)); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.referenceShortcut', function (text, options, globals) { | |||
var evtRootName = evtRootName + '.referenceShortcut'; | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
var rgx = / |
|||
text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals)); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.ghMentions', function (text, options, globals) { | |||
var evtRootName = evtRootName + 'ghMentions'; | |||
if (!options.ghMentions) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
var rgx = /(^|\s)(\)?(@([a-z\d]+(?:[a-z\d._-]+?[a-z\d]+)*))/gi; | |||
text = text.replace(rgx, function (wholeMatch, st, escape, mentions, username) { | |||
// bail if the mentions was escaped | |||
if (escape === '\') { | |||
return st + mentions; | |||
} | |||
// check if options.ghMentionsLink is a string | |||
// TODO Validation should be done at initialization not at runtime | |||
if (!showdown.helper.isString(options.ghMentionsLink)) { | |||
throw new Error('ghMentionsLink option must be a string'); | |||
} | |||
var url = options.ghMentionsLink.replace(/{u}/g, username); | |||
var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, mentions, null, url, null, options, globals); | |||
// captureEnd Event is triggered inside writeAnchorTag function | |||
return st + writeAnchorTag(evt, options, globals); | |||
}); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.angleBrackets', function (text, options, globals) { | |||
var evtRootName = 'makehtml.links.angleBrackets'; | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
// 1. Parse links first | |||
var urlRgx = /<(((?:https?|ftp):\/\/|www\.)[^'">\s]+)>/gi; | |||
text = text.replace(urlRgx, function (wholeMatch, url, urlStart) { | |||
var text = url; | |||
url = (urlStart === 'www.') ? 'http://' + url : url; | |||
var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals); | |||
return writeAnchorTag(evt, options, globals); | |||
}); | |||
// 2. Then Mail Addresses | |||
var mailRgx = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi; | |||
text = text.replace(mailRgx, function (wholeMatch, mail) { | |||
var url = 'mailto:'; | |||
mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals); | |||
if (options.encodeEmails) { | |||
url = showdown.helper.encodeEmailAddress(url + mail); | |||
mail = showdown.helper.encodeEmailAddress(mail); | |||
} else { | |||
url = url + mail; | |||
} | |||
var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals); | |||
return writeAnchorTag(evt, options, globals); | |||
}); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
/** | |||
* TODO MAKE THIS WORK (IT'S NOT ACTIVATED) | |||
* TODO WRITE THIS DOCUMENTATION | |||
*/ | |||
showdown.subParser('makehtml.links.naked', function (text, options, globals) { | |||
if (!options.simplifiedAutoLink) { | |||
return text; | |||
} | |||
var evtRootName = 'makehtml.links.naked'; | |||
text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText(); | |||
// 2. Now we check for | |||
// we also include leading markdown magic chars [_*~] for cases like __https://www.google.com/foobar__ | |||
var urlRgx = /([_*~]*?)(((?:https?|ftp):\/\/|www\.)[^\s<>"'`´.-][^\s<>"'`´]*?\.[a-z\d.]+[^\s<>"']*)\1/gi; | |||
text = text.replace(urlRgx, function (wholeMatch, leadingMDChars, url, urlPrefix) { | |||
// we now will start traversing the url from the front to back, looking for punctuation chars [_*~,;:.!?\)\]] | |||
var len = url.length; | |||
var suffix = ''; | |||
for (var i = len - 1; i >= 0; --i) { | |||
var char = url.charAt(i); | |||
if (/[_*~,;:.!?]/.test(char)) { | |||
// it's a punctuation char | |||
// we remove it from the url | |||
url = url.slice(0, -1); | |||
// and prepend it to the suffix | |||
suffix = char + suffix; | |||
} else if (/\)/.test(char)) { | |||
var opPar = url.match(/\(/g) || []; | |||
var clPar = url.match(/\)/g); | |||
// it's a curved parenthesis so we need to check for "balance" (kinda) | |||
if (opPar.length < clPar.length) { | |||
// there are more closing Parenthesis than opening so chop it!!!!! | |||
url = url.slice(0, -1); | |||
// and prepend it to the suffix | |||
suffix = char + suffix; | |||
} else { | |||
// it's (kinda) balanced so our work is done | |||
break; | |||
} | |||
} else if (/]/.test(char)) { | |||
var opPar2 = url.match(/\[/g) || []; | |||
var clPar2 = url.match(/\]/g); | |||
// it's a squared parenthesis so we need to check for "balance" (kinda) | |||
if (opPar2.length < clPar2.length) { | |||
// there are more closing Parenthesis than opening so chop it!!!!! | |||
url = url.slice(0, -1); | |||
// and prepend it to the suffix | |||
suffix = char + suffix; | |||
} else { | |||
// it's (kinda) balanced so our work is done | |||
break; | |||
} | |||
} else { | |||
// it's not a punctuation or a parenthesis so our work is done | |||
break; | |||
} | |||
} | |||
// we copy the treated url to the text variable | |||
var text = url; | |||
// finally, if it's a www shortcut, we prepend http | |||
url = (urlPrefix === 'www.') ? 'http://' + url : url; | |||
// url part is done so let's take care of text now | |||
// we need to escape the text (because of links such as www.example.com/foo__bar__baz) | |||
text = text.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback); | |||
// finally we dispatch the event | |||
var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals); | |||
// and return the link tag, with the leadingMDChars and suffix. The leadingMDChars are added at the end too because | |||
// we consumed those characters in the regexp | |||
return leadingMDChars + writeAnchorTag(evt, options, globals) + suffix + leadingMDChars; | |||
}); | |||
// 2. Then mails | |||
var mailRgx = /(^|\s)(?:mailto:)?([A-Za-z0-9!# |
|||
text = text.replace(mailRgx, function (wholeMatch, leadingChar, mail) { | |||
var url = 'mailto:'; | |||
mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals); | |||
if (options.encodeEmails) { | |||
url = showdown.helper.encodeEmailAddress(url + mail); | |||
mail = showdown.helper.encodeEmailAddress(mail); | |||
} else { | |||
url = url + mail; | |||
} | |||
var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals); | |||
return leadingChar + writeAnchorTag(evt, options, globals); | |||
}); | |||
text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText(); | |||
return text; | |||
}); | |||
})(); |
@ -0,0 +1,216 @@ | |||
/** | |||
* Form HTML ordered (numbered) and unordered (bulleted) lists. | |||
*/ | |||
showdown.subParser('makehtml.lists', function (text, options, globals) { | |||
'use strict'; | |||
/** | |||
* Process the contents of a single ordered or unordered list, splitting it | |||
* into individual list items. | |||
* @param {string} listStr | |||
* @param {boolean} trimTrailing | |||
* @returns {string} | |||
*/ | |||
function processListItems (listStr, trimTrailing) { | |||
// The $g_list_level global keeps track of when we're inside a list. | |||
// Each time we enter a list, we increment it; when we leave a list, | |||
// we decrement. If it's zero, we're not in a list anymore. | |||
// | |||
// We do this because when we're not inside a list, we want to treat | |||
// something like this: | |||
// | |||
// I recommend upgrading to version | |||
// 8. Oops, now this line is treated | |||
// as a sub-list. | |||
// | |||
// As a single paragraph, despite the fact that the second line starts | |||
// with a digit-period-space sequence. | |||
// | |||
// Whereas when we're inside a list (or sub-list), that line will be | |||
// treated as the start of a sub-list. What a kludge, huh? This is | |||
// an aspect of Markdown's syntax that's hard to parse perfectly | |||
// without resorting to mind-reading. Perhaps the solution is to | |||
// change the syntax rules such that sub-lists must start with a | |||
// starting cardinal number; e.g. "1." or "a.". | |||
globals.gListLevel++; | |||
// trim trailing blank lines: | |||
listStr = listStr.replace(/\n{2,}$/, '\n'); | |||
// attacklab: add sentinel to emulate \z | |||
listStr += '¨0'; | |||
var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0| {0,3}([*+-]|\d+[.])[ \t]+))/gm, | |||
isParagraphed = (/\n[ \t]*\n(?!¨0)/.test(listStr)); | |||
// Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation, | |||
// which is a syntax breaking change | |||
// activating this option reverts to old behavior | |||
// This will be removed in version 2.0 | |||
if (options.disableForced4SpacesIndentedSublists) { | |||
rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm; | |||
} | |||
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) { | |||
checked = (checked && checked.trim() !== ''); | |||
var item = showdown.subParser('makehtml.outdent')(m4, options, globals), | |||
bulletStyle = ''; | |||
// Support for github tasklists | |||
if (taskbtn && options.tasklists) { | |||
bulletStyle = ' class="task-list-item" style="list-style-type: none;"'; | |||
item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () { | |||
var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"'; | |||
if (checked) { | |||
otp += ' checked'; | |||
} | |||
otp += '>'; | |||
return otp; | |||
}); | |||
} | |||
// ISSUE #312 | |||
// This input: - - - a | |||
// causes trouble to the parser, since it interprets it as: | |||
// <ul><li><li><li>a</li></li></li></ul> | |||
// instead of: | |||
// <ul><li>- - a</li></ul> | |||
// So, to prevent it, we will put a marker (¨A)in the beginning of the line | |||
// Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser | |||
item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) { | |||
return '¨A' + wm2; | |||
}); | |||
// SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline | |||
// or/nor indented. ex: | |||
// | |||
// - # foo | |||
// bar is great | |||
// | |||
// While this does now follow the spec per se, not allowing for this might cause confusion since | |||
// header blocks don't need double newlines after | |||
if (/^#+.+\n.+/.test(item)) { | |||
item = item.replace(/^(#+.+)$/m, '$1\n'); | |||
} | |||
// m1 - Leading line or | |||
// Has a double return (multi paragraph) | |||
if (m1 || (item.search(/\n{2,}/) > -1)) { | |||
item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals); | |||
item = showdown.subParser('makehtml.blockGamut')(item, options, globals); | |||
} else { | |||
// Recursion for sub-lists: | |||
item = showdown.subParser('makehtml.lists')(item, options, globals); | |||
item = item.replace(/\n$/, ''); // chomp(item) | |||
item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals); | |||
// Colapse double linebreaks | |||
item = item.replace(/\n\n+/g, '\n\n'); | |||
if (isParagraphed) { | |||
item = showdown.subParser('makehtml.paragraphs')(item, options, globals); | |||
} else { | |||
item = showdown.subParser('makehtml.spanGamut')(item, options, globals); | |||
} | |||
} | |||
// now we need to remove the marker (¨A) | |||
item = item.replace('¨A', ''); | |||
// we can finally wrap the line in list item tags | |||
item = '<li' + bulletStyle + '>' + item + '</li>\n'; | |||
return item; | |||
}); | |||
// attacklab: strip sentinel | |||
listStr = listStr.replace(/¨0/g, ''); | |||
globals.gListLevel--; | |||
if (trimTrailing) { | |||
listStr = listStr.replace(/\s+$/, ''); | |||
} | |||
return listStr; | |||
} | |||
function styleStartNumber (list, listType) { | |||
// check if ol and starts by a number different than 1 | |||
if (listType === 'ol') { | |||
var res = list.match(/^ *(\d+)\./); | |||
if (res && res[1] !== '1') { | |||
return ' start="' + res[1] + '"'; | |||
} | |||
} | |||
return ''; | |||
} | |||
/** | |||
* Check and parse consecutive lists (better fix for issue #142) | |||
* @param {string} list | |||
* @param {string} listType | |||
* @param {boolean} trimTrailing | |||
* @returns {string} | |||
*/ | |||
function parseConsecutiveLists (list, listType, trimTrailing) { | |||
// check if we caught 2 or more consecutive lists by mistake | |||
// we use the counterRgx, meaning if listType is UL we look for OL and vice versa | |||
var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm, | |||
ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm, | |||
counterRxg = (listType === 'ul') ? olRgx : ulRgx, | |||
result = ''; | |||
if (list.search(counterRxg) !== -1) { | |||
(function parseCL (txt) { | |||
var pos = txt.search(counterRxg), | |||
style = styleStartNumber(list, listType); | |||
if (pos !== -1) { | |||
// slice | |||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n'; | |||
// invert counterType and listType | |||
listType = (listType === 'ul') ? 'ol' : 'ul'; | |||
counterRxg = (listType === 'ul') ? olRgx : ulRgx; | |||
//recurse | |||
parseCL(txt.slice(pos)); | |||
} else { | |||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n'; | |||
} | |||
})(list); | |||
} else { | |||
var style = styleStartNumber(list, listType); | |||
result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n'; | |||
} | |||
return result; | |||
} | |||
// Start of list parsing | |||
var subListRgx = /^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm; | |||
var mainListRgx = /(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm; | |||
text = globals.converter._dispatch('lists.before', text, options, globals).getText(); | |||
// add sentinel to hack around khtml/safari bug: | |||
// http://bugs.webkit.org/show_bug.cgi?id=11231 | |||
text += '¨0'; | |||
if (globals.gListLevel) { | |||
text = text.replace(subListRgx, function (wholeMatch, list, m2) { | |||
var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol'; | |||
return parseConsecutiveLists(list, listType, true); | |||
}); | |||
} else { | |||
text = text.replace(mainListRgx, function (wholeMatch, m1, list, m3) { | |||
var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol'; | |||
return parseConsecutiveLists(list, listType, false); | |||
}); | |||
} | |||
// strip sentinel | |||
text = text.replace(/¨0/, ''); | |||
text = globals.converter._dispatch('makehtml.lists.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,49 @@ | |||
/** | |||
* Parse metadata at the top of the document | |||
*/ | |||
showdown.subParser('makehtml.metadata', function (text, options, globals) { | |||
'use strict'; | |||
if (!options.metadata) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals).getText(); | |||
function parseMetadataContents (content) { | |||
// raw is raw so it's not changed in any way | |||
globals.metadata.raw = content; | |||
// escape chars forbidden in html attributes | |||
// double quotes | |||
content = content | |||
// ampersand first | |||
.replace(/&/g, '&') | |||
// double quotes | |||
.replace(/"/g, '"'); | |||
content = content.replace(/\n {4}/g, ' '); | |||
content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) { | |||
globals.metadata.parsed[key] = value; | |||
return ''; | |||
}); | |||
} | |||
text = text.replace(/^\s*«««+(\S*?)\n([\s\S]+?)\n»»»+\n/, function (wholematch, format, content) { | |||
parseMetadataContents(content); | |||
return '¨M'; | |||
}); | |||
text = text.replace(/^\s*---+(\S*?)\n([\s\S]+?)\n---+\n/, function (wholematch, format, content) { | |||
if (format) { | |||
globals.metadata.format = format; | |||
} | |||
parseMetadataContents(content); | |||
return '¨M'; | |||
}); | |||
text = text.replace(/¨M/g, ''); | |||
text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,17 @@ | |||
/** | |||
* Remove one level of line-leading tabs or spaces | |||
*/ | |||
showdown.subParser('makehtml.outdent', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals).getText(); | |||
// attacklab: hack around Konqueror 3.5.4 bug: | |||
// "----------bug".replace(/^-/g,"") == "bug" | |||
text = text.replace(/^(\t|[ ]{1,4})/gm, '¨0'); // attacklab: g_tab_width | |||
// attacklab: clean up hack | |||
text = text.replace(/¨0/g, ''); | |||
text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,70 @@ | |||
/** | |||
* | |||
*/ | |||
showdown.subParser('makehtml.paragraphs', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals).getText(); | |||
// Strip leading and trailing lines: | |||
text = text.replace(/^\n+/g, ''); | |||
text = text.replace(/\n+$/g, ''); | |||
var grafs = text.split(/\n{2,}/g), | |||
grafsOut = [], | |||
end = grafs.length; // Wrap <p> tags | |||
for (var i = 0; i < end; i++) { | |||
var str = grafs[i]; | |||
// if this is an HTML marker, copy it | |||
if (str.search(/¨(K|G)(\d+)\1/g) >= 0) { | |||
grafsOut.push(str); | |||
// test for presence of characters to prevent empty lines being parsed | |||
// as paragraphs (resulting in undesired extra empty paragraphs) | |||
} else if (str.search(/\S/) >= 0) { | |||
str = showdown.subParser('makehtml.spanGamut')(str, options, globals); | |||
str = str.replace(/^([ \t]*)/g, '<p>'); | |||
str += '</p>'; | |||
grafsOut.push(str); | |||
} | |||
} | |||
/** Unhashify HTML blocks */ | |||
end = grafsOut.length; | |||
for (i = 0; i < end; i++) { | |||
var blockText = '', | |||
grafsOutIt = grafsOut[i], | |||
codeFlag = false; | |||
// if this is a marker for an html block... | |||
// use RegExp.test instead of string.search because of QML bug | |||
while (/¨(K|G)(\d+)\1/.test(grafsOutIt)) { | |||
var delim = RegExp.$1, | |||
num = RegExp.$2; | |||
if (delim === 'K') { | |||
blockText = globals.gHtmlBlocks[num]; | |||
} else { | |||
// we need to check if ghBlock is a false positive | |||
if (codeFlag) { | |||
// use encoded version of all text | |||
blockText = showdown.subParser('makehtml.encodeCode')(globals.ghCodeBlocks[num].text, options, globals); | |||
} else { | |||
blockText = globals.ghCodeBlocks[num].codeblock; | |||
} | |||
} | |||
blockText = blockText.replace(/$/g, ' |
|||
grafsOutIt = grafsOutIt.replace(/(\n\n)?¨(K|G)\d+\2(\n\n)?/, blockText); | |||
// Check if grafsOutIt is a pre->code | |||
if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) { | |||
codeFlag = true; | |||
} | |||
} | |||
grafsOut[i] = grafsOutIt; | |||
} | |||
text = grafsOut.join('\n'); | |||
// Strip leading and trailing lines: | |||
text = text.replace(/^\n+/g, ''); | |||
text = text.replace(/\n+$/g, ''); | |||
return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals).getText(); | |||
}); |
@ -0,0 +1,20 @@ | |||
/** | |||
* Run extension | |||
*/ | |||
showdown.subParser('makehtml.runExtension', function (ext, text, options, globals) { | |||
'use strict'; | |||
if (ext.filter) { | |||
text = ext.filter(text, globals.converter, options); | |||
} else if (ext.regex) { | |||
// TODO remove this when old extension loading mechanism is deprecated | |||
var re = ext.regex; | |||
if (!(re instanceof RegExp)) { | |||
re = new RegExp(re, 'g'); | |||
} | |||
text = text.replace(re, ext.replace); | |||
} | |||
return text; | |||
}); |
@ -0,0 +1,50 @@ | |||
/** | |||
* These are all the transformations that occur *within* block-level | |||
* tags like paragraphs, headers, and list items. | |||
*/ | |||
showdown.subParser('makehtml.spanGamut', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.span.before', text, options, globals).getText(); | |||
text = showdown.subParser('makehtml.codeSpans')(text, options, globals); | |||
text = showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(text, options, globals); | |||
text = showdown.subParser('makehtml.encodeBackslashEscapes')(text, options, globals); | |||
// Process link and image tags. Images must come first, | |||
// because ![foo][f] looks like a link. | |||
text = showdown.subParser('makehtml.images')(text, options, globals); | |||
text = globals.converter._dispatch('smakehtml.links.before', text, options, globals).getText(); | |||
text = showdown.subParser('makehtml.links')(text, options, globals); | |||
text = globals.converter._dispatch('smakehtml.links.after', text, options, globals).getText(); | |||
//text = showdown.subParser('makehtml.autoLinks')(text, options, globals); | |||
//text = showdown.subParser('makehtml.simplifiedAutoLinks')(text, options, globals); | |||
text = showdown.subParser('makehtml.emoji')(text, options, globals); | |||
text = showdown.subParser('makehtml.underline')(text, options, globals); | |||
text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals); | |||
text = showdown.subParser('makehtml.strikethrough')(text, options, globals); | |||
text = showdown.subParser('makehtml.ellipsis')(text, options, globals); | |||
// we need to hash HTML tags inside spans | |||
text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals); | |||
// now we encode amps and angles | |||
text = showdown.subParser('makehtml.encodeAmpsAndAngles')(text, options, globals); | |||
// Do hard breaks | |||
if (options.simpleLineBreaks) { | |||
// GFM style hard breaks | |||
// only add line breaks if the text does not contain a block (special case for lists) | |||
if (!/\n\n¨K/.test(text)) { | |||
text = text.replace(/\n+/g, '<br />\n'); | |||
} | |||
} else { | |||
// Vanilla hard breaks | |||
text = text.replace(/ +\n/g, '<br />\n'); | |||
} | |||
text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,11 @@ | |||
showdown.subParser('makehtml.strikethrough', function (text, options, globals) { | |||
'use strict'; | |||
if (options.strikethrough) { | |||
text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals).getText(); | |||
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return '<del>' + txt + '</del>'; }); | |||
text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals).getText(); | |||
} | |||
return text; | |||
}); |
@ -0,0 +1,53 @@ | |||
/** | |||
* Strips link definitions from text, stores the URLs and titles in | |||
* hash references. | |||
* Link defs are in the form: ^[id]: url "optional title" | |||
*/ | |||
showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, globals) { | |||
'use strict'; | |||
var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?([^>\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm, | |||
base64Regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(data:.+?\/.+?;base64,[A-Za-z0-9+/=\n]+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm; | |||
// attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug | |||
text += '¨0'; | |||
var replaceFunc = function (wholeMatch, linkId, url, width, height, blankLines, title) { | |||
linkId = linkId.toLowerCase(); | |||
if (url.match(/^data:.+?\/.+?;base64,/)) { | |||
// remove newlines | |||
globals.gUrls[linkId] = url.replace(/\s/g, ''); | |||
} else { | |||
globals.gUrls[linkId] = showdown.subParser('makehtml.encodeAmpsAndAngles')(url, options, globals); // Link IDs are case-insensitive | |||
} | |||
if (blankLines) { | |||
// Oops, found blank lines, so it's not a title. | |||
// Put back the parenthetical statement we stole. | |||
return blankLines + title; | |||
} else { | |||
if (title) { | |||
globals.gTitles[linkId] = title.replace(/"|'/g, '"'); | |||
} | |||
if (options.parseImgDimensions && width && height) { | |||
globals.gDimensions[linkId] = { | |||
width: width, | |||
height: height | |||
}; | |||
} | |||
} | |||
// Completely remove the definition from the text | |||
return ''; | |||
}; | |||
// first we try to find base64 link references | |||
text = text.replace(base64Regex, replaceFunc); | |||
text = text.replace(regex, replaceFunc); | |||
// attacklab: strip sentinel | |||
text = text.replace(/¨0/, ''); | |||
return text; | |||
}); |
@ -0,0 +1,143 @@ | |||
showdown.subParser('makehtml.tables', function (text, options, globals) { | |||
'use strict'; | |||
if (!options.tables) { | |||
return text; | |||
} | |||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm, | |||
//singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n(?: {0,3}\|.+\|\n)+(?:\n\n|¨0)/gm; | |||
singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm; | |||
function parseStyles (sLine) { | |||
if (/^:[ \t]*--*$/.test(sLine)) { | |||
return ' style="text-align:left;"'; | |||
} else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) { | |||
return ' style="text-align:right;"'; | |||
} else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) { | |||
return ' style="text-align:center;"'; | |||
} else { | |||
return ''; | |||
} | |||
} | |||
function parseHeaders (header, style) { | |||
var id = ''; | |||
header = header.trim(); | |||
// support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility | |||
if (options.tablesHeaderId || options.tableHeaderId) { | |||
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"'; | |||
} | |||
header = showdown.subParser('makehtml.spanGamut')(header, options, globals); | |||
return '<th' + id + style + '>' + header + '</th>\n'; | |||
} | |||
function parseCells (cell, style) { | |||
var subText = showdown.subParser('makehtml.spanGamut')(cell, options, globals); | |||
return '<td' + style + '>' + subText + '</td>\n'; | |||
} | |||
function buildTable (headers, cells) { | |||
var tb = '<table>\n<thead>\n<tr>\n', | |||
tblLgn = headers.length; | |||
for (var i = 0; i < tblLgn; ++i) { | |||
tb += headers[i]; | |||
} | |||
tb += '</tr>\n</thead>\n<tbody>\n'; | |||
for (i = 0; i < cells.length; ++i) { | |||
tb += '<tr>\n'; | |||
for (var ii = 0; ii < tblLgn; ++ii) { | |||
tb += cells[i][ii]; | |||
} | |||
tb += '</tr>\n'; | |||
} | |||
tb += '</tbody>\n</table>\n'; | |||
return tb; | |||
} | |||
function parseTable (rawTable) { | |||
var i, tableLines = rawTable.split('\n'); | |||
for (i = 0; i < tableLines.length; ++i) { | |||
// strip wrong first and last column if wrapped tables are used | |||
if (/^ {0,3}\|/.test(tableLines[i])) { | |||
tableLines[i] = tableLines[i].replace(/^ {0,3}\|/, ''); | |||
} | |||
if (/\|[ \t]*$/.test(tableLines[i])) { | |||
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, ''); | |||
} | |||
// parse code spans first, but we only support one line code spans | |||
tableLines[i] = showdown.subParser('makehtml.codeSpans')(tableLines[i], options, globals); | |||
} | |||
var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}), | |||
rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}), | |||
rawCells = [], | |||
headers = [], | |||
styles = [], | |||
cells = []; | |||
tableLines.shift(); | |||
tableLines.shift(); | |||
for (i = 0; i < tableLines.length; ++i) { | |||
if (tableLines[i].trim() === '') { | |||
continue; | |||
} | |||
rawCells.push( | |||
tableLines[i] | |||
.split('|') | |||
.map(function (s) { | |||
return s.trim(); | |||
}) | |||
); | |||
} | |||
if (rawHeaders.length < rawStyles.length) { | |||
return rawTable; | |||
} | |||
for (i = 0; i < rawStyles.length; ++i) { | |||
styles.push(parseStyles(rawStyles[i])); | |||
} | |||
for (i = 0; i < rawHeaders.length; ++i) { | |||
if (showdown.helper.isUndefined(styles[i])) { | |||
styles[i] = ''; | |||
} | |||
headers.push(parseHeaders(rawHeaders[i], styles[i])); | |||
} | |||
for (i = 0; i < rawCells.length; ++i) { | |||
var row = []; | |||
for (var ii = 0; ii < headers.length; ++ii) { | |||
if (showdown.helper.isUndefined(rawCells[i][ii])) { | |||
} | |||
row.push(parseCells(rawCells[i][ii], styles[ii])); | |||
} | |||
cells.push(row); | |||
} | |||
return buildTable(headers, cells); | |||
} | |||
text = globals.converter._dispatch('makehtml.tables.before', text, options, globals).getText(); | |||
// find escaped pipe characters | |||
text = text.replace(/\(\|)/g, showdown.helper.escapeCharactersCallback); | |||
// parse multi column tables | |||
text = text.replace(tableRgx, parseTable); | |||
// parse one column tables | |||
text = text.replace(singeColTblRgx, parseTable); | |||
text = globals.converter._dispatch('makehtml.tables.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,32 @@ | |||
showdown.subParser('makehtml.underline', function (text, options, globals) { | |||
'use strict'; | |||
if (!options.underline) { | |||
return text; | |||
} | |||
text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText(); | |||
if (options.literalMidWordUnderscores) { | |||
text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) { | |||
return '<u>' + txt + '</u>'; | |||
}); | |||
text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) { | |||
return '<u>' + txt + '</u>'; | |||
}); | |||
} else { | |||
text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm; | |||
}); | |||
text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) { | |||
return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm; | |||
}); | |||
} | |||
// escape remaining underscores to prevent them being parsed by italic and bold | |||
text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback); | |||
text = globals.converter._dispatch('makehtml.underline.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,15 @@ | |||
/** | |||
* Swap back in all the special characters we've hidden. | |||
*/ | |||
showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, globals) { | |||
'use strict'; | |||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals).getText(); | |||
text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) { | |||
var charCodeToReplace = parseInt(m1); | |||
return String.fromCharCode(charCodeToReplace); | |||
}); | |||
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals).getText(); | |||
return text; | |||
}); |
@ -0,0 +1,22 @@ | |||
showdown.subParser('makeMarkdown.blockquote', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes()) { | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
var innerTxt = showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
if (innerTxt === '') { | |||
continue; | |||
} | |||
txt += innerTxt; | |||
} | |||
} | |||
// cleanup | |||
txt = txt.trim(); | |||
txt = '> ' + txt.split('\n').join('\n> '); | |||
return txt; | |||
}); |
@ -0,0 +1,5 @@ | |||
showdown.subParser('makeMarkdown.break', function () { | |||
'use strict'; | |||
return ' \n'; | |||
}); |
@ -0,0 +1,7 @@ | |||
showdown.subParser('makeMarkdown.codeBlock', function (node, globals) { | |||
'use strict'; | |||
var lang = node.getAttribute('language'), | |||
num = node.getAttribute('precodenum'); | |||
return '```' + lang + '\n' + globals.preList[num] + '\n```'; | |||
}); |
@ -0,0 +1,5 @@ | |||
showdown.subParser('makeMarkdown.codeSpan', function (node) { | |||
'use strict'; | |||
return '`' + node.innerHTML + '`'; | |||
}); |
@ -0,0 +1,15 @@ | |||
showdown.subParser('makeMarkdown.emphasis', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes()) { | |||
txt += '*'; | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
txt += '*'; | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,17 @@ | |||
showdown.subParser('makeMarkdown.header', function (node, globals, headerLevel) { | |||
'use strict'; | |||
var headerMark = new Array(headerLevel + 1).join('#'), | |||
txt = ''; | |||
if (node.hasChildNodes()) { | |||
txt = headerMark + ' '; | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,5 @@ | |||
showdown.subParser('makeMarkdown.hr', function () { | |||
'use strict'; | |||
return '---'; | |||
}); |
@ -0,0 +1,18 @@ | |||
showdown.subParser('makeMarkdown.image', function (node) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasAttribute('src')) { | |||
txt += ' + '>'; | |||
if (node.hasAttribute('width') && node.hasAttribute('height')) { | |||
txt += ' =' + node.getAttribute('width') + 'x' + node.getAttribute('height'); | |||
} | |||
if (node.hasAttribute('title')) { | |||
txt += ' "' + node.getAttribute('title') + '"'; | |||
} | |||
txt += ')'; | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,20 @@ | |||
showdown.subParser('makeMarkdown.links', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes() && node.hasAttribute('href')) { | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
txt = '['; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
txt += ']('; | |||
txt += '<' + node.getAttribute('href') + '>'; | |||
if (node.hasAttribute('title')) { | |||
txt += ' "' + node.getAttribute('title') + '"'; | |||
} | |||
txt += ')'; | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,31 @@ | |||
showdown.subParser('makeMarkdown.list', function (node, globals, type) { | |||
'use strict'; | |||
var txt = ''; | |||
if (!node.hasChildNodes()) { | |||
return ''; | |||
} | |||
var listItems = node.childNodes, | |||
listItemsLenght = listItems.length, | |||
listNum = node.getAttribute('start') || 1; | |||
for (var i = 0; i < listItemsLenght; ++i) { | |||
if (typeof listItems[i].tagName === 'undefined' || listItems[i].tagName.toLowerCase() !== 'li') { | |||
continue; | |||
} | |||
// define the bullet to use in list | |||
var bullet = ''; | |||
if (type === 'ol') { | |||
bullet = listNum.toString() + '. '; | |||
} else { | |||
bullet = '- '; | |||
} | |||
// parse list item | |||
txt += bullet + showdown.subParser('makeMarkdown.listItem')(listItems[i], globals); | |||
++listNum; | |||
} | |||
return txt.trim(); | |||
}); |
@ -0,0 +1,25 @@ | |||
showdown.subParser('makeMarkdown.listItem', function (node, globals) { | |||
'use strict'; | |||
var listItemTxt = ''; | |||
var children = node.childNodes, | |||
childrenLenght = children.length; | |||
for (var i = 0; i < childrenLenght; ++i) { | |||
listItemTxt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
// if it's only one liner, we need to add a newline at the end | |||
if (!/\n$/.test(listItemTxt)) { | |||
listItemTxt += '\n'; | |||
} else { | |||
// it's multiparagraph, so we need to indent | |||
listItemTxt = listItemTxt | |||
.split('\n') | |||
.join('\n ') | |||
.replace(/^ {4}$/gm, '') | |||
.replace(/\n\n+/g, '\n\n'); | |||
} | |||
return listItemTxt; | |||
}); |
@ -0,0 +1,124 @@ | |||
showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) { | |||
'use strict'; | |||
spansOnly = spansOnly || false; | |||
var txt = ''; | |||
// edge case of text without wrapper paragraph | |||
if (node.nodeType === 3) { | |||
return showdown.subParser('makeMarkdown.txt')(node, globals); | |||
} | |||
// HTML comment | |||
if (node.nodeType === 8) { | |||
return '<!--' + node.data + '-->\n\n'; | |||
} | |||
// process only node elements | |||
if (node.nodeType !== 1) { | |||
return ''; | |||
} | |||
var tagName = node.tagName.toLowerCase(); | |||
switch (tagName) { | |||
// | |||
// BLOCKS | |||
// | |||
case 'h1': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 1) + '\n\n'; } | |||
break; | |||
case 'h2': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 2) + '\n\n'; } | |||
break; | |||
case 'h3': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 3) + '\n\n'; } | |||
break; | |||
case 'h4': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 4) + '\n\n'; } | |||
break; | |||
case 'h5': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 5) + '\n\n'; } | |||
break; | |||
case 'h6': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 6) + '\n\n'; } | |||
break; | |||
case 'p': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.paragraph')(node, globals) + '\n\n'; } | |||
break; | |||
case 'blockquote': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.blockquote')(node, globals) + '\n\n'; } | |||
break; | |||
case 'hr': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.hr')(node, globals) + '\n\n'; } | |||
break; | |||
case 'ol': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ol') + '\n\n'; } | |||
break; | |||
case 'ul': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ul') + '\n\n'; } | |||
break; | |||
case 'precode': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.codeBlock')(node, globals) + '\n\n'; } | |||
break; | |||
case 'pre': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.pre')(node, globals) + '\n\n'; } | |||
break; | |||
case 'table': | |||
if (!spansOnly) { txt = showdown.subParser('makeMarkdown.table')(node, globals) + '\n\n'; } | |||
break; | |||
// | |||
// SPANS | |||
// | |||
case 'code': | |||
txt = showdown.subParser('makeMarkdown.codeSpan')(node, globals); | |||
break; | |||
case 'em': | |||
case 'i': | |||
txt = showdown.subParser('makeMarkdown.emphasis')(node, globals); | |||
break; | |||
case 'strong': | |||
case 'b': | |||
txt = showdown.subParser('makeMarkdown.strong')(node, globals); | |||
break; | |||
case 'del': | |||
txt = showdown.subParser('makeMarkdown.strikethrough')(node, globals); | |||
break; | |||
case 'a': | |||
txt = showdown.subParser('makeMarkdown.links')(node, globals); | |||
break; | |||
case 'img': | |||
txt = showdown.subParser('makeMarkdown.image')(node, globals); | |||
break; | |||
case 'br': | |||
txt = showdown.subParser('makeMarkdown.break')(node, globals); | |||
break; | |||
default: | |||
txt = node.outerHTML + '\n\n'; | |||
} | |||
// common normalization | |||
// TODO eventually | |||
return txt; | |||
}); |
@ -0,0 +1,17 @@ | |||
showdown.subParser('makeMarkdown.paragraph', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes()) { | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
} | |||
// some text normalization | |||
txt = txt.trim(); | |||
return txt; | |||
}); |
@ -0,0 +1,6 @@ | |||
showdown.subParser('makeMarkdown.pre', function (node, globals) { | |||
'use strict'; | |||
var num = node.getAttribute('prenum'); | |||
return '<pre>' + globals.preList[num] + '</pre>'; | |||
}); |
@ -0,0 +1,15 @@ | |||
showdown.subParser('makeMarkdown.strikethrough', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes()) { | |||
txt += '~~'; | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
txt += '~~'; | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,15 @@ | |||
showdown.subParser('makeMarkdown.strong', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (node.hasChildNodes()) { | |||
txt += '**'; | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals); | |||
} | |||
txt += '**'; | |||
} | |||
return txt; | |||
}); |
@ -0,0 +1,70 @@ | |||
showdown.subParser('makeMarkdown.table', function (node, globals) { | |||
'use strict'; | |||
var txt = '', | |||
tableArray = [[], []], | |||
headings = node.querySelectorAll('thead>tr>th'), | |||
rows = node.querySelectorAll('tbody>tr'), | |||
i, ii; | |||
for (i = 0; i < headings.length; ++i) { | |||
var headContent = showdown.subParser('makeMarkdown.tableCell')(headings[i], globals), | |||
allign = '---'; | |||
if (headings[i].hasAttribute('style')) { | |||
var style = headings[i].getAttribute('style').toLowerCase().replace(/\s/g, ''); | |||
switch (style) { | |||
case 'text-align:left;': | |||
allign = ':---'; | |||
break; | |||
case 'text-align:right;': | |||
allign = '---:'; | |||
break; | |||
case 'text-align:center;': | |||
allign = ':---:'; | |||
break; | |||
} | |||
} | |||
tableArray[0][i] = headContent.trim(); | |||
tableArray[1][i] = allign; | |||
} | |||
for (i = 0; i < rows.length; ++i) { | |||
var r = tableArray.push([]) - 1, | |||
cols = rows[i].getElementsByTagName('td'); | |||
for (ii = 0; ii < headings.length; ++ii) { | |||
var cellContent = ' '; | |||
if (typeof cols[ii] !== 'undefined') { | |||
cellContent = showdown.subParser('makeMarkdown.tableCell')(cols[ii], globals); | |||
} | |||
tableArray[r].push(cellContent); | |||
} | |||
} | |||
var cellSpacesCount = 3; | |||
for (i = 0; i < tableArray.length; ++i) { | |||
for (ii = 0; ii < tableArray[i].length; ++ii) { | |||
var strLen = tableArray[i][ii].length; | |||
if (strLen > cellSpacesCount) { | |||
cellSpacesCount = strLen; | |||
} | |||
} | |||
} | |||
for (i = 0; i < tableArray.length; ++i) { | |||
for (ii = 0; ii < tableArray[i].length; ++ii) { | |||
if (i === 1) { | |||
if (tableArray[i][ii].slice(-1) === ':') { | |||
tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii].slice(-1), cellSpacesCount - 1, '-') + ':'; | |||
} else { | |||
tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount, '-'); | |||
} | |||
} else { | |||
tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount); | |||
} | |||
} | |||
txt += '| ' + tableArray[i].join(' | ') + ' |\n'; | |||
} | |||
return txt.trim(); | |||
}); |
@ -0,0 +1,15 @@ | |||
showdown.subParser('makeMarkdown.tableCell', function (node, globals) { | |||
'use strict'; | |||
var txt = ''; | |||
if (!node.hasChildNodes()) { | |||
return ''; | |||
} | |||
var children = node.childNodes, | |||
childrenLength = children.length; | |||
for (var i = 0; i < childrenLength; ++i) { | |||
txt += showdown.subParser('makeMarkdown.node')(children[i], globals, true); | |||
} | |||
return txt.trim(); | |||
}); |
@ -0,0 +1,43 @@ | |||
showdown.subParser('makeMarkdown.txt', function (node) { | |||
'use strict'; | |||
var txt = node.nodeValue; | |||
// multiple spaces are collapsed | |||
txt = txt.replace(/ +/g, ' '); | |||
// replace the custom ¨NBSP; with a space | |||
txt = txt.replace(/¨NBSP;/g, ' '); | |||
// ", <, > and & should replace escaped html entities | |||
txt = showdown.helper.unescapeHTMLEntities(txt); | |||
// escape markdown magic characters | |||
// emphasis, strong and strikethrough - can appear everywhere | |||
// we also escape pipe (|) because of tables | |||
// and escape ` because of code blocks and spans | |||
txt = txt.replace(/([*_~|`])/g, '\$1'); | |||
// escape > because of blockquotes | |||
txt = txt.replace(/^(\s*)>/g, '\$1>'); | |||
// hash character, only troublesome at the beginning of a line because of headers | |||
txt = txt.replace(/^#/gm, '\#'); | |||
// horizontal rules | |||
txt = txt.replace(/^(\s*)([-=]{3,})(\s*)$/, ' |
|||
// dot, because of ordered lists, only troublesome at the beginning of a line when preceded by an integer | |||
txt = txt.replace(/^( {0,3}\d+)\./gm, '$1\.'); | |||
// +, * and -, at the beginning of a line becomes a list, so we need to escape them also (asterisk was already escaped) | |||
txt = txt.replace(/^( {0,3})([+-])/gm, ' |
|||
// images and links, ] followed by ( is problematic, so we escape it | |||
txt = txt.replace(/]([\s]*)\(/g, '\]$1\('); | |||
// reference URIs must also be escaped | |||
txt = txt.replace(/^ {0,3}\[([\S \t]*?)]:/gm, '\[$1]:'); | |||
return txt; | |||
}); |