mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
feat(emoji): add emoji support
Add unicode emoji support to showdown. To enable this feature, use `emoji: true` option. A list of supported emojis is available here: https://github.com/showdownjs/showdown/wiki/Emojis Closes #448
This commit is contained in:
parent
61929bb262
commit
5b8f1d312f
|
@ -345,7 +345,7 @@ var defaultOptions = showdown.getDefaultOptions();
|
|||
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] Enables e-mail addresses encoding through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities. (since v1.6.1)
|
||||
* **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.
|
||||
|
||||
|
@ -354,6 +354,9 @@ var defaultOptions = showdown.getDefaultOptions();
|
|||
|
||||
* **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)**
|
||||
|
||||
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
|
||||
|
||||
## Flavors
|
||||
|
|
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
1183
src/helpers.js
1183
src/helpers.js
File diff suppressed because one or more lines are too long
|
@ -140,6 +140,11 @@ function getDefaultOpts (simple) {
|
|||
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'
|
||||
}
|
||||
};
|
||||
if (simple === false) {
|
||||
|
|
|
@ -24,7 +24,8 @@ var showdown = {},
|
|||
requireSpaceBeforeHeadingText: true,
|
||||
ghCompatibleHeaderId: true,
|
||||
ghMentions: true,
|
||||
backslashEscapesHTMLTags: true
|
||||
backslashEscapesHTMLTags: true,
|
||||
emoji: true
|
||||
},
|
||||
original: {
|
||||
noHeaderId: true,
|
||||
|
|
26
src/subParsers/emoji.js
Normal file
26
src/subParsers/emoji.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* These are all the transformations that occur *within* block-level
|
||||
* tags like paragraphs, headers, and list items.
|
||||
*/
|
||||
showdown.subParser('emoji', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
if (!options.emoji) {
|
||||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('emoji.before', text, options, globals);
|
||||
|
||||
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('emoji.after', text, options, globals);
|
||||
|
||||
return text;
|
||||
});
|
|
@ -20,6 +20,7 @@ showdown.subParser('spanGamut', function (text, options, globals) {
|
|||
// delimiters in inline links like [this](<url>).
|
||||
text = showdown.subParser('autoLinks')(text, options, globals);
|
||||
text = showdown.subParser('simplifiedAutoLinks')(text, options, globals);
|
||||
text = showdown.subParser('emoji')(text, options, globals);
|
||||
text = showdown.subParser('italicsAndBold')(text, options, globals);
|
||||
text = showdown.subParser('strikethrough')(text, options, globals);
|
||||
|
||||
|
|
3
test/features/emojis/complex.html
Normal file
3
test/features/emojis/complex.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
<p>foo🍎bar</p>
|
||||
<p>foo: apple :bar</p>
|
||||
<p>:foo 🍎 bar:</p>
|
5
test/features/emojis/complex.md
Normal file
5
test/features/emojis/complex.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
foo:apple:bar
|
||||
|
||||
foo: apple :bar
|
||||
|
||||
:foo :apple: bar:
|
4
test/features/emojis/links.html
Normal file
4
test/features/emojis/links.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
<p>this link <a href="http://www.example.com/some:apple:url">somelink</a></p>
|
||||
<p>emoji <a href="http://www.example.com/some:apple:url">🍎</a></p>
|
||||
<p><a href="http://www.example.com/some:apple:url">🍎</a></p>
|
||||
<p><a href="http://www.example.com/some:apple:url">🍎</a></p>
|
11
test/features/emojis/links.md
Normal file
11
test/features/emojis/links.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
this link [somelink](http://www.example.com/some:apple:url)
|
||||
|
||||
emoji [:apple:](http://www.example.com/some:apple:url)
|
||||
|
||||
[:apple:][apple]
|
||||
|
||||
[:apple:][]
|
||||
|
||||
|
||||
[apple]: http://www.example.com/some:apple:url
|
||||
[:apple:]: http://www.example.com/some:apple:url
|
2
test/features/emojis/simple.html
Normal file
2
test/features/emojis/simple.html
Normal file
|
@ -0,0 +1,2 @@
|
|||
<p>🍎 and 💋</p>
|
||||
<p>💋my🍎</p>
|
3
test/features/emojis/simple.md
Normal file
3
test/features/emojis/simple.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
:apple: and :kiss:
|
||||
|
||||
:kiss:my:apple:
|
1
test/features/emojis/simplifiedautolinks.html
Normal file
1
test/features/emojis/simplifiedautolinks.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p><a href="http://www.example.com/some:apple:url">http://www.example.com/some:apple:url</a></p>
|
1
test/features/emojis/simplifiedautolinks.md
Normal file
1
test/features/emojis/simplifiedautolinks.md
Normal file
|
@ -0,0 +1 @@
|
|||
http://www.example.com/some:apple:url
|
2
test/features/emojis/special.html
Normal file
2
test/features/emojis/special.html
Normal file
File diff suppressed because one or more lines are too long
3
test/features/emojis/special.md
Normal file
3
test/features/emojis/special.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
this is showdown's emoji :showdown:
|
||||
|
||||
and this is github's emoji :octocat:
|
|
@ -10,7 +10,8 @@ var bootstrap = require('../bootstrap.js'),
|
|||
openLinksInNewWindowSuite = bootstrap.getTestSuite('test/features/openLinksInNewWindow/'),
|
||||
disableForced4SpacesIndentedSublistsSuite = bootstrap.getTestSuite('test/features/disableForced4SpacesIndentedSublists/'),
|
||||
rawHeaderIdSuite = bootstrap.getTestSuite('test/features/rawHeaderId/'),
|
||||
rawPrefixHeaderIdSuite = bootstrap.getTestSuite('test/features/rawPrefixHeaderId/');
|
||||
rawPrefixHeaderIdSuite = bootstrap.getTestSuite('test/features/rawPrefixHeaderId/'),
|
||||
emojisSuite = bootstrap.getTestSuite('test/features/emojis/');
|
||||
|
||||
describe('makeHtml() features testsuite', function () {
|
||||
'use strict';
|
||||
|
@ -178,4 +179,19 @@ describe('makeHtml() features testsuite', function () {
|
|||
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||
}
|
||||
});
|
||||
|
||||
// test emojis support
|
||||
describe('emojis support', function () {
|
||||
var converter,
|
||||
suite = emojisSuite;
|
||||
for (var i = 0; i < suite.length; ++i) {
|
||||
if (suite[i].name === 'simplifiedautolinks') {
|
||||
converter = new showdown.Converter({emoji: true, simplifiedAutoLink: true});
|
||||
} else {
|
||||
converter = new showdown.Converter({emoji: true});
|
||||
}
|
||||
|
||||
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user