Skip to content

Commit e76af56

Browse files
authored
feat(YfmHtmlBlock): added compatibility for sanitize named export (#668)
1 parent ed88851 commit e76af56

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/extensions/additional/YfmHtmlBlock/utils.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
import diplodocSanitize, {type SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';
1+
import type {SanitizeOptions} from '@diplodoc/transform/lib/sanitize.js';
2+
import * as sanitizeModule from '@diplodoc/transform/lib/sanitize.js';
3+
4+
type SanitizeFn = (
5+
html: string,
6+
options?: SanitizeOptions,
7+
additionalOptions?: SanitizeOptions,
8+
) => string;
9+
10+
interface SanitizeModule {
11+
sanitize?: SanitizeFn;
12+
default?: SanitizeFn;
13+
}
14+
15+
const sanitizeAll = () => {
16+
console.warn('[YfmHtmlBlock]: sanitize function not found');
17+
return '';
18+
};
19+
const getSanitizeFunction = (): SanitizeFn => {
20+
const module = sanitizeModule as SanitizeModule;
21+
const sanitize = 'sanitize' in module && module.sanitize ? module.sanitize : module.default;
22+
return sanitize instanceof Function ? sanitize : sanitizeAll;
23+
};
24+
25+
// MAJOR: use `import {sanitize} from '@diplodoc/transform/lib/sanitize.js'`
26+
const diplodocSanitize = getSanitizeFunction();
227

328
// yfmHtmlBlock additional css properties white list
429
const getYfmHtmlBlockWhiteList = () => {

src/extensions/markdown/Lists/plugins/CollapseListsPlugin.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Fragment, type Node} from 'prosemirror-model';
22
import {Plugin, TextSelection, type Transaction} from 'prosemirror-state';
3+
// @ts-ignore // TODO: fix cjs build
34
import {findChildren, hasParentNode} from 'prosemirror-utils';
45

56
import {getChildrenOfNode} from '../../../../utils';
@@ -36,7 +37,8 @@ export function collapseEmptyListItems(
3637
nodes: ReturnType<typeof findChildren>,
3738
): number {
3839
const stepsCountBefore = tr.steps.length;
39-
nodes.reverse().forEach((list) => {
40+
// TODO: fix cjs build
41+
nodes.reverse().forEach((list: {node: Node; pos: number}) => {
4042
const listNode = list.node;
4143
const listPos = list.pos;
4244
const childrenOfList = getChildrenOfNode(listNode).reverse();

0 commit comments

Comments
 (0)