mirror of
https://github.com/outline/outline.git
synced 2026-11-30 09:00:18 +03:00
* checkpoint * feat: Convert @ prefixed links to mentions on server Markdown writes A Markdown link preceded by "@" now becomes a mention when brought in through the documents API, MCP, or an import, so an exported mention survives a round trip instead of degrading to a plain link. The editor rule creates a generic mention carrying the href, and the type of resource it points at is resolved by the plugin that recognizes the URL through a new MentionProvider hook. Mentions of external resources also serialize to their real URL rather than a mention:// URI, so the reference resolves outside of Outline. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: Escape values interpolated into rendered mention HTML markdown-it leaves markup in a link label intact when html is disabled, so the label and attributes are escaped before being written into the tag. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
165 lines
4.8 KiB
TypeScript
165 lines
4.8 KiB
TypeScript
import { MentionType } from "../../types";
|
|
import { schema, serializer } from "../../test/editor";
|
|
|
|
const id = "0c440212-8b40-49fa-8a64-2548d6b60d59";
|
|
const modelId = "c85a0d80-3a89-4b25-a0cd-e7fc83f0d226";
|
|
|
|
const serializeMention = (
|
|
attrs: Record<string, unknown>,
|
|
options?: { commonMark?: boolean }
|
|
) => {
|
|
const doc = schema.nodeFromJSON({
|
|
type: "doc",
|
|
content: [
|
|
{
|
|
type: "paragraph",
|
|
content: [{ type: "mention", attrs: { id, modelId, ...attrs } }],
|
|
},
|
|
],
|
|
});
|
|
return serializer.serialize(doc, options).trim();
|
|
};
|
|
|
|
describe("Mention serialization", () => {
|
|
describe("markdown leaving Outline", () => {
|
|
it("serializes an issue mention as an @ prefixed link to the external url", () => {
|
|
expect(
|
|
serializeMention(
|
|
{
|
|
type: MentionType.Issue,
|
|
label: "Epic 1: Control plane Helm chart",
|
|
href: "https://github.com/acme/infra/issues/2",
|
|
},
|
|
{ commonMark: true }
|
|
)
|
|
).toBe(
|
|
"@[Epic 1: Control plane Helm chart](https://github.com/acme/infra/issues/2)"
|
|
);
|
|
});
|
|
|
|
it("serializes a pull request mention as an @ prefixed link to the external url", () => {
|
|
expect(
|
|
serializeMention(
|
|
{
|
|
type: MentionType.PullRequest,
|
|
label: "Add Helm chart",
|
|
href: "https://github.com/acme/infra/pull/42",
|
|
},
|
|
{ commonMark: true }
|
|
)
|
|
).toBe("@[Add Helm chart](https://github.com/acme/infra/pull/42)");
|
|
});
|
|
|
|
it("serializes a project mention as an @ prefixed link to the external url", () => {
|
|
expect(
|
|
serializeMention(
|
|
{
|
|
type: MentionType.Project,
|
|
label: "Q3 Roadmap",
|
|
href: "https://github.com/orgs/acme/projects/7",
|
|
},
|
|
{ commonMark: true }
|
|
)
|
|
).toBe("@[Q3 Roadmap](https://github.com/orgs/acme/projects/7)");
|
|
});
|
|
|
|
it("serializes a url mention as an @ prefixed link", () => {
|
|
expect(
|
|
serializeMention(
|
|
{
|
|
type: MentionType.URL,
|
|
label: "Example",
|
|
href: "https://example.com/page",
|
|
},
|
|
{ commonMark: true }
|
|
)
|
|
).toBe("@[Example](https://example.com/page)");
|
|
});
|
|
|
|
it("sanitizes an unsafe url", () => {
|
|
const markdown = serializeMention(
|
|
{
|
|
type: MentionType.Issue,
|
|
label: "Epic 1",
|
|
// oxlint-disable-next-line no-script-url
|
|
href: "javascript:alert(1)",
|
|
},
|
|
{ commonMark: true }
|
|
);
|
|
expect(markdown).not.toContain("(javascript:");
|
|
});
|
|
|
|
it("keeps the mention:// format when there is no url to link to", () => {
|
|
expect(
|
|
serializeMention(
|
|
{ type: MentionType.Issue, label: "Epic 1" },
|
|
{ commonMark: true }
|
|
)
|
|
).toBe(`@[Epic 1](mention://${id}/issue/${modelId})`);
|
|
});
|
|
|
|
it("keeps the mention:// format for internal mentions", () => {
|
|
expect(
|
|
serializeMention(
|
|
{ type: MentionType.User, label: "John Doe" },
|
|
{ commonMark: true }
|
|
)
|
|
).toBe(`@[John Doe](mention://${id}/user/${modelId})`);
|
|
});
|
|
});
|
|
|
|
describe("markdown staying within Outline", () => {
|
|
it("keeps the mention:// format for an issue mention", () => {
|
|
expect(
|
|
serializeMention({
|
|
type: MentionType.Issue,
|
|
label: "Epic 1: Control plane Helm chart",
|
|
href: "https://github.com/acme/infra/issues/2",
|
|
})
|
|
).toBe(
|
|
`@[Epic 1: Control plane Helm chart](mention://${id}/issue/${modelId})`
|
|
);
|
|
});
|
|
|
|
it("keeps the mention:// format for a pull request mention", () => {
|
|
expect(
|
|
serializeMention({
|
|
type: MentionType.PullRequest,
|
|
label: "Add Helm chart",
|
|
href: "https://github.com/acme/infra/pull/42",
|
|
})
|
|
).toBe(`@[Add Helm chart](mention://${id}/pull_request/${modelId})`);
|
|
});
|
|
|
|
it("keeps the mention:// format for a project mention", () => {
|
|
expect(
|
|
serializeMention({
|
|
type: MentionType.Project,
|
|
label: "Q3 Roadmap",
|
|
href: "https://github.com/orgs/acme/projects/7",
|
|
})
|
|
).toBe(`@[Q3 Roadmap](mention://${id}/project/${modelId})`);
|
|
});
|
|
});
|
|
|
|
describe("document and collection mentions", () => {
|
|
it("serializes a document mention as an internal link", () => {
|
|
expect(
|
|
serializeMention(
|
|
{ type: MentionType.Document, label: "Onboarding" },
|
|
{ commonMark: true }
|
|
)
|
|
).toBe(`[Onboarding](/doc/${modelId})`);
|
|
});
|
|
|
|
it("serializes a collection mention as an internal link", () => {
|
|
expect(
|
|
serializeMention(
|
|
{ type: MentionType.Collection, label: "Engineering" },
|
|
{ commonMark: true }
|
|
)
|
|
).toBe(`[Engineering](/collection/${modelId})`);
|
|
});
|
|
});
|
|
});
|