fix: Relative links in document HTML should become absolute in emailed snippets

closes #6480
This commit is contained in:
Tom Moor
2024-02-06 21:27:24 -05:00
parent 68d4041b1c
commit d8e59a32ee
3 changed files with 16 additions and 0 deletions

View File

@@ -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({

View File

@@ -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(