Align title correctly when first character is emoji

This commit is contained in:
Tom Moor
2017-07-29 16:15:04 -07:00
parent cfcdae8aa0
commit 297bf850c2
9 changed files with 51 additions and 17 deletions

18
shared/parseTitle.js Normal file
View File

@ -0,0 +1,18 @@
// @flow
import emojiRegex from 'emoji-regex';
export default function parseTitle(text: string = '') {
const regex = emojiRegex();
// find and extract title
const firstLine = text.trim().split(/\r?\n/)[0];
const title = firstLine.replace(/^#/, '').trim();
// find and extract first emoji
const matches = regex.exec(title);
const firstEmoji = matches ? matches[0] : null;
const startsWithEmoji = firstEmoji && title.startsWith(firstEmoji);
const emoji = startsWithEmoji ? firstEmoji : undefined;
return { title, emoji };
}