Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either enable emoji plugin or not #1726

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,6 @@ window.$docsify = {

Note that if you are running an external script, e.g. an embedded jsfiddle demo, make sure to include the [external-script](plugins.md?id=external-script) plugin.

## noEmoji

- type: `Boolean`

Disabled emoji parse.

```js
window.$docsify = {
noEmoji: true,
};
```

?> If this option is `false` but you don't want to emojify some specific colons, [refer to this](https://github.com/docsifyjs/docsify/issues/742#issuecomment-586313143)

## mergeNavbar

- type: `Boolean`
Expand Down
9 changes: 7 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,18 @@ Configure by `data-ga`.

## emoji

The default is to support parsing emoji. For example `:100:` will be parsed to :100:. But it is not precise because there is no matching non-emoji string. If you need to correctly parse the emoji string, you need install this plugin.
Emoji parsing is disabled by default.
To enable emoji parsing, you need to add the following plugin.

```html
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/emoji.min.js"></script>
```

?> If you don't want to parse to emoji, you can use __colon_<span>_</span> or `&#58;`. If you need to use in the title, we recommend using `&#58;`. For example, `&#58;100:`
Only [Github emojis](https://gist.github.com/rxaviers/7360908) are searched and replaced.

Code blocks are not parsed, thus :100: won't be rendered here: `:100:`.

?> If you don't want a specific emoji to be parsed, you can replace a colon by __colon_<span>_</span> or `&#58;`. If you need to use in the title, we recommend using `&#58;`. For example, `&#58;100:`

## External Script

Expand Down
1 change: 0 additions & 1 deletion src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export default function(vm) {
nameLink: window.location.pathname,
autoHeader: false,
executeScript: null,
noEmoji: false,
ga: '',
ext: '.md',
mergeNavbar: false,
Expand Down
2 changes: 1 addition & 1 deletion src/core/render/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Compiler {
html = compile.parser(text);
}

html = config.noEmoji ? html : emojify(html);
html = emojify(html);
slugify.clear();

return html;
Expand Down
16 changes: 5 additions & 11 deletions src/core/render/emojify.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { inBrowser } from '../util/env';

function replace(m, $1) {
return (
'<img class="emoji" src="https://github.githubassets.com/images/icons/emoji/' +
$1 +
'.png" alt="' +
$1 +
'" />'
);
}

export function emojify(text) {
if (!window.emojify) {
return text.replace(/__colon__/g, ':');
}

return text
.replace(/<(pre|template|code)[^>]*?>[\s\S]+?<\/(pre|template|code)>/g, m =>
m.replace(/:/g, '__colon__')
)
.replace(/:([a-z0-9_\-\+]+?):/g, (inBrowser && window.emojify) || replace)
.replace(/:([a-z0-9_\-\+]+?):/g, inBrowser && window.emojify)
.replace(/__colon__/g, ':');
}