Skip to content

Commit

Permalink
emojify: simply either enable emojis or not
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoKaPeek committed Jan 17, 2022
1 parent 719dcbe commit a52946f
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
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, ':');
}

0 comments on commit a52946f

Please sign in to comment.