fix: Remove no longer required unescaping, closes #5555
This commit is contained in:
@@ -13,7 +13,6 @@ import {
|
|||||||
getCurrentTimeAsString,
|
getCurrentTimeAsString,
|
||||||
unicodeCLDRtoBCP47,
|
unicodeCLDRtoBCP47,
|
||||||
} from "@shared/utils/date";
|
} from "@shared/utils/date";
|
||||||
import unescape from "@shared/utils/unescape";
|
|
||||||
import { parser, schema } from "@server/editor";
|
import { parser, schema } from "@server/editor";
|
||||||
import { trace } from "@server/logging/tracing";
|
import { trace } from "@server/logging/tracing";
|
||||||
import type Document from "@server/models/Document";
|
import type Document from "@server/models/Document";
|
||||||
@@ -83,7 +82,7 @@ export default class DocumentHelper {
|
|||||||
* @returns The document title and content as a Markdown string
|
* @returns The document title and content as a Markdown string
|
||||||
*/
|
*/
|
||||||
static toMarkdown(document: Document | Revision) {
|
static toMarkdown(document: Document | Revision) {
|
||||||
const text = unescape(document.text);
|
const text = document.text.replace(/\n\\\n/g, "\n\n");
|
||||||
|
|
||||||
if (document.version) {
|
if (document.version) {
|
||||||
return `# ${document.title}\n\n${text}`;
|
return `# ${document.title}\n\n${text}`;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { find, map } from "lodash";
|
|||||||
import queryParser from "pg-tsquery";
|
import queryParser from "pg-tsquery";
|
||||||
import { Op, QueryTypes, WhereOptions } from "sequelize";
|
import { Op, QueryTypes, WhereOptions } from "sequelize";
|
||||||
import { DateFilter } from "@shared/types";
|
import { DateFilter } from "@shared/types";
|
||||||
import unescape from "@shared/utils/unescape";
|
|
||||||
import { sequelize } from "@server/database/sequelize";
|
import { sequelize } from "@server/database/sequelize";
|
||||||
import Collection from "@server/models/Collection";
|
import Collection from "@server/models/Collection";
|
||||||
import Document from "@server/models/Document";
|
import Document from "@server/models/Document";
|
||||||
@@ -410,7 +409,7 @@ export default class SearchHelper {
|
|||||||
return {
|
return {
|
||||||
results: map(results, (result) => ({
|
results: map(results, (result) => ({
|
||||||
ranking: result.searchRanking,
|
ranking: result.searchRanking,
|
||||||
context: removeMarkdown(unescape(result.searchContext), {
|
context: removeMarkdown(result.searchContext, {
|
||||||
stripHTML: false,
|
stripHTML: false,
|
||||||
}),
|
}),
|
||||||
document: find(documents, {
|
document: find(documents, {
|
||||||
|
|||||||
@@ -6,11 +6,6 @@ it("should trim the title", () => {
|
|||||||
it("should extract first title", () => {
|
it("should extract first title", () => {
|
||||||
expect(parseTitle(`# Title one\n# Title two`).title).toBe("Title one");
|
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", () => {
|
it("should parse emoji if first character", () => {
|
||||||
const parsed = parseTitle(`# 😀 Title`);
|
const parsed = parseTitle(`# 😀 Title`);
|
||||||
expect(parsed.title).toBe("😀 Title");
|
expect(parsed.title).toBe("😀 Title");
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import emojiRegex from "emoji-regex";
|
import emojiRegex from "emoji-regex";
|
||||||
import unescape from "./unescape";
|
|
||||||
|
|
||||||
export default function parseTitle(text = "") {
|
export default function parseTitle(text = "") {
|
||||||
const regex = emojiRegex();
|
const regex = emojiRegex();
|
||||||
|
|
||||||
// find and extract title
|
// find and extract title
|
||||||
const firstLine = text.trim().split(/\r?\n/)[0];
|
const firstLine = text.trim().split(/\r?\n/)[0];
|
||||||
const trimmedTitle = firstLine.replace(/^#/, "").trim();
|
const title = firstLine.replace(/^#/, "").trim();
|
||||||
|
|
||||||
// remove any escape characters
|
|
||||||
const title = unescape(trimmedTitle);
|
|
||||||
|
|
||||||
// find and extract first emoji
|
// find and extract first emoji
|
||||||
const matches = regex.exec(title);
|
const matches = regex.exec(title);
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
const unescape = (text: string) =>
|
|
||||||
text.replace(/\\([\\`*{}[\]()#+\-.!_>])/g, "$1").replace(/\n\\\n/g, "\n\n");
|
|
||||||
|
|
||||||
export default unescape;
|
|
||||||
Reference in New Issue
Block a user