From c09f1410344bd6f79a258ce60bc7e251c56d75a6 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Fri, 19 Apr 2024 00:33:35 +0800 Subject: [PATCH] :recycle: Refactor: refactor code block rendering --- assets/js/theme.js | 9 +++++++-- layouts/_default/_markup/render-codeblock.html | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/js/theme.js b/assets/js/theme.js index 9a816245..6a388924 100644 --- a/assets/js/theme.js +++ b/assets/js/theme.js @@ -386,8 +386,13 @@ class FixIt { // code title const $title = document.createElement('span'); $title.classList.add('code-title'); - const hlAttrs = this.data[$chroma.parentNode.id]; - $title.insertAdjacentHTML('afterbegin', `${hlAttrs?.title ?? ''}`); + // insert code title inner + $title.insertAdjacentHTML( + 'afterbegin', + $chroma.parentNode.title + ? `${$chroma.parentNode.title}` + : '' + ); $title.addEventListener('click', () => { $chroma.classList.toggle('open'); }, false); diff --git a/layouts/_default/_markup/render-codeblock.html b/layouts/_default/_markup/render-codeblock.html index 5d39b991..046abec3 100644 --- a/layouts/_default/_markup/render-codeblock.html +++ b/layouts/_default/_markup/render-codeblock.html @@ -1,3 +1,2 @@ -{{- $id := dict "Content" .Attributes "Scratch" .Page.Scratch | partial "function/id.html" -}} -{{- $codeBlock := transform.Highlight .Inner .Type .Options -}} -{{- replace $codeBlock "