fix: Relative links in document HTML should become absolute in emailed snippets
closes #6480
This commit is contained in:
@@ -69,6 +69,7 @@ export default class DocumentPublishedOrUpdatedEmail extends BaseEmail<
|
|||||||
includeTitle: false,
|
includeTitle: false,
|
||||||
centered: false,
|
centered: false,
|
||||||
signedUrls: (4 * Day) / 1000,
|
signedUrls: (4 * Day) / 1000,
|
||||||
|
baseUrl: props.teamUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
// inline all css so that it works in as many email providers as possible.
|
// inline all css so that it works in as many email providers as possible.
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ type HTMLOptions = {
|
|||||||
* number then the urls will be signed for that many seconds. (defaults to false)
|
* number then the urls will be signed for that many seconds. (defaults to false)
|
||||||
*/
|
*/
|
||||||
signedUrls?: boolean | number;
|
signedUrls?: boolean | number;
|
||||||
|
/** The base URL to use for relative links */
|
||||||
|
baseUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@trace()
|
@trace()
|
||||||
@@ -111,6 +113,7 @@ export default class DocumentHelper {
|
|||||||
includeStyles: options?.includeStyles,
|
includeStyles: options?.includeStyles,
|
||||||
includeMermaid: options?.includeMermaid,
|
includeMermaid: options?.includeMermaid,
|
||||||
centered: options?.centered,
|
centered: options?.centered,
|
||||||
|
baseUrl: options?.baseUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
addTags({
|
addTags({
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export type HTMLOptions = {
|
|||||||
includeMermaid?: boolean;
|
includeMermaid?: boolean;
|
||||||
/** Whether to include styles to center diff (defaults to true) */
|
/** Whether to include styles to center diff (defaults to true) */
|
||||||
centered?: boolean;
|
centered?: boolean;
|
||||||
|
/** The base URL to use for relative links */
|
||||||
|
baseUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type MentionAttrs = {
|
type MentionAttrs = {
|
||||||
@@ -217,6 +219,16 @@ export default class ProsemirrorHelper {
|
|||||||
target
|
target
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Convert relative urls to absolute
|
||||||
|
if (options?.baseUrl) {
|
||||||
|
const elements = doc.querySelectorAll("a[href]");
|
||||||
|
for (const el of elements) {
|
||||||
|
if ("href" in el && (el.href as string).startsWith("/")) {
|
||||||
|
el.href = new URL(el.href as string, options.baseUrl).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Inject mermaidjs scripts if the document contains mermaid diagrams
|
// Inject mermaidjs scripts if the document contains mermaid diagrams
|
||||||
if (options?.includeMermaid) {
|
if (options?.includeMermaid) {
|
||||||
const mermaidElements = dom.window.document.querySelectorAll(
|
const mermaidElements = dom.window.document.querySelectorAll(
|
||||||
|
|||||||
Reference in New Issue
Block a user