Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: add runkit embeds #30241

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api/crypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
Use `require('crypto')` to access this module.

```js
// RUNKIT-ENABLE
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the way #22831 marked runkit after the "```js" fence rather than inside it like it is here. This comment is visible when rendered as markdown (and maybe in the json version of the docs too?).

Copy link
Member Author

Choose a reason for hiding this comment

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

it wouldn't highlight correctly in any editors i tried with that approach.

Copy link
Member

Choose a reason for hiding this comment

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

Should we maybe land this as is for now and try to improve the solution later on?
It seems like it would even be an improvement having the comment in markdown compared to now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this comment line is being added into only one of the js examples, is it the intention that it later be added to every single one? That seems overly intrusive.


const crypto = require('crypto');

const secret = 'abcdefg';
Expand Down
44 changes: 44 additions & 0 deletions doc/api_assets/hljs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.hljs-attribute,
.hljs-tag,
.hljs-name,
.hljs-class .hljs-title,
.hljs-selector-id,
.hljs-type,
.hljs-params,
.hljs-function {
color: hsla(288, 8.108%, 37%, 1);
}

.hljs-literal {
color: hsla(39, 81.176%, 57.5%, 1);
}

.hljs-comment,
.hljs-quote {
color: #978998;
}

.hljs-variable,
.hljs-template-variable {
color: #8e85e5;
}

.hljs-link,
.hljs-keyword,
.hljs-built_in,
.hljs-builtin-name {
color: #4a91e2;
}

.hljs-number {
color: #33b277;
}

.hljs-string {
color: #dd6546;
}

.hljs-regexp,
.hljs-symbol {
color: #cc4928;
}
47 changes: 47 additions & 0 deletions doc/api_assets/runkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

(function() {
// https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith
function ReplaceWithPolyfill() {
'use-strict'; // For safari, and IE > 10
var parent = this.parentNode, i = arguments.length, currentNode;
if (!parent) return;
if (!i) // if there are no arguments
parent.removeChild(this);
while (i--) { // i-- decrements i and returns the value of i before the decrement
currentNode = arguments[i];
if (typeof currentNode !== 'object'){
currentNode = this.ownerDocument.createTextNode(currentNode);
} else if (currentNode.parentNode){
currentNode.parentNode.removeChild(currentNode);
}
// the value of "i" below is after the decrement
if (!i) // if currentNode is the first argument (currentNode === arguments[0])
parent.replaceChild(currentNode, this);
else // if currentNode isn't the first
parent.insertBefore(currentNode, this.previousSibling);
}
}
if (!Element.prototype.replaceWith)
Element.prototype.replaceWith = ReplaceWithPolyfill;
if (!CharacterData.prototype.replaceWith)
CharacterData.prototype.replaceWith = ReplaceWithPolyfill;
if (!DocumentType.prototype.replaceWith)
DocumentType.prototype.replaceWith = ReplaceWithPolyfill;
}());

(function() {
var runnables = document.querySelectorAll('.runkit');
runnables.forEach(function(runnable) {
var source = RunKit.sourceFromElement(runnable);
var wrapper = document.createElement('div');
wrapper.class = 'runkit-wrapper';
wrapper.style = 'top: 0; left: -9999px; margin: 1rem;';
RunKit.createNotebook({
element: wrapper,
minHeight: '0px',
source: source,
});
runnable.parentElement.replaceWith(wrapper);
});
}());
25 changes: 0 additions & 25 deletions doc/api_assets/sh.css

This file was deleted.

1 change: 0 additions & 1 deletion doc/api_assets/sh_javascript.min.js

This file was deleted.

Loading