mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
be8e13df64
Summary: Documents can now be flagged as tutorials, which causes them to display Markdown-formatted slides from a special GristDocTutorial table. Tutorial documents are forked on open, and remember the last slide a user was on. They can be restarted too, which prepares a new fork of the tutorial. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Differential Revision: https://phab.getgrist.com/D3813
27 lines
634 B
TypeScript
27 lines
634 B
TypeScript
import DOMPurify from 'dompurify';
|
|
|
|
const config = {
|
|
ADD_TAGS: ['iframe'],
|
|
ADD_ATTR: ['allowFullscreen'],
|
|
};
|
|
|
|
DOMPurify.addHook('uponSanitizeAttribute', (node) => {
|
|
if (!('target' in node)) { return; }
|
|
|
|
node.setAttribute('target', '_blank');
|
|
});
|
|
DOMPurify.addHook('uponSanitizeElement', (node, data) => {
|
|
if (data.tagName !== 'iframe') { return; }
|
|
|
|
const src = node.getAttribute('src');
|
|
if (src?.startsWith('https://www.youtube.com/embed/')) {
|
|
return;
|
|
}
|
|
|
|
return node.parentNode?.removeChild(node);
|
|
});
|
|
|
|
export function sanitizeHTML(source: string | Node): string {
|
|
return DOMPurify.sanitize(source, config);
|
|
}
|