Skip to content

Commit

Permalink
支持 mermaid图,支持化学方程式
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Nov 15, 2022
1 parent 12babbd commit 6ac7f2b
Show file tree
Hide file tree
Showing 3 changed files with 1,717 additions and 2 deletions.
21 changes: 20 additions & 1 deletion components/NotionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ import 'prismjs/components/prism-swift.js'
import 'prismjs/components/prism-wasm.js'
import 'prismjs/components/prism-yaml.js'
import 'prismjs/components/prism-r.js'
// mermaid图
import mermaid from 'mermaid'
// 化学方程式
import '@/lib/mhchem'

const Collection = dynamic(() =>
import('react-notion-x/build/third-party/collection').then((m) => m.Collection), { ssr: true }
Expand All @@ -66,6 +69,18 @@ const NotionPage = ({ post }) => {
const zoomRef = React.useRef(zoom ? zoom.clone() : null)

React.useEffect(() => {
// 准备接入化学方程式
// console.log('kk', katex)
// const html = katex.renderToString('\\ce{CO2 + C -> 2 C0}')
// console.log(html)
// katex.__parse('\\ce{CO2 + C -> 2 CO}')
// katex.render('\ce{2H2O->2H2 + O2}', document.getElementById('test1'))
// katex.render('(\ce{2H + O -> H2O}\)', document.getElementById('test2'))
// katex.render('\\ce{2H2O->2H2 + O2}', document.getElementById('test3'))

// document.getElementById('test').innerHTML = katex.renderToString('\ce{2H2O->2H2 + O2}')
// document.getElementById('test').innerHTML = katex.renderToString('\(\ce{2H + O -> H2O}\)')

// 支持 Mermaid
const mermaids = document.querySelectorAll('.notion-code .language-mermaid')
for (const e of mermaids) {
Expand Down Expand Up @@ -93,7 +108,7 @@ const NotionPage = ({ post }) => {
}
}

// 相册图片不允许点击
// 相册图片点击不跳转
const cards = document.getElementsByClassName('notion-collection-card')
for (const e of cards) {
e.removeAttribute('href')
Expand All @@ -105,6 +120,10 @@ const NotionPage = ({ post }) => {
}, [])

return <div id='container' className='max-w-5xl overflow-x-hidden mx-auto'>
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/mhchem.min.js" integrity="sha384-5gCAXJ0ZgozlShOzzT0OWArn7yCPGWVIvgo+BAd8NUKbCmulrJiQuCVR9cHlPHeG"></script>
<div id='test1'></div>
<div id='test2'></div>
<div id='test2'></div>
<NotionRenderer
recordMap={post.blockMap}
mapPageUrl={mapPageUrl}
Expand Down
Loading

0 comments on commit 6ac7f2b

Please sign in to comment.