Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions src/extensions/additional/YfmHtmlBlock/utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import type {SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';
import * as sanitizeModule from '@diplodoc/transform/lib/sanitize.js';
import type {SanitizeOptions} from '@diplodoc/transform/lib/sanitize';

type SanitizeFn = (
html: string,
options?: SanitizeOptions,
additionalOptions?: SanitizeOptions,
) => string;

interface SanitizeModule {
sanitize?: SanitizeFn;
default?: SanitizeFn;
}

const sanitizeAll = () => {
console.warn('[YfmHtmlBlock]: sanitize function not found');
return '';
};
const getSanitizeFunction = (): SanitizeFn => {
const module = sanitizeModule as SanitizeModule;
const sanitize = 'sanitize' in module && module.sanitize ? module.sanitize : module.default;
return sanitize instanceof Function ? sanitize : sanitizeAll;
};
import {getSanitize} from 'src/utils/getSanitize';

// MAJOR: use `import {sanitize} from '@diplodoc/transform/lib/sanitize.js'`
const diplodocSanitize = getSanitizeFunction();
const diplodocSanitize = getSanitize('YfmHtmlBlock');

// yfmHtmlBlock additional css properties white list
const getYfmHtmlBlockWhiteList = () => {
Expand Down
5 changes: 4 additions & 1 deletion src/extensions/markdown/Html/schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import sanitize from '@diplodoc/transform/lib/sanitize.js';
import type {NodeSpec} from 'prosemirror-model';

import {getSanitize} from 'src/utils/getSanitize';

import {HtmlAttr, HtmlNode} from './const';

enum DomAttr {
Html = 'data-html',
HtmlRaw = 'data-html-raw',
}

const sanitize = getSanitize('Html');

export const schemaSpecs: Record<HtmlNode, NodeSpec> = {
[HtmlNode.Block]: {
atom: true,
Expand Down
23 changes: 23 additions & 0 deletions src/utils/getSanitize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type {SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';
import * as sanitizeModule from '@diplodoc/transform/lib/sanitize.js';

type SanitizeFn = (
html: string,
options?: SanitizeOptions,
additionalOptions?: SanitizeOptions,
) => string;

interface SanitizeModule {
sanitize?: SanitizeFn;
default?: SanitizeFn;
}

const sanitizeAll = (blockName: string) => () => {
console.warn(`[${blockName}]: sanitize function not found`);
return '';
};
export const getSanitize = (blockName: string): SanitizeFn => {
const module = sanitizeModule as SanitizeModule;
const sanitize = 'sanitize' in module && module.sanitize ? module.sanitize : module.default;
return sanitize instanceof Function ? sanitize : sanitizeAll(blockName);
};
Loading