From 7a5c55590a8bc6e45606d4d27162877bfc7ff94a Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sun, 3 Nov 2019 13:57:34 -0800 Subject: [PATCH] doc: add runkit embeds Fixes https://github.com/nodejs/node/issues/21723 Co-authored-by: Francisco Ryan Tolmasky I --- doc/api/crypto.md | 2 + doc/api_assets/hljs.css | 44 +++ doc/api_assets/runkit.js | 47 +++ doc/api_assets/sh.css | 25 -- doc/api_assets/sh_javascript.min.js | 1 - doc/api_assets/sh_main.js | 553 ---------------------------- doc/template.html | 7 +- tools/doc/html.js | 16 +- tools/doc/package-lock.json | 5 + tools/doc/package.json | 1 + 10 files changed, 117 insertions(+), 584 deletions(-) create mode 100644 doc/api_assets/hljs.css create mode 100644 doc/api_assets/runkit.js delete mode 100644 doc/api_assets/sh.css delete mode 100644 doc/api_assets/sh_javascript.min.js delete mode 100644 doc/api_assets/sh_main.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 83f91620a7bfcd..8c52807e083116 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -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 + const crypto = require('crypto'); const secret = 'abcdefg'; diff --git a/doc/api_assets/hljs.css b/doc/api_assets/hljs.css new file mode 100644 index 00000000000000..3bfab9d6471133 --- /dev/null +++ b/doc/api_assets/hljs.css @@ -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; +} diff --git a/doc/api_assets/runkit.js b/doc/api_assets/runkit.js new file mode 100644 index 00000000000000..5acae33fdd6ff0 --- /dev/null +++ b/doc/api_assets/runkit.js @@ -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); + }); +}()); diff --git a/doc/api_assets/sh.css b/doc/api_assets/sh.css deleted file mode 100644 index 234de111f42501..00000000000000 --- a/doc/api_assets/sh.css +++ /dev/null @@ -1,25 +0,0 @@ -.sh_sourceCode { - font-weight: normal; - font-style: normal; -} - -.sh_sourceCode .sh_symbol, -.sh_sourceCode .sh_cbracket { - color: #333; -} - -.sh_sourceCode .sh_keyword { - color: #338; -} - -.sh_sourceCode .sh_string, -.sh_sourceCode .sh_regexp, -.sh_sourceCode .sh_number, -.sh_sourceCode .sh_specialchar { - color: #E54305; -} - -.sh_sourceCode .sh_comment { - color: #666; - font-weight: lighter; -} diff --git a/doc/api_assets/sh_javascript.min.js b/doc/api_assets/sh_javascript.min.js deleted file mode 100644 index d12482ced20918..00000000000000 --- a/doc/api_assets/sh_javascript.min.js +++ /dev/null @@ -1 +0,0 @@ -if(!this.sh_languages){this.sh_languages={}}sh_languages.javascript=[[[/\/\/\//g,"sh_comment",1],[/\/\//g,"sh_comment",7],[/\/\*\*/g,"sh_comment",8],[/\/\*/g,"sh_comment",9],[/\b(?:abstract|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|final|finally|for|function|goto|if|implements|in|instanceof|interface|native|new|null|private|protected|prototype|public|return|static|super|switch|synchronized|throw|throws|this|transient|true|try|typeof|var|volatile|while|with)\b/g,"sh_keyword",-1],[/(\+\+|--|\)|\])(\s*)(\/=?(?![*\/]))/g,["sh_symbol","sh_normal","sh_symbol"],-1],[/(0x[A-Fa-f0-9]+|(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?)(\s*)(\/(?![*\/]))/g,["sh_number","sh_normal","sh_symbol"],-1],[/([A-Za-z$_][A-Za-z0-9$_]*\s*)(\/=?(?![*\/]))/g,["sh_normal","sh_symbol"],-1],[/\/(?:\\.|[^*\\\/])(?:\\.|[^\\\/])*\/[gim]*/g,"sh_regexp",-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/"/g,"sh_string",10],[/'/g,"sh_string",11],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/\{|\}/g,"sh_cbracket",-1],[/\b(?:Math|Infinity|NaN|undefined|arguments)\b/g,"sh_predef_var",-1],[/\b(?:Array|Boolean|Date|Error|EvalError|Function|Number|Object|RangeError|ReferenceError|RegExp|String|SyntaxError|TypeError|URIError|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt)\b/g,"sh_predef_func",-1],[/(?:[A-Za-z]|_)[A-Za-z0-9_]*(?=[ \t]*\()/g,"sh_function",-1]],[[/$/g,null,-2],[/(?:?)|(?:?)/g,"sh_url",-1],[/<\?xml/g,"sh_preproc",2,1],[//g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z](?:[A-Za-z0-9_:.-]*)/g,"sh_keyword",6,1],[/&(?:[A-Za-z0-9]+);/g,"sh_preproc",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*(?:\/)?>/g,"sh_keyword",-1],[/<(?:\/)?[A-Za-z][A-Za-z0-9]*/g,"sh_keyword",6,1],[/@[A-Za-z]+/g,"sh_type",-1],[/(?:TODO|FIXME|BUG)(?:[:]?)/g,"sh_todo",-1]],[[/\?>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/\\(?:\\|")/g,null,-1],[/"/g,"sh_string",-2]],[[/>/g,"sh_preproc",-2],[/([^=" \t>]+)([ \t]*)(=?)/g,["sh_type","sh_normal","sh_symbol"],-1],[/"/g,"sh_string",3]],[[/-->/g,"sh_comment",-2],[/