Skip to content

Commit 130b0a6

Browse files
authored
feat: display the title attribute (#39)
Closes #38
1 parent 6bacbfb commit 130b0a6

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

assets/mods/code-block-panel/js/panel.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import snackbar from 'mods/snackbar/js/index.ts';
33
import i18n from './i18n';
44

55
export default class Panel {
6+
private highlight: HTMLElement
7+
68
private pre: HTMLElement
79

810
private wrapper: HTMLElement
@@ -21,6 +23,7 @@ export default class Panel {
2123
}
2224

2325
this.pre = this.code.parentElement as HTMLElement
26+
this.highlight = this.pre.parentElement as HTMLElement
2427

2528
this.ele = document.createElement('div')
2629
this.ele.className = 'code-block-panel'
@@ -30,7 +33,7 @@ export default class Panel {
3033
this.wrapper.appendChild(this.ele)
3134

3235
this.maxLines()
33-
this.language()
36+
this.title()
3437
this.lineNoButton()
3538
this.wrapButton()
3639
this.expandButton()
@@ -57,17 +60,14 @@ export default class Panel {
5760
}
5861
}
5962

60-
// Show the code language.
61-
private language() {
62-
const lang = this.code.getAttribute('data-lang')
63-
if (!lang || lang === 'fallback') {
63+
// Display the title
64+
private title() {
65+
const title = this.highlight.getAttribute('title')
66+
if (title === null) {
6467
return
6568
}
6669

67-
const e = document.createElement('span')
68-
e.className = 'code-block-lang'
69-
e.innerText = lang
70-
this.pre.appendChild(e)
70+
this.code.setAttribute('title', title)
7171
}
7272

7373
private button(name: string, callback: CallableFunction): HTMLButtonElement {

assets/mods/code-block-panel/scss/index.scss

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,25 @@
2626
&.code-wrap {
2727
white-space: pre-wrap !important;
2828
}
29-
}
3029

31-
.code-block-lang {
32-
font-style: italic;
33-
position: absolute;
34-
right: 1rem;
35-
text-transform: uppercase;
36-
top: 0;
30+
&::before,
31+
&::after {
32+
position: absolute;
33+
right: .75rem;
34+
font-weight: 700;
35+
}
36+
37+
&::before {
38+
content: attr(data-lang);
39+
top: .25rem;
40+
text-transform: uppercase;
41+
font-size: 0.75rem;
42+
}
43+
44+
&::after {
45+
content: attr(title);
46+
bottom: .25rem;
47+
}
3748
}
3849
}
3950
}

0 commit comments

Comments
 (0)