mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
292c894b93
Summary: Text columns can now display their values as Markdown-formatted text by changing their cell format to "Markdown". A minimal subset of the Markdown specification is currently supported. Test Plan: Browser tests. Reviewers: Spoffy, dsagal Reviewed By: Spoffy, dsagal Subscribers: dsagal, Spoffy Differential Revision: https://phab.getgrist.com/D4326
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import createDOMPurifier from 'dompurify';
|
|
|
|
export function sanitizeHTML(source: string | Node): string {
|
|
return defaultPurifier.sanitize(source);
|
|
}
|
|
|
|
export function sanitizeTutorialHTML(source: string | Node): string {
|
|
return tutorialPurifier.sanitize(source, {
|
|
ADD_TAGS: ['iframe'],
|
|
ADD_ATTR: ['allowFullscreen'],
|
|
});
|
|
}
|
|
|
|
const defaultPurifier = createDOMPurifier();
|
|
defaultPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);
|
|
|
|
const tutorialPurifier = createDOMPurifier();
|
|
tutorialPurifier.addHook('uponSanitizeAttribute', handleSanitizeAttribute);
|
|
tutorialPurifier.addHook('uponSanitizeElement', handleSanitizeTutorialElement);
|
|
|
|
function handleSanitizeAttribute(node: Element) {
|
|
if (!('target' in node)) { return; }
|
|
|
|
node.setAttribute('target', '_blank');
|
|
}
|
|
|
|
function handleSanitizeTutorialElement(node: Element, data: createDOMPurifier.SanitizeElementHookEvent) {
|
|
if (data.tagName !== 'iframe') { return; }
|
|
|
|
const src = node.getAttribute('src');
|
|
if (src?.startsWith('https://www.youtube.com/embed/')) {
|
|
return;
|
|
}
|
|
|
|
node.parentNode?.removeChild(node);
|
|
}
|