mirror of
https://github.com/outline/outline.git
synced 2026-01-06 11:09:55 -06:00
feat: Convert attachment links to absolute when copying Markdown (#9873)
This commit is contained in:
@@ -677,7 +677,13 @@ export default class Document extends ArchivableModel implements Searchable {
|
||||
nodes: extensionManager.nodes,
|
||||
marks: extensionManager.marks,
|
||||
});
|
||||
const markdown = serializer.serialize(Node.fromJSON(schema, this.data), {
|
||||
|
||||
const doc = Node.fromJSON(
|
||||
schema,
|
||||
ProsemirrorHelper.attachmentsToAbsoluteUrls(this.data)
|
||||
);
|
||||
|
||||
const markdown = serializer.serialize(doc, {
|
||||
softBreak: true,
|
||||
});
|
||||
return markdown;
|
||||
|
||||
@@ -552,7 +552,6 @@
|
||||
"API key": "API key",
|
||||
"Show path to document": "Show path to document",
|
||||
"Path to document": "Path to document",
|
||||
"Group member options": "Group member options",
|
||||
"Export collection": "Export collection",
|
||||
"Rename": "Rename",
|
||||
"Sort in sidebar": "Sort in sidebar",
|
||||
@@ -568,13 +567,13 @@
|
||||
"Apply template": "Apply template",
|
||||
"Enable embeds": "Enable embeds",
|
||||
"File": "File",
|
||||
"Group member options": "Group member options",
|
||||
"Group members": "Group members",
|
||||
"Edit group": "Edit group",
|
||||
"Delete group": "Delete group",
|
||||
"Group options": "Group options",
|
||||
"Cancel": "Cancel",
|
||||
"Import menu options": "Import menu options",
|
||||
"Member options": "Member options",
|
||||
"New document in <em>{{ collectionName }}</em>": "New document in <em>{{ collectionName }}</em>",
|
||||
"New child document": "New child document",
|
||||
"Save in workspace": "Save in workspace",
|
||||
|
||||
@@ -4,6 +4,7 @@ import textBetween from "../editor/lib/textBetween";
|
||||
import { getTextSerializers } from "../editor/lib/textSerializers";
|
||||
import { ProsemirrorData } from "../types";
|
||||
import { TextHelper } from "./TextHelper";
|
||||
import env from "../env";
|
||||
|
||||
export type Heading = {
|
||||
/* The heading in plain text */
|
||||
@@ -364,6 +365,53 @@ export class ProsemirrorHelper {
|
||||
return headings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all attachment URLs in the ProsemirrorData to absolute URLs.
|
||||
* This is useful for ensuring that attachments can be accessed correctly
|
||||
* when the document is rendered in a different context or environment.
|
||||
*
|
||||
* @param data The ProsemirrorData object to process
|
||||
* @returns The ProsemirrorData with absolute URLs for attachments
|
||||
*/
|
||||
static attachmentsToAbsoluteUrls(data: ProsemirrorData): ProsemirrorData {
|
||||
function replace(node: ProsemirrorData) {
|
||||
if (
|
||||
node.type === "image" &&
|
||||
node.attrs?.src &&
|
||||
String(node.attrs.src).match(
|
||||
new RegExp("^" + attachmentRedirectRegex.source)
|
||||
)
|
||||
) {
|
||||
node.attrs.src = env.URL + node.attrs.src;
|
||||
}
|
||||
if (
|
||||
node.type === "video" &&
|
||||
node.attrs?.src &&
|
||||
String(node.attrs.src).match(
|
||||
new RegExp("^" + attachmentRedirectRegex.source)
|
||||
)
|
||||
) {
|
||||
node.attrs.src = env.URL + node.attrs.src;
|
||||
}
|
||||
if (
|
||||
node.type === "attachment" &&
|
||||
node.attrs?.href &&
|
||||
String(node.attrs.src).match(
|
||||
new RegExp("^" + attachmentRedirectRegex.source)
|
||||
)
|
||||
) {
|
||||
node.attrs.href = env.URL + node.attrs.href;
|
||||
}
|
||||
if (node.content) {
|
||||
node.content.forEach(replace);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
return replace(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all template variables in the node.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user