mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-10 09:12:39 +00:00
Add emoji highlighting to editor
This commit is contained in:
@@ -5,6 +5,7 @@ const createClass = require('create-react-class');
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
const Markdown = require('../../../shared/naturalcrit/markdown.js');
|
||||||
|
|
||||||
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
|
const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
|
||||||
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
const SnippetBar = require('./snippetbar/snippetbar.jsx');
|
||||||
@@ -219,6 +220,33 @@ const Editor = createClass({
|
|||||||
endCh = match.index+match[0].length;
|
endCh = match.index+match[0].length;
|
||||||
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
|
codeMirror.markText({ line: lineNumber, ch: 0 }, { line: lineNumber, ch: endCh }, { className: 'block' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emojis
|
||||||
|
if(line.match(/:[^\s:]+:/g)) {
|
||||||
|
let startIndex = line.indexOf(':');
|
||||||
|
const emojiRegex = /:[^\s:]+:/gy;
|
||||||
|
|
||||||
|
while (startIndex >= 0) {
|
||||||
|
emojiRegex.lastIndex = startIndex;
|
||||||
|
if (match) {
|
||||||
|
let tokens = Markdown.marked.lexer(match[0]);
|
||||||
|
tokens = tokens[0].tokens.filter(t => t.type == 'emoji')
|
||||||
|
if (!tokens.length)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let startPos = { line: lineNumber, ch: match.index };
|
||||||
|
let endPos = { line: lineNumber, ch: match.index + match[0].length };
|
||||||
|
|
||||||
|
// Iterate over conflicting marks and clear them
|
||||||
|
var marks = codeMirror.findMarks(startPos, endPos);
|
||||||
|
marks.forEach(function(marker) {
|
||||||
|
marker.clear();
|
||||||
|
});
|
||||||
|
codeMirror.markText(startPos, endPos, { className: 'emoji' });
|
||||||
|
}
|
||||||
|
startIndex = line.indexOf(':', Math.max(startIndex + 1, emojiRegex.lastIndex));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,6 +43,13 @@
|
|||||||
font-weight : bold;
|
font-weight : bold;
|
||||||
color : green;
|
color : green;
|
||||||
}
|
}
|
||||||
|
.emoji:not(.cm-comment) {
|
||||||
|
align-self : center;
|
||||||
|
margin-left : 2px;
|
||||||
|
color : hsl(300, 100%, 14%);
|
||||||
|
background : #ffa2ff;
|
||||||
|
border-radius : 6px;
|
||||||
|
}
|
||||||
.superscript:not(.cm-comment) {
|
.superscript:not(.cm-comment) {
|
||||||
font-weight : bold;
|
font-weight : bold;
|
||||||
color : goldenrod;
|
color : goldenrod;
|
||||||
|
|||||||
Reference in New Issue
Block a user