fix: Remove no longer required unescaping, closes #5555

This commit is contained in:
Tom Moor
2023-07-14 21:46:31 -04:00
parent 5c83070941
commit 5dcd7a74ca
5 changed files with 3 additions and 18 deletions

View File

@@ -6,11 +6,6 @@ it("should trim the title", () => {
it("should extract first title", () => {
expect(parseTitle(`# Title one\n# Title two`).title).toBe("Title one");
});
it("should remove escape characters", () => {
expect(parseTitle(`# Thing \\- one`).title).toBe("Thing - one");
expect(parseTitle(`# \\[wip\\] Title`).title).toBe("[wip] Title");
expect(parseTitle(`# \\> Title`).title).toBe("> Title");
});
it("should parse emoji if first character", () => {
const parsed = parseTitle(`# 😀 Title`);
expect(parsed.title).toBe("😀 Title");

View File

@@ -1,15 +1,11 @@
import emojiRegex from "emoji-regex";
import unescape from "./unescape";
export default function parseTitle(text = "") {
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 = unescape(trimmedTitle);
const title = firstLine.replace(/^#/, "").trim();
// find and extract first emoji
const matches = regex.exec(title);

View File

@@ -1,4 +0,0 @@
const unescape = (text: string) =>
text.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, "$1").replace(/\n\\\n/g, "\n\n");
export default unescape;