Skip to content

Commit cb99897

Browse files
committed
minor improvements
1 parent 381965f commit cb99897

File tree

3 files changed

+52
-53
lines changed

3 files changed

+52
-53
lines changed

app/thirdparty/assets/prism/plugins/line-numbers/prism-line-numbers-markor.js

+13-17
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,21 @@ function getNumberDigits(number) {
2121
}
2222

2323
function adjustLineNumbers() {
24-
const preElements = document.querySelectorAll("pre[class*='language-']");
2524
let fontWidth = -1;
25+
const codeElements = document.querySelectorAll("pre > code");
26+
codeElements.forEach((element) => {
27+
const maxNumber = element.textContent.split("\n").length - 1;
28+
if (maxNumber == 0) {
29+
return;
30+
}
2631

27-
preElements.forEach((element) => {
28-
let codeElement = element.querySelector("pre > code");
29-
if (codeElement) {
30-
const maxNumber = codeElement.textContent.split("\n").length - 1;
31-
if (maxNumber == 0) {
32-
return;
33-
}
34-
35-
if (fontWidth == -1) {
36-
const canvasContext = document.createElement("canvas").getContext("2d");
37-
canvasContext.font = window.getComputedStyle(codeElement, null).getPropertyValue("font");
38-
fontWidth = canvasContext.measureText("0").width;
39-
}
40-
41-
const digits = getNumberDigits(maxNumber);
42-
element.style.paddingLeft = 2 * fontWidth + digits * fontWidth - digits + "px";
32+
if (fontWidth == -1) {
33+
const canvasContext = document.createElement("canvas").getContext("2d");
34+
canvasContext.font = window.getComputedStyle(element, null).getPropertyValue("font");
35+
fontWidth = canvasContext.measureText("0").width;
4336
}
37+
38+
const digits = getNumberDigits(maxNumber);
39+
element.parentNode.style.paddingLeft = 2 * fontWidth + digits * fontWidth - digits + "px";
4440
});
4541
}
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,61 @@
11
div.code-toolbar {
2-
position: relative;
2+
position: relative;
33
}
44

55
div.code-toolbar > .toolbar {
6-
position: absolute;
7-
z-index: 10;
8-
top: .3em;
9-
right: .2em;
10-
transition: opacity 0.3s ease-in-out;
11-
opacity: 0;
6+
position: absolute;
7+
z-index: 10;
8+
top: 0.3em;
9+
right: 0.2em;
10+
transition: opacity 0.3s ease-in-out;
11+
opacity: 0;
1212
}
1313

1414
div.code-toolbar:hover > .toolbar {
15-
opacity: 1;
15+
opacity: 1;
1616
}
1717

1818
/* Separate line b/c rules are thrown out if selector is invalid. */
1919
div.code-toolbar:focus-within > .toolbar {
20-
opacity: 1;
20+
opacity: 1;
2121
}
2222

2323
div.code-toolbar > .toolbar > .toolbar-item {
24-
display: inline-block;
24+
display: inline-block;
2525
}
2626

2727
div.code-toolbar > .toolbar > .toolbar-item > a {
28-
cursor: pointer;
28+
cursor: pointer;
2929
}
3030

3131
div.code-toolbar > .toolbar > .toolbar-item > button {
32-
background: none;
33-
border: 0;
34-
color: inherit;
35-
font: inherit;
36-
line-height: normal;
37-
overflow: visible;
38-
padding: 0;
39-
-webkit-user-select: none; /* for button */
32+
background: none;
33+
border: 0;
34+
color: inherit;
35+
font: inherit;
36+
line-height: normal;
37+
overflow: visible;
38+
padding: 0;
39+
user-select: none;
40+
-webkit-user-select: none;
4041
}
4142

4243
div.code-toolbar > .toolbar > .toolbar-item > a,
4344
div.code-toolbar > .toolbar > .toolbar-item > button,
4445
div.code-toolbar > .toolbar > .toolbar-item > span {
45-
color: #aaa;
46-
font-size: 0.8em;
47-
text-transform: none;
48-
background: rgba(215, 215, 215, 0.4);
49-
box-shadow: 0 2px 0 0 rgba(150,150,150,0.8);
50-
border-radius: 0.5em;
51-
display: inline-block;
52-
min-width: 80%;
53-
max-height: 1.75em;
54-
padding-left: 0.45em;
55-
padding-right: 0.45em;
56-
padding-top: 0.1em;
57-
padding-bottom: 0.2em;
46+
color: #aaa;
47+
font-size: 0.8em;
48+
text-transform: none;
49+
background: rgba(215, 215, 215, 0.4);
50+
box-shadow: 0 2px 0 0 rgba(150, 150, 150, 0.8);
51+
border-radius: 0.5em;
52+
display: inline-block;
53+
min-width: 80%;
54+
max-height: 1.75em;
55+
padding-left: 0.45em;
56+
padding-right: 0.45em;
57+
padding-top: 0.1em;
58+
padding-bottom: 0.1em;
5859
}
5960

6061
div.code-toolbar > .toolbar > .toolbar-item > a:hover,
@@ -63,6 +64,6 @@ div.code-toolbar > .toolbar > .toolbar-item > button:hover,
6364
div.code-toolbar > .toolbar > .toolbar-item > button:focus,
6465
div.code-toolbar > .toolbar > .toolbar-item > span:hover,
6566
div.code-toolbar > .toolbar > .toolbar-item > span:focus {
66-
color: rgba(0, 0, 200, 0.8);
67-
text-decoration: none;
67+
color: darkblue;
68+
text-decoration: none;
6869
}

app/thirdparty/assets/prism/prism-markor.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
function usePrismCodeBlock() {
22
elements = document.querySelectorAll("pre > code");
33
elements.forEach(function (element) {
4-
if (!element.classList.contains("language-")) {
4+
let attribute = element.getAttribute("class");
5+
if (attribute == null || attribute.indexOf("language-") == -1) {
56
element.classList.add("language-text");
7+
Prism.highlightElement(element);
68
}
79
});
810
}
911

1012
function wrapCodeBlockWords() {
11-
let preElements = document.querySelectorAll("pre[class*='language-']");
13+
let preElements = document.querySelectorAll("pre");
1214
preElements.forEach((element) => {
1315
element.style.whiteSpace = "pre-wrap";
1416
element.style.overflowWrap = "break-word";

0 commit comments

Comments
 (0)