QQ、微信表情符号解析:字符串到图片URL

QQ WechaT EmotioN ParseR

嗯,这是一个很简单的小工具,作用是将网页中添加的QQ表情和或者微信表情字符串转化为表情图片。

快速!这是目前最快速的表情字符串转换JS库,使用前缀树(Trie)实现,对于限长的表情库,算法复杂度达到O(n)。 方便!无任何依赖,只需引入min.js即可使用。同时支持Node.js环境。 Demo example 1

输入:

/::)

输出:

<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/0.gif" alt="/::)">

效果:

example 2

输入:

I xx Gunzi, /::), No no no, I just xx xx/::B.

输出:

I xx Gunzi, <img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/0.gif" alt="/::)">, No no no, I just xx xx<img src="https://res.wx.qq.com/mpres/htmledition/images/icon/emotion/2.gif" alt="/::B">.

效果:

I xx Gunzi, , No no no, I just xx xx.

Usage

本工具对外暴露一个qqWechatEmotionParser()方法,此方法的输入是需要处理的字符串,输出是将字符表情转化为img标签的字符串。

浏览器环境

下载并引入https://github.com/buddys/qq-wechat-emotion-parser/blob/master/dist/qq-wechat-emotion-parser.min.js。

<script src="/path/to/qq-wechat-emotion-parser.min.js"></script>

调用window.qqWechatEmotionParser

var text = 'I xx Gunzi /::), No no no, I just xx xx/:<L>.'; var html = qqWechatEmotionParser(text); document.write(text); document.write('<br/>') document.write(html); Node环境

安装:

npm install qq-wechat-emotion-parser

使用:

var qqWechatEmotionParser = require('qq-wechat-emotion-parser'); var text = 'I xx Gunzi /::), No no no, I just xx xx/:<L>.'; var html = qqWechatEmotionParser(text); console.log(html); Contribution 贡献代码

欢迎通过Github提交issue或者贡献代码, 贡献代码前需要仔细阅读原代码尽量保持代码风格一致。

新增标签

表情在src/emotion.json文件下保存,通过编辑该json文件定义表情的字符表示以及图片源。需要注意以下两点:

表情的字符表示应该尽量避免产生歧义 图片托管应使用稳定,国内访问速度快的服务器 License

GPL V3.0

harttle, meriky @ Buddys Copyright (c) 2016

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。