Skip to content

Commit

Permalink
✨ Feat: add code block attributes support (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lruihao committed Jun 11, 2023
1 parent ff95cfa commit 6df8f28
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
<!-- Releases see https://github.com/hugo-fixit/FixIt/releases -->

## v0.2.18-lts

- :sparkles: Feat: add code block attributes support ([#330](https://github.com/hugo-fixit/FixIt/issues/330))

## v0.2.18 [2023.3.31]

> **Note**
Expand Down
6 changes: 6 additions & 0 deletions assets/css/_partials/_single/_code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ pre {
padding: 0 0.2rem;
@include transition(transform 0.2s ease);
}

.title-inner {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
}

.code-title::after {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions layouts/_default/_markup/render-codeblock.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- $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 -}}
5 changes: 3 additions & 2 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Util {
class FixIt {
constructor() {
this.config = window.config;
this.data = this.config.data;
this.data = this.config.data || [];
this.isDark = document.body.dataset.theme === 'dark';
this.util = new Util();
this.newScrollTop = this.util.getScrollTop();
Expand Down Expand Up @@ -528,7 +528,8 @@ class FixIt {
// code title
const $title = document.createElement('span');
$title.classList.add('code-title');
$title.insertAdjacentHTML('afterbegin', '<i class="arrow fa-solid fa-chevron-right fa-fw" aria-hidden="true"></i>');
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>`);
$title.addEventListener('click', () => {
$chroma.classList.toggle('open');
}, false);
Expand Down

1 comment on commit 6df8f28

@vercel
Copy link

@vercel vercel bot commented on 6df8f28 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.