Skip to content

Commit

Permalink
♻️ Refactor: refactor code block rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Apr 18, 2024
1 parent a2d8eaa commit c09f141
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions assets/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', `<i class="arrow fa-solid fa-chevron-right fa-fw" aria-hidden="true"></i><span class="title-inner">${hlAttrs?.title ?? ''}</span>`);
// insert code title inner
$title.insertAdjacentHTML(
'afterbegin',
$chroma.parentNode.title
? `<i class="arrow fa-solid fa-chevron-right fa-fw" aria-hidden="true"></i><span class="title-inner">${$chroma.parentNode.title}</span>`
: '<i class="arrow fa-solid fa-chevron-right fa-fw" aria-hidden="true"></i>'
);
$title.addEventListener('click', () => {
$chroma.classList.toggle('open');
}, false);
Expand Down
5 changes: 2 additions & 3 deletions layouts/_default/_markup/render-codeblock.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{{- $id := dict "Content" .Attributes "Scratch" .Page.Scratch | partial "function/id.html" -}}
{{- $codeBlock := transform.Highlight .Inner .Type .Options -}}
{{- replace $codeBlock "<div class=\"highlight\">" (printf "<div class=\"highlight\" id=\"%v\">" $id) 1 | safeHTML -}}
{{- $result := transform.HighlightCodeBlock . -}}
{{- $result.Wrapped -}}

0 comments on commit c09f141

Please sign in to comment.