Emojify markdown

This commit is contained in:
Jori Lallo
2016-06-05 23:24:05 -07:00
parent 6011de49a0
commit 33b823b66e
6 changed files with 30 additions and 2 deletions

View File

@ -40,6 +40,7 @@
"css-loader": "^0.23.1",
"debug": "^2.2.0",
"dotenv": "^2.0.0",
"emoji-name-map": "^1.1.1",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^5.0.0",
"eslint-plugin-react": "^3.16.1",

View 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)
);

View File

@ -2,6 +2,7 @@ import { observable, action, computed, autorun } from 'mobx';
import { client } from 'utils/ApiClient';
import localforage from 'localforage';
import { browserHistory } from 'react-router';
import emojify from 'utils/emojify';
const DOCUMENT_EDIT_SETTINGS = 'DOCUMENT_EDIT_SETTINGS';
@ -10,7 +11,7 @@ const parseHeader = (text) => {
const match = firstLine.match(/^#+ +(.*)$/);
if (match) {
return match[1];
return emojify(match[1]);
}
}

File diff suppressed because one or more lines are too long

16
src/utils/emojify.js Normal file
View 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;

View File

@ -1,6 +1,7 @@
import slug from 'slug';
import marked, { Renderer } from 'marked';
import highlight from 'highlight.js';
import emojify from './emojify';
slug.defaults.mode ='rfc3986';
@ -35,7 +36,7 @@ marked.setOptions({
// TODO: This is syncronous and can be costly
const convertToMarkdown = (text) => {
return marked(text);
return marked(emojify(text));
};
export {