mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
fix: Remove quote flattening on markdown serialization (#12774)
* fix: Remove quote flattening on markdown serialization closes #12773 * PR feedback
This commit is contained in:
1 parent
ebaaedb10e
commit
bd013dbfa5
4 files changed
+93
-5
No files matched your search
@@ -419,6 +419,40 @@ describe("documentUpdater", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should patch text retrieved via toMarkdown containing smart quotes and brackets", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
teamId: user.teamId,
|
||||
content: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [{ type: "text", text: "the cat’s “meow” [loud]" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
// findText is the exact text a client receives from retrieval.
|
||||
const findText = await DocumentHelper.toMarkdown(document, {
|
||||
includeTitle: false,
|
||||
});
|
||||
expect(findText).toBe("the cat’s “meow” [loud]");
|
||||
|
||||
const result = DocumentHelper.applyMarkdownToDocument(
|
||||
document,
|
||||
"quiet",
|
||||
TextEditMode.Patch,
|
||||
findText
|
||||
);
|
||||
|
||||
expect(result.content!.content![0]).toMatchObject({
|
||||
type: "paragraph",
|
||||
content: [{ type: "text", text: "quiet" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw when findText is not found in document", async () => {
|
||||
const user = await buildUser();
|
||||
const document = await buildDocument({
|
||||
|
||||
@@ -342,6 +342,61 @@ This is a [test paragraph](https://example.net)`,
|
||||
});
|
||||
|
||||
describe("toMarkdown", () => {
|
||||
it("should preserve smart quotes rather than flattening them", async () => {
|
||||
const document = await buildDocument({
|
||||
content: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [{ type: "text", text: "the cat’s “meow”" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const result = await DocumentHelper.toMarkdown(document, {
|
||||
includeTitle: false,
|
||||
});
|
||||
expect(result).toBe("the cat’s “meow”");
|
||||
});
|
||||
|
||||
it("should not escape standalone square brackets", async () => {
|
||||
const document = await buildDocument({
|
||||
content: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [{ type: "text", text: "one [two] three" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const result = await DocumentHelper.toMarkdown(document, {
|
||||
includeTitle: false,
|
||||
});
|
||||
expect(result).toBe("one [two] three");
|
||||
});
|
||||
|
||||
it("should escape literal inline-link syntax with nested brackets", async () => {
|
||||
const document = await buildDocument({
|
||||
content: {
|
||||
type: "doc",
|
||||
content: [
|
||||
{
|
||||
type: "paragraph",
|
||||
content: [{ type: "text", text: "nested [a[b]c](url) link" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const result = await DocumentHelper.toMarkdown(document, {
|
||||
includeTitle: false,
|
||||
});
|
||||
// Escaped so it is not re-parsed into a link on round-trip.
|
||||
expect(result).toBe("nested \\[a\\[b]c](url) link");
|
||||
});
|
||||
|
||||
it("should export bullet lists inside table cells with br tags", async () => {
|
||||
// Create a document with a table containing a bullet list in a cell
|
||||
// This tests the renderList inTable handling
|
||||
|
||||
@@ -211,10 +211,6 @@ export class DocumentHelper {
|
||||
const text = serializer
|
||||
.serialize(node)
|
||||
.replace(/(^|\n)\\(\n|$)/g, "\n\n")
|
||||
.replace(/“/g, '"')
|
||||
.replace(/”/g, '"')
|
||||
.replace(/‘/g, "'")
|
||||
.replace(/’/g, "'")
|
||||
.trim();
|
||||
|
||||
if (
|
||||
|
||||
@@ -547,7 +547,10 @@ export class MarkdownSerializerState {
|
||||
// content. If `startOfLine` is true, also escape characters that
|
||||
// has special meaning only at the start of the line.
|
||||
esc(str = "", startOfLine) {
|
||||
str = str.replace(/[`*\\~[\]]/g, "\\$&");
|
||||
str = str.replace(/[`*\\~]/g, "\\$&");
|
||||
// Only escape an opening square bracket when the same line later contains a
|
||||
// `](`, meaning it could otherwise be parsed as an inline link or image
|
||||
str = str.replace(/\[(?=[^\n]*\]\()/g, "\\$&");
|
||||
if (startOfLine) {
|
||||
str = str.replace(/^[:#\-*+]/, "\\$&").replace(/^(\d+)\./, "$1\\.");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user