Skip to content

Commit 8c404b1

Browse files
authored
Merge pull request #14839 from dotty-staging/scaladoc/snippet-fix
Fix snippets hiding and buttons animation
2 parents 10d1700 + 75f80a9 commit 8c404b1

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

scaladoc-js/common/css/code-snippets.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ input:checked + .slider:before {
140140
transition: all .2s ease;
141141
opacity: 0;
142142
visibility: hidden;
143+
display: flex;
144+
flex-direction: row-reverse;
145+
justify-content: flex-start;
143146
}
144147

145148
.snippet:hover .buttons {
146149
opacity: 1;
147150
visibility: visible;
148-
display: flex;
149-
flex-direction: row-reverse;
150-
justify-content: flex-start;
151151
}
152152

153153
.snippet .buttons button {

scaladoc/resources/dotty_res/scripts/ux.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,30 @@ window.addEventListener("DOMContentLoaded", () => {
8989

9090
hljs.registerLanguage("scala", highlightDotty);
9191
hljs.registerAliases(["dotty", "scala3"], "scala");
92-
hljs.initHighlighting();
92+
93+
var aliases = ['language-scala', 'language-dotty', 'language-scala3']
94+
95+
var highlightDeep = function(el) {
96+
el.childNodes.forEach(node => {
97+
if(node.nodeType == Node.TEXT_NODE) {
98+
let newNode = document.createElement('span');
99+
newNode.innerHTML = hljs.highlight(node.textContent, {language: 'scala'}).value;
100+
el.insertBefore(newNode, node);
101+
el.removeChild(node);
102+
} else if(node.nodeType == Node.ELEMENT_NODE) {
103+
highlightDeep(node);
104+
}
105+
})
106+
}
107+
108+
document.querySelectorAll('pre code').forEach( el => {
109+
if (aliases.some(alias => el.classList.contains(alias))) {
110+
highlightDeep(el);
111+
} else {
112+
hljs.highlightElement(el);
113+
}
114+
});
115+
93116

94117
/* listen for the `F` key to be pressed, to focus on the member filter input (if it's present) */
95118
document.body.addEventListener('keydown', e => {

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pre {
8888
margin: 0px;
8989
}
9090
pre code, pre code.hljs {
91+
font-family: var(--mono-font);
9192
font-size: 1em;
9293
padding: 0;
9394
}

0 commit comments

Comments
 (0)