diff --git a/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.test.ts b/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.test.ts index 1147f4358..10b0daeb2 100644 --- a/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.test.ts +++ b/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.test.ts @@ -1,7 +1,7 @@ jest.mock("@ckeditor/ckeditor5-utils/src/version") import ResourceLink from "@mitodl/ckeditor5-resource-link/src/link" -import Markdown from "./Markdown" +import Markdown, { MarkdownDataProcessor } from "./Markdown" import { createTestEditor, markdownTest } from "./test_util" import { turndownService } from "../turndown" @@ -46,4 +46,23 @@ describe("ResourceLink plugin", () => { '
' ) }) + + it("should serialize multiple links to and from markdown", async () => { + const editor = await getEditor("") + markdownTest( + editor, + 'dogs {{< resource_link uuid1 "woof" >}} cats {{< resource_link uuid2 "meow" >}}, cool', + '' + ) + }) + + it("[BUG] does not behave well if link title ends in backslash", async () => { + const editor = await getEditor("") + const { md2html } = (editor.data + .processor as unknown) as MarkdownDataProcessor + expect(md2html('{{< resource_link uuid123 "bad \\" >}}')).toBe( + // This is wrong. Should not end in </a> + '' + ) + }) }) diff --git a/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.ts b/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.ts index 07e026d85..f0378228c 100644 --- a/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.ts +++ b/static/js/lib/ckeditor/plugins/ResourceLinkMarkdownSyntax.ts @@ -5,13 +5,21 @@ import { editor } from "@ckeditor/ckeditor5-core" import MarkdownSyntaxPlugin from "./MarkdownSyntaxPlugin" import { TurndownRule } from "../../../types/ckeditor_markdown" -export const RESOURCE_LINK_SHORTCODE_REGEX = /{{< resource_link (\S+) "(.+)" >}}/g - import { RESOURCE_LINK_CKEDITOR_CLASS, RESOURCE_LINK } from "@mitodl/ckeditor5-resource-link/src/constants" +/** + * (\S+) to match and capture the UUID + * "(.*?)" to match and capture the label text + * + * Limitations: + * - gets fooled by label texts that include literal `" >}}` values. For + * example, < resource_link uuid123 "silly " >}} link" >}}. + */ +export const RESOURCE_LINK_SHORTCODE_REGEX = /{{< resource_link (\S+) "(.*?)" >}}/g + /** * Class for defining Markdown conversion rules for Resource links *