Skip to content

Commit

Permalink
feat: support mixed html #53
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 committed Oct 28, 2024
1 parent a794c04 commit 2f7a7ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/htmlmixed.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLDivElement>(null)
const _host = logseq.Experiments.ensureHostScope()

useEffect(() => {
elRef.current.innerHTML = content
}, [content])

return (<div className={'fcp-html-container'} ref={elRef}></div>)
}
21 changes: 20 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SettingSchemaDesc> = [
Expand All @@ -25,6 +27,13 @@ const settingsSchema: Array<SettingSchemaDesc> = [
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',
Expand All @@ -45,6 +54,7 @@ function main(baseInfo: LSPluginBaseInfo) {
}
)
}

if (settings.echarts) {
logseq.Experiments.registerFencedCodeRenderer(
Supports.Echarts, {
Expand All @@ -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, {
Expand Down

0 comments on commit 2f7a7ba

Please sign in to comment.