Skip to content

Commit

Permalink
feat(underline): add EXPERIMENTAL support for underline
Browse files Browse the repository at this point in the history
Syntax is:
```
__double underscores__
or
___triple unserscores___
```
Keep in mind that, with this option enabled, underscore no longer
parses as `<em>` or `<strong>`

Closes #450
  • Loading branch information
tivie committed Oct 24, 2017
1 parent 9cdc35e commit 084b819
Show file tree
Hide file tree
Showing 13 changed files with 993 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -357,6 +357,9 @@ var defaultOptions = showdown.getDefaultOptions();
* **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>`.
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
## Flavors
Expand Down
33 changes: 33 additions & 0 deletions dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/options.js
Expand Up @@ -145,6 +145,11 @@ function getDefaultOpts (simple) {
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'
}
};
if (simple === false) {
Expand Down
1 change: 1 addition & 0 deletions src/subParsers/spanGamut.js
Expand Up @@ -21,6 +21,7 @@ showdown.subParser('spanGamut', function (text, options, globals) {
text = showdown.subParser('autoLinks')(text, options, globals);
text = showdown.subParser('simplifiedAutoLinks')(text, options, globals);
text = showdown.subParser('emoji')(text, options, globals);
text = showdown.subParser('underline')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);

Expand Down
26 changes: 26 additions & 0 deletions src/subParsers/underline.js
@@ -0,0 +1,26 @@
showdown.subParser('underline', function (text, options, globals) {
'use strict';

if (!options.underline) {
return text;
}

text = globals.converter._dispatch('underline.before', text, options, globals);

if (options.literalMidWordUnderscores) {
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;
});
}

// escape remaining underscores to prevent them being parsed by italic and bold
text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);

text = globals.converter._dispatch('underline.after', text, options, globals);

return text;
});

0 comments on commit 084b819

Please sign in to comment.