0%

Hexo中添加emoji表情

💯🔢😋🚵🔜🛥🏞🌃🎆📘❎🇨🇳🐱🌕🌖🌗🌘🌑🌒🌓🌔0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟

本文介绍如何让Hexo支持emoji表情。

首先,要知道markdown 变成html的转换器叫做markdown渲染器。在Hexo中默认的markdown渲染器使用的是hexo-renderer-marked,此渲染器不支持插件扩展;要让hexo支持emoji,则需要将渲染器更换为支持插件扩展的渲染器。网络博主们推荐hexo-renderer-markdown-it,该渲染器可通过使用markdown-it-emoji插件来支持emoji渲染。

安装

三步:卸载旧渲染器,安装新渲染器,安装插件

卸载hexo-renderer-marked

切换到本地blog目录

1
npm un hexo-renderer-marked --save

安装和配置hexo-renderer-markdown-it渲染器

安装渲染器

1
npm i hexo-renderer-markdown-it --save

渲染器配置:

  1. 在站点配置文件_config.yml中添加如下代码:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    # Markdown-it config
    ## Docs: https://github.com/celsomiranda/hexo-renderer-markdown-it/wiki
    markdown:
    render:
    html: true
    xhtmlOut: false
    breaks: true
    linkify: true
    typographer: true
    quotes: '“”‘’'
    plugins:
    - markdown-it-abbr
    - markdown-it-footnote
    - markdown-it-ins
    - markdown-it-sub
    - markdown-it-sup
    anchors:
    level: 2
    collisionSuffix: 'v'
    permalink: true
    permalinkClass: header-anchor
    permalinkSide: 'left'
    permalinkSymbol:

    以上配置详细说明如下,或见Advanced Configuration

    • markdown:
    • render
    • plugin
    • anchors
  2. 安装markdown-it-checkbox插件

    1
    npm install markdown-it-checkbox --save
  3. 在站点配置文件_config.yml文件中的markdown.plugins添加- markdown-it-checkbox,即:

    1
    2
    3
    4
    5
    6
    7
    plugins:
    - markdown-it-abbr
    - markdown-it-footnote
    - markdown-it-ins
    - markdown-it-sub
    - markdown-it-sup
    - markdown-it-checkbox # 本行启用了checkbox插件

    示例:


    语法:

    1
    2
    [ ] 这是未勾选的checkbox
    [x] 这是已勾选的checkbox

安装和配置markdown-it-emoji插件

安装插件

1
2
# 安装markdown-it-emoji插件
npm install markdown-it-emoji --save

在站点配置文件_config.yml文件中的markdown.plugins添加- markdown-it-emoji,即:

1
2
3
4
5
6
7
8
plugins:
- markdown-it-abbr
- markdown-it-footnote
- markdown-it-ins
- markdown-it-sub
- markdown-it-sup
- markdown-it-checkbox # 本行启用了checkbox插件
- markdown-it-emoji # 本行启用了emoji插件

配置插件 & 优化Emoji样式

  1. 安装twemoji

    1
    npm install twemoji
  2. 配置

    node_modules\markdown-it-emoji\index.js目录下添加代码:

    1
    2
    3
    4
    5
    var twemoji           = require('twemoji')  //添加twemoji
    //使用twemoji渲染
    md.renderer.rules.emoji = function(token, idx) {
    return twemoji.parse(token[idx].content);
    };

    完整代码为:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    'use strict';

    var emojies_defs = require('./lib/data/full.json');
    var emojies_shortcuts = require('./lib/data/shortcuts');
    var emoji_html = require('./lib/render');
    var emoji_replace = require('./lib/replace');
    var normalize_opts = require('./lib/normalize_opts');
    var twemoji = require('twemoji') //添加twemoji

    module.exports = function emoji_plugin(md, options) {
    var defaults = {
    defs: emojies_defs,
    shortcuts: emojies_shortcuts,
    enabled: []
    };

    var opts = normalize_opts(md.utils.assign({}, defaults, options || {}));

    md.renderer.rules.emoji = emoji_html;

    //使用twemoji渲染
    md.renderer.rules.emoji = function(token, idx) {
    return twemoji.parse(token[idx].content);
    };

    md.core.ruler.push('emoji', emoji_replace(md, opts.defs, opts.shortcuts, opts.scanRE, opts.replaceRE));
    };
  3. 在themes/next/source/css/main.styl文件中添加Emoji样式:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    /*emoji样式*/
    .emoji { height: 1.2em;}
    img.emoji{
    margin: 0 .05em 0 .1em !important;
    vertical-align: -0.1em;
    //override theme default style
    padding:0px !important;
    border:none !important;
    display:inline !important;
    }

    示例:

    💯🔢😋🚵🔜🛥🏞🌃🎆📘❎🇨🇳🐱🌕🌖🌗🌘🌑🌒🌓🌔0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟🕐🕑🕒🕓🕔🕕🕖🕗🕘🕙🕚🕛🕜🕝🕞🕟🕠🕡🕢🕣🕤🕥🕦🕧🇸🇨✝️☪️☮️🕉☸️✡️🔯🕎☯️✡️☦️⚾️

    源代码:

    1
    2
    3
    4
    5
    6
    7
    :100::1234::yum::mountain_biking_man::soon::motor_boat::national_park::night_with_stars::fireworks::blue_book:
    :negative_squared_cross_mark::cn::cat::full_moon::waning_gibbous_moon::last_quarter_moon::waning_crescent_moon:
    :new_moon::waxing_crescent_moon::first_quarter_moon::waxing_gibbous_moon::zero::one::two::three::four::five::six:
    :seven::eight::nine::keycap_ten::clock1::clock2::clock3::clock4::clock5::clock6::clock7::clock8::clock9::clock10:
    :clock11::clock12::clock130::clock230::clock330::clock430::clock530::clock630::clock730::clock830::clock930:
    :clock1030::clock1130::clock1230::seychelles::latin_cross::star_and_crescent::peace_symbol::om::wheel_of_dharma:
    :star_of_david::six_pointed_star::menorah::yin_yang::star_of_david::orthodox_cross::baseball:

    插件地址:

    Emoji表情检索:

Emoji and code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
😊 :blush:	😃 :smiley:	☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
😴 :sleeping: 😟 :worried: 😦 :frowning:
😧 :anguished: 😮 :open_mouth: 😬 :grimacing:
😕 :confused: 😯 :hushed: 😑 :expressionless:
😒 :unamused: 😅 :sweat_smile: 😓 :sweat:
😥 :disappointed_relieved: 😩 :weary: 😔 :pensive:
😞 :disappointed: 😖 :confounded: 😨 :fearful:
😰 :cold_sweat: 😣 :persevere: 😢 :cry:
😭 :sob: 😂 :joy: 😲 :astonished:
😱 :scream: :neckbeard: :neckbeard: 😫 :tired_face:
😠 :angry: 😡 :rage: 😤 :triumph:
😪 :sleepy: 😋 :yum: 😷 :mask:
😎 :sunglasses: 😵 :dizzy_face: 👿 :imp:
😈 :smiling_imp: 😐 :neutral_face: 😶 :no_mouth:
😇 :innocent: 👽 :alien: 💛 :yellow_heart:
💙 :blue_heart: 💜 :purple_heart: ❤️ :heart:
💚 :green_heart: 💔 :broken_heart: 💓 :heartbeat:
💗 :heartpulse: 💕 :two_hearts: 💞 :revolving_hearts:
💘 :cupid: 💖 :sparkling_heart: ✨ :sparkles:
⭐️ :star: 🌟 :star2: 💫 :dizzy:
💥 :boom: 💥 :collision: 💢 :anger:
❗️ :exclamation: ❓ :question: ❕ :grey_exclamation:
❔ :grey_question: 💤 :zzz: 💨 :dash:
💦 :sweat_drops: 🎶 :notes: 🎵 :musical_note:
🔥 :fire: 💩 :hankey: 💩 :poop:
💩 :shit: 👍 :+1: 👍 :thumbsup:
👎 :-1: 👎 :thumbsdown: 👌 :ok_hand:
👊 :punch: 👊 :facepunch: ✊ :fist:
✌️ :v: 👋 :wave: ✋ :hand:
✋ :raised_hand: 👐 :open_hands: ☝️ :point_up:
👇 :point_down: 👈 :point_left: 👉 :point_right:
🙌 :raised_hands: 🙏 :pray: 👆 :point_up_2:
👏 :clap: 💪 :muscle: 🤘 :metal:
🖕 :fu: 🚶 :walking: 🏃 :runner:
🏃 :running: 👫 :couple: 👪 :family:
👬 :two_men_holding_hands: 👭 :two_women_holding_hands: 💃 :dancer:
👯 :dancers: 🙆 :ok_woman: 🙅 :no_good:
💁 :information_desk_person: 🙋 :raising_hand: 👰 :bride_with_veil:
🙎 :person_with_pouting_face: 🙍 :person_frowning: 🙇 :bow:
:couplekiss: :couplekiss: 💑 :couple_with_heart: 💆 :massage:
💇 :haircut: 💅 :nail_care: 👦 :boy:
👧 :girl: 👩 :woman: 👨 :man:
👶 :baby: 👵 :older_woman: 👴 :older_man:
👱 :person_with_blond_hair: 👲 :man_with_gua_pi_mao: 👳 :man_with_turban:
👷 :construction_worker: 👮 :cop: 👼 :angel:
👸 :princess: 😺 :smiley_cat: 😸 :smile_cat:
😻 :heart_eyes_cat: 😽 :kissing_cat: 😼 :smirk_cat:
🙀 :scream_cat: 😿 :crying_cat_face: 😹 :joy_cat:
😾 :pouting_cat: 👹 :japanese_ogre: 👺 :japanese_goblin:
🙈 :see_no_evil: 🙉 :hear_no_evil: 🙊 :speak_no_evil:
💂 :guardsman: 💀 :skull: 🐾 :feet:
👄 :lips: 💋 :kiss: 💧 :droplet:
👂 :ear: 👀 :eyes: 👃 :nose:
👅 :tongue: 💌 :love_letter: 👤 :bust_in_silhouette:
👥 :busts_in_silhouette: 💬 :speech_balloon: 💭 :thought_balloon:

参考资料

https://www.jianshu.com/p/f9e57ecca150

https://vxiaozhe1998.gitee.io/2020/03/25/HEXO下的锚点标题与Emoji表情/#more

https://blog.csdn.net/weixin_30745641/article/details/95686757