Skip to content

Commit 98493ed

Browse files
committed
Add runkit embeds.
1 parent 8beb944 commit 98493ed

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

doc/api/crypto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
1111

1212
Use `require('crypto')` to access this module.
1313

14-
```js
14+
```js runkit
1515
const crypto = require('crypto');
1616

1717
const secret = 'abcdefg';

doc/api_assets/runkit.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(function () {
2+
if (window.NodeList && !NodeList.prototype.forEach)
3+
NodeList.prototype.forEach = Array.prototype.forEach;
4+
5+
var runnables = document.querySelectorAll(".runkit");
6+
7+
if (runnables.length <= 0)
8+
return;
9+
10+
var script = document.createElement("script");
11+
12+
script.onload = function () {
13+
14+
var version = document
15+
.querySelector('meta[name="nodejs.org:node-version"]')
16+
.content;
17+
18+
RunKit
19+
.getMaximumAvailableNodeVersionInRange(version)
20+
.then(function (nodeVersion) {
21+
if (!nodeVersion)
22+
return;
23+
24+
runnables.forEach(function (runnable) {
25+
var replace = runnable.parentNode;
26+
RunKit.createNotebook({
27+
element: replace,
28+
source: RunKit.sourceFromElement(replace),
29+
clearParentContents: true,
30+
minHeight: '0px',
31+
nodeVersion: nodeVersion,
32+
evaluateOnLoad: RunKit.__nodeShouldEvaluateOnLoad(),
33+
onLoad: function () {
34+
replace.style.background = "none";
35+
replace.style.overflow = "visible";
36+
replace.style.border = "none";
37+
}
38+
});
39+
});
40+
});
41+
};
42+
43+
script.src = "https://embed.runkit.com";
44+
45+
document.body.append(script);
46+
})();

doc/api_assets/style.css

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,18 @@ code {
383383
}
384384

385385
pre {
386-
padding: 1rem;
386+
padding: 4px 8px 8px;
387387
vertical-align: top;
388388
background-color: #f2f2f2;
389389
margin: 1rem;
390390
overflow-x: auto;
391+
border: 1px solid #E7E5E8;
392+
border-radius: 4px;
391393
}
392394

393395
pre > code {
394396
padding: 0;
397+
background: none;
395398
}
396399

397400
pre + h3 {
@@ -652,6 +655,10 @@ td > *:last-child {
652655
}
653656
}
654657

658+
#apicontent {
659+
overflow: hidden;
660+
}
661+
655662
@media print {
656663
html {
657664
height: auto;
@@ -699,7 +706,4 @@ td > *:last-child {
699706
a {
700707
color: inherit;
701708
}
702-
#apicontent {
703-
overflow: hidden;
704-
}
705709
}

doc/template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ <h2>Table of Contents</h2>
5353
</div>
5454
</div>
5555
</div>
56+
<script src="assets/runkit.js"></script>
5657
</body>
5758
</html>

0 commit comments

Comments
 (0)