From 2f7a7ba01c7ebd493fda2bb24291ce4b5c954f61 Mon Sep 17 00:00:00 2001 From: charlie Date: Mon, 28 Oct 2024 16:52:06 +0800 Subject: [PATCH] feat: support mixed html #53 --- src/htmlmixed.tsx | 14 ++++++++++++++ src/main.ts | 21 ++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/htmlmixed.tsx diff --git a/src/htmlmixed.tsx b/src/htmlmixed.tsx new file mode 100644 index 0000000..a9f6005 --- /dev/null +++ b/src/htmlmixed.tsx @@ -0,0 +1,14 @@ +import '@logseq/libs' +import React, { useEffect } from 'react' + +export default function (props: { content: string }) { + const { content } = props + const elRef = React.useRef(null) + const _host = logseq.Experiments.ensureHostScope() + + useEffect(() => { + elRef.current.innerHTML = content + }, [content]) + + return (
) +} diff --git a/src/main.ts b/src/main.ts index 93491b2..947f717 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,11 +3,13 @@ import { LSPluginBaseInfo, SettingSchemaDesc } from '@logseq/libs/dist/LSPlugin' import mermaidRenderer from './mermaid' import echartsRenderer from './echarts' import TikzjaxRenderer from './tikzjax' +import htmlRenderer from './htmlmixed' const Supports = { Mermaid: 'mermaid', Echarts: 'echarts', - TikZJax: 'tikz' + TikZJax: 'tikz', + HTMLmixed: 'htmlmixed', } const settingsSchema: Array = [ @@ -25,6 +27,13 @@ const settingsSchema: Array = [ description: 'Use Echarts to render the chart.', default: true }, + { + key: 'htmlmixed', + type: 'boolean', + title: 'Support html mixed tags?', + description: 'Render with html mixed tags', + default: true + }, { key: 'tikzjax', type: 'boolean', @@ -45,6 +54,7 @@ function main(baseInfo: LSPluginBaseInfo) { } ) } + if (settings.echarts) { logseq.Experiments.registerFencedCodeRenderer( Supports.Echarts, { @@ -54,6 +64,15 @@ function main(baseInfo: LSPluginBaseInfo) { ) } + if (settings.htmlmixed) { + logseq.Experiments.registerFencedCodeRenderer( + Supports.HTMLmixed, { + edit: false, + render: htmlRenderer, + } + ) + } + if (settings.tikzjax) { logseq.Experiments.registerFencedCodeRenderer( Supports.TikZJax, {