mirror of
https://github.com/outline/outline.git
synced 2026-11-28 00:09:58 +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>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import type { Node } from "prosemirror-model";
|
|
import { MentionType } from "@shared/types";
|
|
import { parser } from "..";
|
|
|
|
function firstMention(markdown: string): Node | undefined {
|
|
const doc = parser.parse(markdown);
|
|
let mention: Node | undefined;
|
|
|
|
doc?.descendants((node: Node) => {
|
|
if (!mention && node.type.name === "mention") {
|
|
mention = node;
|
|
}
|
|
});
|
|
|
|
return mention;
|
|
}
|
|
|
|
describe("mention type rule", () => {
|
|
it("should resolve a GitHub issue link", () => {
|
|
const mention = firstMention(
|
|
"@[Fix parser](https://github.com/acme/infra/issues/2)"
|
|
);
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.Issue);
|
|
expect(mention?.attrs.href).toBe("https://github.com/acme/infra/issues/2");
|
|
expect(mention?.attrs.label).toBe("Fix parser");
|
|
});
|
|
|
|
it("should resolve a GitHub pull request link", () => {
|
|
const mention = firstMention(
|
|
"@[Add parser](https://github.com/acme/infra/pull/5)"
|
|
);
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.PullRequest);
|
|
});
|
|
|
|
it("should resolve a GitHub project link", () => {
|
|
const mention = firstMention(
|
|
"@[Roadmap](https://github.com/orgs/acme/projects/1)"
|
|
);
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.Project);
|
|
});
|
|
|
|
it("should leave a GitHub link to an unmentionable resource generic", () => {
|
|
const mention = firstMention("@[Repo](https://github.com/acme/infra)");
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.URL);
|
|
});
|
|
|
|
it("should leave a link no plugin recognizes generic", () => {
|
|
const mention = firstMention("@[Example](https://example.com/page)");
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.URL);
|
|
expect(mention?.attrs.href).toBe("https://example.com/page");
|
|
});
|
|
|
|
it("should not affect mention:// links", () => {
|
|
const mention = firstMention(
|
|
"@[John Doe](mention://a1b2c3d4-e5f6-7890-abcd-ef1234567890/user/f0e1d2c3-b4a5-6789-0abc-def123456789)"
|
|
);
|
|
|
|
expect(mention?.attrs.type).toBe(MentionType.User);
|
|
expect(mention?.attrs.href).toBeUndefined();
|
|
});
|
|
|
|
it("should not convert a link without an @ prefix", () => {
|
|
expect(
|
|
firstMention("[Fix parser](https://github.com/acme/infra/issues/2)")
|
|
).toBeUndefined();
|
|
});
|
|
});
|