mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-01 07:26:47 +00:00
@@ -43,9 +43,15 @@ const PrismMac = () => {
|
|||||||
loadExternalResource('/css/prism-mac-style.css', 'css')
|
loadExternalResource('/css/prism-mac-style.css', 'css')
|
||||||
}
|
}
|
||||||
// 加载prism样式
|
// 加载prism样式
|
||||||
loadPrismThemeCSS(isDarkMode, prismThemeSwitch, prismThemeDarkPath, prismThemeLightPath, prismThemePrefixPath)
|
loadPrismThemeCSS(
|
||||||
|
isDarkMode,
|
||||||
|
prismThemeSwitch,
|
||||||
|
prismThemeDarkPath,
|
||||||
|
prismThemeLightPath,
|
||||||
|
prismThemePrefixPath
|
||||||
|
)
|
||||||
// 折叠代码
|
// 折叠代码
|
||||||
loadExternalResource(prismjsAutoLoader, 'js').then((url) => {
|
loadExternalResource(prismjsAutoLoader, 'js').then(url => {
|
||||||
if (window?.Prism?.plugins?.autoloader) {
|
if (window?.Prism?.plugins?.autoloader) {
|
||||||
window.Prism.plugins.autoloader.languages_path = prismjsPath
|
window.Prism.plugins.autoloader.languages_path = prismjsPath
|
||||||
}
|
}
|
||||||
@@ -62,7 +68,13 @@ const PrismMac = () => {
|
|||||||
/**
|
/**
|
||||||
* 加载Prism主题样式
|
* 加载Prism主题样式
|
||||||
*/
|
*/
|
||||||
const loadPrismThemeCSS = (isDarkMode, prismThemeSwitch, prismThemeDarkPath, prismThemeLightPath, prismThemePrefixPath) => {
|
const loadPrismThemeCSS = (
|
||||||
|
isDarkMode,
|
||||||
|
prismThemeSwitch,
|
||||||
|
prismThemeDarkPath,
|
||||||
|
prismThemeLightPath,
|
||||||
|
prismThemePrefixPath
|
||||||
|
) => {
|
||||||
let PRISM_THEME
|
let PRISM_THEME
|
||||||
let PRISM_PREVIOUS
|
let PRISM_PREVIOUS
|
||||||
if (prismThemeSwitch) {
|
if (prismThemeSwitch) {
|
||||||
@@ -73,8 +85,14 @@ const loadPrismThemeCSS = (isDarkMode, prismThemeSwitch, prismThemeDarkPath, pri
|
|||||||
PRISM_THEME = prismThemeLightPath
|
PRISM_THEME = prismThemeLightPath
|
||||||
PRISM_PREVIOUS = prismThemeDarkPath
|
PRISM_PREVIOUS = prismThemeDarkPath
|
||||||
}
|
}
|
||||||
const previousTheme = document.querySelector(`link[href="${PRISM_PREVIOUS}"]`)
|
const previousTheme = document.querySelector(
|
||||||
if (previousTheme && previousTheme.parentNode && previousTheme.parentNode.contains(previousTheme)) {
|
`link[href="${PRISM_PREVIOUS}"]`
|
||||||
|
)
|
||||||
|
if (
|
||||||
|
previousTheme &&
|
||||||
|
previousTheme.parentNode &&
|
||||||
|
previousTheme.parentNode.contains(previousTheme)
|
||||||
|
) {
|
||||||
previousTheme.parentNode.removeChild(previousTheme)
|
previousTheme.parentNode.removeChild(previousTheme)
|
||||||
}
|
}
|
||||||
loadExternalResource(PRISM_THEME, 'css')
|
loadExternalResource(PRISM_THEME, 'css')
|
||||||
@@ -103,14 +121,17 @@ const renderCollapseCode = (codeCollapse, codeCollapseExpandDefault) => {
|
|||||||
const collapseWrapper = document.createElement('div')
|
const collapseWrapper = document.createElement('div')
|
||||||
collapseWrapper.className = 'collapse-wrapper w-full py-2'
|
collapseWrapper.className = 'collapse-wrapper w-full py-2'
|
||||||
const panelWrapper = document.createElement('div')
|
const panelWrapper = document.createElement('div')
|
||||||
panelWrapper.className = 'border dark:border-gray-600 rounded-md hover:border-indigo-500 duration-200 transition-colors'
|
panelWrapper.className =
|
||||||
|
'border dark:border-gray-600 rounded-md hover:border-indigo-500 duration-200 transition-colors'
|
||||||
|
|
||||||
const header = document.createElement('div')
|
const header = document.createElement('div')
|
||||||
header.className = 'flex justify-between items-center px-4 py-2 cursor-pointer select-none'
|
header.className =
|
||||||
|
'flex justify-between items-center px-4 py-2 cursor-pointer select-none'
|
||||||
header.innerHTML = `<h3 class="text-lg font-medium">${language}</h3><svg class="transition-all duration-200 w-5 h-5 transform rotate-0" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M6.293 6.293a1 1 0 0 1 1.414 0L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414l-3 3a1 1 0 0 1-1.414 0l-3-3a1 1 0 0 1 0-1.414z" clip-rule="evenodd"/></svg>`
|
header.innerHTML = `<h3 class="text-lg font-medium">${language}</h3><svg class="transition-all duration-200 w-5 h-5 transform rotate-0" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M6.293 6.293a1 1 0 0 1 1.414 0L10 8.586l2.293-2.293a1 1 0 0 1 1.414 1.414l-3 3a1 1 0 0 1-1.414 0l-3-3a1 1 0 0 1 0-1.414z" clip-rule="evenodd"/></svg>`
|
||||||
|
|
||||||
const panel = document.createElement('div')
|
const panel = document.createElement('div')
|
||||||
panel.className = 'invisible h-0 transition-transform duration-200 border-t border-gray-300'
|
panel.className =
|
||||||
|
'invisible h-0 transition-transform duration-200 border-t border-gray-300'
|
||||||
|
|
||||||
panelWrapper.appendChild(header)
|
panelWrapper.appendChild(header)
|
||||||
panelWrapper.appendChild(panel)
|
panelWrapper.appendChild(panel)
|
||||||
@@ -145,7 +166,7 @@ const renderMermaid = async(mermaidCDN) => {
|
|||||||
if (m.target.className === 'notion-code language-mermaid') {
|
if (m.target.className === 'notion-code language-mermaid') {
|
||||||
const chart = m.target.querySelector('code').textContent
|
const chart = m.target.querySelector('code').textContent
|
||||||
if (chart && !m.target.querySelector('.mermaid')) {
|
if (chart && !m.target.querySelector('.mermaid')) {
|
||||||
const mermaidChart = document.createElement('div')
|
const mermaidChart = document.createElement('pre')
|
||||||
mermaidChart.className = 'mermaid'
|
mermaidChart.className = 'mermaid'
|
||||||
mermaidChart.innerHTML = chart
|
mermaidChart.innerHTML = chart
|
||||||
m.target.appendChild(mermaidChart)
|
m.target.appendChild(mermaidChart)
|
||||||
@@ -172,7 +193,10 @@ const renderMermaid = async(mermaidCDN) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (document.querySelector('#notion-article')) {
|
if (document.querySelector('#notion-article')) {
|
||||||
observer.observe(document.querySelector('#notion-article'), { attributes: true, subtree: true })
|
observer.observe(document.querySelector('#notion-article'), {
|
||||||
|
attributes: true,
|
||||||
|
subtree: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +258,10 @@ const fixCodeLineStyle = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
observer.observe(document.querySelector('#notion-article'), { attributes: true, subtree: true })
|
observer.observe(document.querySelector('#notion-article'), {
|
||||||
|
attributes: true,
|
||||||
|
subtree: true
|
||||||
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const preCodes = document.querySelectorAll('pre.notion-code')
|
const preCodes = document.querySelectorAll('pre.notion-code')
|
||||||
for (const preCode of preCodes) {
|
for (const preCode of preCodes) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ module.exports = {
|
|||||||
// Mermaid 图表CDN
|
// Mermaid 图表CDN
|
||||||
MERMAID_CDN:
|
MERMAID_CDN:
|
||||||
process.env.NEXT_PUBLIC_MERMAID_CDN ||
|
process.env.NEXT_PUBLIC_MERMAID_CDN ||
|
||||||
'https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.2.4/mermaid.min.js' // CDN
|
'https://cdnjs.cloudflare.com/ajax/libs/mermaid/11.4.0/mermaid.min.js' // CDN
|
||||||
|
|
||||||
// END********代码相关********
|
// END********代码相关********
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2027,6 +2027,10 @@ code.language-mermaid {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mermaid .invisible{
|
||||||
|
visibility: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
.code-toolbar {
|
.code-toolbar {
|
||||||
@apply w-full shadow-md pb-0;
|
@apply w-full shadow-md pb-0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user