From 4a6df5662aa19b759653eef2e095a6e46874604c Mon Sep 17 00:00:00 2001 From: Sergey Makhnatkin Date: Wed, 21 Aug 2024 12:26:17 +0200 Subject: [PATCH] feat(yfmHtmlBlock): updated @diplodoc/html-extension (#343) --- demo/Playground.tsx | 15 ++++++++----- demo/md-plugins.ts | 10 ++++++++- package-lock.json | 8 +++---- package.json | 2 +- .../YfmHtmlBlockNodeView/YfmHtmlBlockView.tsx | 22 +++++++++++++------ src/extensions/yfm/YfmHtmlBlock/index.ts | 1 + 6 files changed, 39 insertions(+), 19 deletions(-) diff --git a/demo/Playground.tsx b/demo/Playground.tsx index 904bf63c..4f277ae7 100644 --- a/demo/Playground.tsx +++ b/demo/Playground.tsx @@ -169,12 +169,15 @@ export const Playground = React.memo((props) => { .use(YfmHtmlBlock, { useConfig: useYfmHtmlBlockStyles, sanitize: getSanitizeYfmHtmlBlock({options: defaultOptions}), - baseTarget: '_blank', - styles: { - body: { - margin: 0, - }, - }, + head: ` + + + void; options: YfmHtmlBlockOptions; view: EditorView; -}> = ({onChange, node, getPos, view, options: {useConfig, sanitize, styles, baseTarget = '_'}}) => { +}> = ({ + onChange, + node, + getPos, + view, + options: {useConfig, sanitize, styles, baseTarget = '_parent', head: headContent = ''}, +}) => { const [editing, setEditing, unsetEditing, toggleEditing] = useBooleanState( Boolean(node.attrs[YfmHtmlBlockConsts.NodeAttrs.newCreated]), ); @@ -233,25 +239,27 @@ export const YfmHtmlBlockView: React.FC<{ ); } - let dirtyHtml = - `` + node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc]; - + let additional = baseTarget ? `` : ''; if (styles) { const stylesContent = typeof styles === 'string' ? `` : ``; - dirtyHtml = stylesContent + dirtyHtml; + additional += stylesContent; } - const html = sanitize ? sanitize(dirtyHtml) : dirtyHtml; + const head = `${headContent || additional}`; + const body = `${node.attrs[YfmHtmlBlockConsts.NodeAttrs.srcdoc] ?? ''}`; + const html = `${head}${body}`; + + const resultHtml = sanitize ? sanitize(html) : html; return (
- +