1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-09-16 08:56:40 +02:00

Desktop: Fixes #9304: Fix HTML resource links lost when editing notes in the rich text editor (#9435)

This commit is contained in:
Henry Heino
2023-12-06 11:17:16 -08:00
committed by GitHub
parent c0c32a7ac1
commit 92a0964a8d
14 changed files with 125 additions and 17 deletions

View File

@@ -38,6 +38,7 @@ interface RenderOptions {
postMessageSyntax: string;
enableLongPress: boolean;
itemIdToUrl?: ItemIdToUrlHandler;
allowedFilePrefixes?: string[];
}
// https://github.com/es-shims/String.prototype.trimStart/blob/main/implementation.js
@@ -99,7 +100,9 @@ export default class HtmlToHtml {
let html = this.cache_.value(cacheKey);
if (!html) {
html = htmlUtils.sanitizeHtml(markup);
html = htmlUtils.sanitizeHtml(markup, {
allowedFilePrefixes: options.allowedFilePrefixes,
});
html = htmlUtils.processImageTags(html, (data: any) => {
if (!data.src) return null;

View File

@@ -192,6 +192,10 @@ export interface RuleOptions {
vendorDir?: string;
itemIdToUrl?: ItemIdToUrlHandler;
// Passed to the HTML sanitizer: Allows file:// URLs with
// paths with the included prefixes.
allowedFilePrefixes?: string[];
platformName?: string;
}

View File

@@ -34,7 +34,13 @@ export default {
// So the sanitizeHtml function must handle this kind of non-valid HTML.
if (!sanitizedContent) {
sanitizedContent = htmlUtils.sanitizeHtml(token.content, { addNoMdConvClass: true });
sanitizedContent = htmlUtils.sanitizeHtml(
token.content,
{
addNoMdConvClass: true,
allowedFilePrefixes: ruleOptions.allowedFilePrefixes,
},
);
}
token.content = sanitizedContent;

View File

@@ -189,10 +189,12 @@ class HtmlUtils {
// If true, adds a "jop-noMdConv" class to all the tags.
// It can be used afterwards to restore HTML tags in Markdown.
addNoMdConvClass: false,
allowedFilePrefixes: [],
...options,
};
// If options.allowedFilePrefixes is `undefined`, default to [].
options.allowedFilePrefixes ??= [];
const output: string[] = [];
const tagStack: string[] = [];