Emojify markdown
This commit is contained in:
@ -40,6 +40,7 @@
|
|||||||
"css-loader": "^0.23.1",
|
"css-loader": "^0.23.1",
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"dotenv": "^2.0.0",
|
"dotenv": "^2.0.0",
|
||||||
|
"emoji-name-map": "^1.1.1",
|
||||||
"eslint": "^1.10.3",
|
"eslint": "^1.10.3",
|
||||||
"eslint-config-airbnb": "^5.0.0",
|
"eslint-config-airbnb": "^5.0.0",
|
||||||
"eslint-plugin-react": "^3.16.1",
|
"eslint-plugin-react": "^3.16.1",
|
||||||
|
8
scripts/update_emoji_mapping.js
Normal file
8
scripts/update_emoji_mapping.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var mapping = require('emoji-name-map');
|
||||||
|
|
||||||
|
fs.writeFile(
|
||||||
|
path.join(__dirname, '../src/utils/emoji-mapping.json'),
|
||||||
|
JSON.stringify(mapping.emoji)
|
||||||
|
);
|
@ -2,6 +2,7 @@ import { observable, action, computed, autorun } from 'mobx';
|
|||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import localforage from 'localforage';
|
import localforage from 'localforage';
|
||||||
import { browserHistory } from 'react-router';
|
import { browserHistory } from 'react-router';
|
||||||
|
import emojify from 'utils/emojify';
|
||||||
|
|
||||||
const DOCUMENT_EDIT_SETTINGS = 'DOCUMENT_EDIT_SETTINGS';
|
const DOCUMENT_EDIT_SETTINGS = 'DOCUMENT_EDIT_SETTINGS';
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ const parseHeader = (text) => {
|
|||||||
const match = firstLine.match(/^#+ +(.*)$/);
|
const match = firstLine.match(/^#+ +(.*)$/);
|
||||||
|
|
||||||
if (match) {
|
if (match) {
|
||||||
return match[1];
|
return emojify(match[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
src/utils/emoji-mapping.json
Normal file
1
src/utils/emoji-mapping.json
Normal file
File diff suppressed because one or more lines are too long
16
src/utils/emojify.js
Normal file
16
src/utils/emojify.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import emojiMapping from './emoji-mapping.json';
|
||||||
|
|
||||||
|
const EMOJI_REGEX = /:([A-Za-z0-9_\-\+]+?):/gm;
|
||||||
|
|
||||||
|
const emojify = (text) => {
|
||||||
|
const emojis = text.match(EMOJI_REGEX) || [];
|
||||||
|
let emojifiedText = text;
|
||||||
|
|
||||||
|
emojifiedText = text.replace(EMOJI_REGEX, (match, p1, offset, string) => {
|
||||||
|
return emojiMapping[p1] || match;
|
||||||
|
});
|
||||||
|
|
||||||
|
return emojifiedText;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default emojify;
|
@ -1,6 +1,7 @@
|
|||||||
import slug from 'slug';
|
import slug from 'slug';
|
||||||
import marked, { Renderer } from 'marked';
|
import marked, { Renderer } from 'marked';
|
||||||
import highlight from 'highlight.js';
|
import highlight from 'highlight.js';
|
||||||
|
import emojify from './emojify';
|
||||||
|
|
||||||
slug.defaults.mode ='rfc3986';
|
slug.defaults.mode ='rfc3986';
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ marked.setOptions({
|
|||||||
|
|
||||||
// TODO: This is syncronous and can be costly
|
// TODO: This is syncronous and can be costly
|
||||||
const convertToMarkdown = (text) => {
|
const convertToMarkdown = (text) => {
|
||||||
return marked(text);
|
return marked(emojify(text));
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Reference in New Issue
Block a user