This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
outline/shared/utils/parseTitle.js
Tom Moor 6a0a22a636 Updated parseTitle to remove escape characters
Tests pass, however the JS running in the browser appears to be behaving differently. Not got to the bottom of it yet
2018-06-03 22:07:41 -04:00

22 lines
662 B
JavaScript

// @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 trimmedTitle = firstLine.replace(/^#/, '').trim();
// remove any escape characters
const title = trimmedTitle.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, '$&');
// 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 };
}