Files
outline/server/editor/index.ts
T
Tom MoorandClaude Opus 5 f49b047648 feat: Convert @ prefixed Markdown links to mentions on server writes (#13403)
* 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>
2026-08-27 17:42:28 -04:00

86 lines
2.6 KiB
TypeScript

import data from "@emoji-mart/data";
import type { EmojiMartData } from "@emoji-mart/data";
import { Schema } from "prosemirror-model";
import type { Editor } from "~/editor";
import defaultEmbeds from "@shared/editor/embeds";
import ExtensionManager from "@shared/editor/lib/ExtensionManager";
import { populateEmojiData } from "@shared/editor/lib/emoji";
import {
basicExtensions,
richExtensions,
withComments,
} from "@shared/editor/nodes";
import CodeBlock from "@shared/editor/nodes/CodeBlock";
import CodeFence from "@shared/editor/nodes/CodeFence";
import Mention from "@shared/editor/nodes/Mention";
import mentionRules from "./rules/mentions";
populateEmojiData(data as EmojiMartData);
// Server-side parsing/serializing only requires schema and a few static props,
// but the Extension API expects a full Editor. This stub satisfies bindEditor
// without instantiating the React component.
const stubEditor = (s: Schema): Editor =>
({
schema: s,
props: {
theme: { isDark: false },
embeds: defaultEmbeds,
embedsDisabled: false,
},
}) as unknown as Editor;
const extensions = withComments(richExtensions);
export const extensionManager = new ExtensionManager(extensions);
export const schema = new Schema({
nodes: extensionManager.nodes,
marks: extensionManager.marks,
});
for (const extension of extensionManager.extensions) {
extension.bindEditor(stubEditor(schema));
}
export const parser = extensionManager.parser({
schema,
plugins: [...extensionManager.rulePlugins, mentionRules],
});
export const serializer = extensionManager.serializer();
export const plugins = extensionManager.plugins;
export const basicExtensionManager = new ExtensionManager(basicExtensions);
export const basicSchema = new Schema({
nodes: basicExtensionManager.nodes,
marks: basicExtensionManager.marks,
});
for (const extension of basicExtensionManager.extensions) {
extension.bindEditor(stubEditor(basicSchema));
}
export const basicParser = basicExtensionManager.parser({
schema: basicSchema,
plugins: basicExtensionManager.rulePlugins,
});
const commentExtensions = [...basicExtensions, CodeBlock, CodeFence, Mention];
export const commentExtensionManager = new ExtensionManager(commentExtensions);
export const commentSchema = new Schema({
nodes: commentExtensionManager.nodes,
marks: commentExtensionManager.marks,
});
for (const extension of commentExtensionManager.extensions) {
extension.bindEditor(stubEditor(commentSchema));
}
export const commentParser = commentExtensionManager.parser({
schema: commentSchema,
plugins: [...commentExtensionManager.rulePlugins, mentionRules],
});