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,
|
||||
centered: false,
|
||||
signedUrls: (4 * Day) / 1000,
|
||||
baseUrl: props.teamUrl,
|
||||
});
|
||||
|
||||
// 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)
|
||||
*/
|
||||
signedUrls?: boolean | number;
|
||||
/** The base URL to use for relative links */
|
||||
baseUrl?: string;
|
||||
};
|
||||
|
||||
@trace()
|
||||
@@ -111,6 +113,7 @@ export default class DocumentHelper {
|
||||
includeStyles: options?.includeStyles,
|
||||
includeMermaid: options?.includeMermaid,
|
||||
centered: options?.centered,
|
||||
baseUrl: options?.baseUrl,
|
||||
});
|
||||
|
||||
addTags({
|
||||
|
||||
@@ -23,6 +23,8 @@ export type HTMLOptions = {
|
||||
includeMermaid?: boolean;
|
||||
/** Whether to include styles to center diff (defaults to true) */
|
||||
centered?: boolean;
|
||||
/** The base URL to use for relative links */
|
||||
baseUrl?: string;
|
||||
};
|
||||
|
||||
type MentionAttrs = {
|
||||
@@ -217,6 +219,16 @@ export default class ProsemirrorHelper {
|
||||
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
|
||||
if (options?.includeMermaid) {
|
||||
const mermaidElements = dom.window.document.querySelectorAll(
|
||||
|
||||
Reference in New Issue
Block a user