Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

remark-shiki-twoslash

Package Overview
Dependencies
Maintainers
3
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-shiki-twoslash - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

1

dist/remark-shiki-twoslash.cjs.development.js

@@ -811,2 +811,3 @@ 'use strict';

// 'thing' from the map
// const toReplace: [index:number, length: number, str: string][] = []

@@ -813,0 +814,0 @@ var toReplace = [];

2

dist/remark-shiki-twoslash.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("shiki-twoslash"),e=require("shiki"),n=(t=require("unist-util-visit"))&&"object"==typeof t&&"default"in t?t.default:t;function o(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function u(t){o(a,n,i,u,c,"next",t)}function c(t){o(a,n,i,u,c,"throw",t)}u(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function u(t,r){return t(r={exports:{}},r.exports),r.exports}var c=u((function(t){var r=function(t){var r,e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=Object.create((r&&r.prototype instanceof d?r:d).prototype),i=new S(n||[]);return o._invoke=function(t,r,e){var n=f;return function(o,i){if(n===p)throw new Error("Generator is already running");if(n===v){if("throw"===o)throw i;return T()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=_(a,e);if(u){if(u===y)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===f)throw n=v,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=p;var c=h(t,r,e);if("normal"===c.type){if(n=e.done?v:l,c.arg===y)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n=v,e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f="suspendedStart",l="suspendedYield",p="executing",v="completed",y={};function d(){}function g(){}function m(){}var w={};w[i]=function(){return this};var x=Object.getPrototypeOf,b=x&&x(x(N([])));b&&b!==e&&n.call(b,i)&&(w=b);var L=m.prototype=d.prototype=Object.create(w);function E(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function j(t,r){var e;this._invoke=function(o,i){function a(){return new r((function(e,a){!function e(o,i,a,u){var c=h(t[o],t,i);if("throw"!==c.type){var s=c.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?r.resolve(f.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}(o,i,e,a)}))}return e=e?e.then(a,a):a()}}function _(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,_(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=h(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,y):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function k(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function O(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function N(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function e(){for(;++o<t.length;)if(n.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=r,e.done=!0,e};return a.next=a}}return{next:T}}function T(){return{value:r,done:!0}}return g.prototype=L.constructor=m,m.constructor=g,g.displayName=c(m,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===g||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,u,"GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},E(j.prototype),j.prototype[a]=function(){return this},t.AsyncIterator=j,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new j(s(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},E(L),c(L,u,"Generator"),L[i]=function(){return this},L.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=N,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(O),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function o(n,o){return u.type="throw",u.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),O(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;O(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:N(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),y}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),s=function(t,r,e){var n=e.split(" ")[1],o=[];r.split("\n").forEach((function(r,e){var i=r.trim();if(i.startsWith("// - ")){var a=i.split("// - ")[1].split(" ")[0];t.set(n+"-"+a,o.join("\n"))}else o.push(r)})),t.set(n,o.join("\n"))},h=new Map;function f(t,e,n,o,i){var a,u={json5:"json"};if(u[e]&&(e=u[e]),"twoslash"===e){if(!n)throw new Error("A twoslash code block needs a pragma like 'twoslash include [name]'");s(h,t,n),a=""}else a=o.map((function(o){var a=o.customName.split("/").pop().replace(".json","");return r.renderCodeToHTML(t,e,n.split(" "),{themeName:a},o,i)})).join("\n");return a}var l=function(t,e,n,o){if(void 0===o&&(o={}),!(process&&process.env&&process.env.TWOSLASH_DISABLE)&&n&&n.includes("twoslash"))return function(t,e,n){try{require("crypto")}catch(o){return r.runTwoSlash(t,e,n)}var o=require("crypto").createHash,i=require("fs"),a=i.readFileSync,u=i.existsSync,c=i.mkdirSync,s=i.writeFileSync,h=require("path").join,f=o("sha1").update(t).digest("hex"),l=h(__dirname,"..","..",".cache","twoslash"),p=h(l,f+".json");if(u(p))return JSON.parse(a(p,"utf8"));var v=r.runTwoSlash(t,e,n);return u(l)||c(l,{recursive:!0}),s(p,JSON.stringify(v),"utf8"),v}(function(t,r){for(var e,n=/\/\/ @include: (.*)$/gm,o=[];null!==(e=n.exec(r));){e.index===n.lastIndex&&n.lastIndex++;var i=e[1],a=t.get(i);if(!a){var u="Could not find an includes with the key: '"+i+"'.\nThere is: "+[].concat(t.keys())+".";throw new Error(u)}o.push([e.index,e[0].length,a])}var c=r.toString();return o.reverse().forEach((function(t){c=c.substring(0,t[0])+t[2]+c.substring(t[0]+t[1])})),c}(h,t),e,o)},p=new Map,v=function(){var t=i(c.mark((function t(r){var n;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.themes||(r.theme?[r.theme]:["light-plus"]),t.next=3,Promise.all(n.map(function(){var t=i(c.mark((function t(n){var o,i,u;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(i=p.get(o=n.name||n))){t.next=4;break}return t.abrupt("return",i);case 4:return t.next=6,e.getHighlighter(a({},r,{theme:n,themes:void 0}));case 6:return(u=t.sent).customName=o,p.set(o,u),t.abrupt("return",u);case 10:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),y=function(t){if(!t.vfsRoot)try{t.vfsRoot=require("path").join(__dirname,"..","..","..")}catch(t){}},d=function(){return h.clear()},g=function(t,r){return void 0===r&&(r={}),function(e){var n=e.lang,o=e.meta?"string"==typeof e.meta?e.meta:e.meta.join(" "):"",i=l(e.value,n,o,r);i&&(e.value=i.code,e.lang=i.extension,e.twoslash=i);var a=f(e.value,n,o,t,i);e.type="html",e.value=a,e.children=[]}},m=function(){var t=i(c.mark((function t(r){return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r={}),y(r),d(),t.next=5,v(r);case 5:return t.abrupt("return",{settings:r,highlighters:t.sent});case 7:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}();exports.default=function(t){return void 0===t&&(t={}),y(t),function(){var r=i(c.mark((function r(e){var o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,v(t);case 2:o=r.sent,d(),n(e,"code",g(o,t));case 5:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()},exports.highlightersFromSettings=v,exports.remarkVisitor=g,exports.runTwoSlashOnNode=l,exports.setupForFile=m,exports.transformAttributesToHTML=function(t,r,e,n,o){var i=l(t,r,e,o);return f(i&&i.code||t,r,e,n,i)};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("shiki-twoslash"),e=require("shiki"),n=(t=require("unist-util-visit"))&&"object"==typeof t&&"default"in t?t.default:t;function o(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function i(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var a=t.apply(r,e);function u(t){o(a,n,i,u,c,"next",t)}function c(t){o(a,n,i,u,c,"throw",t)}u(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function u(t,r){return t(r={exports:{}},r.exports),r.exports}var c=u((function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof f?r:f).prototype),i=new E(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=x(a,e);if(u){if(u===h)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=s(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===h)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,i),o}function s(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var h={};function f(){}function l(){}function p(){}var v={};v[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(j([])));y&&y!==r&&e.call(y,o)&&(v=y);var m=p.prototype=f.prototype=Object.create(v);function g(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function w(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,u){var c=s(t[o],t,i);if("throw"!==c.type){var h=c.arg,f=h.value;return f&&"object"==typeof f&&e.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):r.resolve(f).then((function(t){h.value=t,a(h)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,x(t,r),"throw"===r.method))return h;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return h}var n=s(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,h;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,h):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,h)}function b(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function L(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function j(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:_}}function _(){return{value:void 0,done:!0}}return l.prototype=m.constructor=p,p.constructor=l,l.displayName=u(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===l||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},g(w.prototype),w.prototype[i]=function(){return this},t.AsyncIterator=w,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new w(c(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},g(m),u(m,a,"Generator"),m[o]=function(){return this},m.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=j,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(L),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=e.call(i,"catchLoc"),c=e.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,h):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),h},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),L(e),h}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;L(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:j(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),h}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),s=new Map;function h(t,e,n,o,i){var a,u={json5:"json"};if(u[e]&&(e=u[e]),"twoslash"===e){if(!n)throw new Error("A twoslash code block needs a pragma like 'twoslash include [name]'");!function(t,r,e){var n=e.split(" ")[1],o=[];r.split("\n").forEach((function(r,e){var i=r.trim();if(i.startsWith("// - ")){var a=i.split("// - ")[1].split(" ")[0];t.set(n+"-"+a,o.join("\n"))}else o.push(r)})),t.set(n,o.join("\n"))}(s,t,n),a=""}else a=o.map((function(o){var a=o.customName.split("/").pop().replace(".json","");return r.renderCodeToHTML(t,e,n.split(" "),{themeName:a},o,i)})).join("\n");return a}var f=function(t,e,n,o){if(void 0===o&&(o={}),!(process&&process.env&&process.env.TWOSLASH_DISABLE)&&n&&n.includes("twoslash"))return function(t,e,n){try{require("crypto")}catch(o){return r.runTwoSlash(t,e,n)}var o=require("crypto").createHash,i=require("fs"),a=i.readFileSync,u=i.existsSync,c=i.mkdirSync,s=i.writeFileSync,h=require("path").join,f=o("sha1").update(t).digest("hex"),l=h(__dirname,"..","..",".cache","twoslash"),p=h(l,f+".json");if(u(p))return JSON.parse(a(p,"utf8"));var v=r.runTwoSlash(t,e,n);return u(l)||c(l,{recursive:!0}),s(p,JSON.stringify(v),"utf8"),v}(function(t,r){for(var e,n=/\/\/ @include: (.*)$/gm,o=[];null!==(e=n.exec(r));){e.index===n.lastIndex&&n.lastIndex++;var i=e[1],a=t.get(i);if(!a){var u="Could not find an includes with the key: '"+i+"'.\nThere is: "+[].concat(t.keys())+".";throw new Error(u)}o.push([e.index,e[0].length,a])}var c=r.toString();return o.reverse().forEach((function(t){c=c.substring(0,t[0])+t[2]+c.substring(t[0]+t[1])})),c}(s,t),e,o)},l=new Map,p=function(){var t=i(c.mark((function t(r){var n;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.themes||(r.theme?[r.theme]:["light-plus"]),t.next=3,Promise.all(n.map(function(){var t=i(c.mark((function t(n){var o,i,u;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(i=l.get(o=n.name||n))){t.next=4;break}return t.abrupt("return",i);case 4:return t.next=6,e.getHighlighter(a({},r,{theme:n,themes:void 0}));case 6:return(u=t.sent).customName=o,l.set(o,u),t.abrupt("return",u);case 10:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}()));case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}(),v=function(t){if(!t.vfsRoot)try{t.vfsRoot=require("path").join(__dirname,"..","..","..")}catch(t){}},d=function(){return s.clear()},y=function(t,r){return void 0===r&&(r={}),function(e){var n=e.lang,o=e.meta?"string"==typeof e.meta?e.meta:e.meta.join(" "):"",i=f(e.value,n,o,r);i&&(e.value=i.code,e.lang=i.extension,e.twoslash=i);var a=h(e.value,n,o,t,i);e.type="html",e.value=a,e.children=[]}},m=function(){var t=i(c.mark((function t(r){return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r={}),v(r),d(),t.next=5,p(r);case 5:return t.abrupt("return",{settings:r,highlighters:t.sent});case 7:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}();exports.default=function(t){return void 0===t&&(t={}),v(t),function(){var r=i(c.mark((function r(e){var o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,p(t);case 2:o=r.sent,d(),n(e,"code",y(o,t));case 5:case"end":return r.stop()}}),r)})));return function(t){return r.apply(this,arguments)}}()},exports.highlightersFromSettings=p,exports.remarkVisitor=y,exports.runTwoSlashOnNode=f,exports.setupForFile=m,exports.transformAttributesToHTML=function(t,r,e,n,o){var i=f(t,r,e,o);return h(i&&i.code||t,r,e,n,i)};
//# sourceMappingURL=remark-shiki-twoslash.cjs.production.min.js.map

@@ -805,2 +805,3 @@ import { runTwoSlash, renderCodeToHTML } from 'shiki-twoslash';

// 'thing' from the map
// const toReplace: [index:number, length: number, str: string][] = []

@@ -807,0 +808,0 @@ var toReplace = [];

{
"name": "remark-shiki-twoslash",
"version": "1.3.0",
"version": "1.4.0",
"license": "MIT",
"homepage": "https://github.com/microsoft/TypeScript-Website",
"homepage": "https://github.com/shikijs/twoslash",
"repository": {
"url": "https://github.com/microsoft/TypeScript-Website.git",
"url": "https://github.com/shikijs/twoslash.git",
"directory": "packages/remark-shiki-twoslash",

@@ -12,5 +12,5 @@ "type": "git"

"bugs": {
"url": "https://github.com/microsoft/TypeScript-Website/issues"
"url": "https://github.com/shikijs/twoslash/issues"
},
"description": "A remark plugin which adds twoslash code samples for TypeScript",
"description": "A remark plugin which renders code samples for all languages via Shiki, but has some real cool features for TS/JS code",
"author": "Orta Therox",

@@ -25,4 +25,2 @@ "main": "./dist/index.js",

"start": "tsdx watch",
"bootstrap": "yarn build",
"prepublishOnly": "yarn build",
"build": "tsdx build",

@@ -36,21 +34,18 @@ "test": "tsdx test",

"shiki": "^0.9.3",
"shiki-twoslash": "1.3.1",
"shiki-twoslash": "1.4.0",
"tslib": "2.1.0",
"typescript": "*",
"unist-util-visit": "^2.0.0"
"typescript": ">3",
"unist-util-visit": "^2.0.0",
"regenerator-runtime": "^0.13.7"
},
"devDependencies": {
"@mdx-js/mdx": "^1.5.5",
"@mdx-js/mdx": "^1.6.2",
"@types/jest": "^25.1.3",
"babel-jest": "^26.6.3",
"mdx": "*",
"rehype-stringify": "^6.0.1",
"tsdx": "^0.14.1",
"tslib": "^1.10.0",
"typescript": "*",
"typescript": ">3",
"unified": "^8.4.2"
},
"jest": {
"testEnvironment": "node"
}
}
### remark-shiki-twoslash
Sets up markdown code blocks to run through [shiki](https://shiki.matsu.io) which means it gets the VS Code quality
[You might first want to read the user docs.](https://shikijs.github.io/twoslash/).
This module sets up markdown code blocks to run through [shiki](https://shiki.matsu.io) which means it gets the VS Code quality
syntax highlighting, with optional inline TypeScript compiler-backed tooling.

@@ -8,3 +10,3 @@

In addition to all the languages shiki handles ([it's a lot](https://github.com/octref/shiki/blob/master/packages/languages/README.md#literal-values)), this module adds opt-in [@typescript/twoslash](https://github.com/microsoft/TypeScript-Website/tree/v2/packages/ts-twoslasher) rendering for TypeScript code blocks and tsconfig JSON files.
In addition to all the languages shiki handles (and [it's a lot](https://github.com/octref/shiki/blob/master/packages/languages/README.md#literal-values)), this module adds opt-in [@typescript/twoslash](https://github.com/microsoft/TypeScript-Website/tree/v2/packages/ts-twoslasher) rendering for TypeScript code blocks and tsconfig JSON files.

@@ -35,246 +37,254 @@ This module powers the code samples on the TypeScript website.

This CSS comes from the [TypeScript website's scss](https://github.com/microsoft/TypeScript-website/blob/v2/packages/typescriptlang-org/src/templates/markdown-twoslash.scss)
This CSS is based on from the [TypeScript website's scss](https://github.com/microsoft/TypeScript-website/blob/v2/packages/typescriptlang-org/src/templates/markdown-twoslash.scss)
You should consider it a base to work from, rather than a perfect for every project reference.
```css
/* Code blocks look like:
<pre class='shiki [theme-name] twoslash'>
<div class='language-id>[lang-id]</div>
<!-- AUTO-GENERATED-CONTENT:START (CODE:src=../../packages/shiki-twoslash/style.css) -->
<!-- The below code snippet is automatically added from ../../packages/shiki-twoslash/style.css -->
```css
/* Start of Shiki Twoslash CSS
Code blocks look like:
<pre class='shiki lsp twoslash [theme-name]'>
<div class='language-id>[lang-id]</div>
<div class='code-container'>
<code>
<div class='line'>[the code as a series of spans]</div>
</code>
<code>[the code as a series of spans]</code>
<a href='playground...'>Try</a> (optional)
</div>
</pre>
*/
pre {
/* Give the text some space to breathe */
padding: 12px;
/* All code samples get a grey border, twoslash ones get a different color */
border-left: 1px solid #999;
border-bottom: 1px solid #999;
margin-bottom: 3rem;
/* Important to allow the code to move horizontally;
*/
overflow: auto;
/* So that folks know you can highlight */
position: relative;
}
pre.shiki {
overflow: initial;
}
pre.shiki:hover .dim {
opacity: 1;
}
pre.shiki div.dim {
opacity: 0.5;
}
pre.shiki div.dim,
pre.shiki div.highlight {
margin: 0;
padding: 0;
}
pre.shiki div.highlight {
opacity: 1;
background-color: #f1f8ff;
}
pre.shiki div.line {
min-height: 1rem;
}
pre.twoslash {
border-color: #719af4;
}
pre .code-container {
overflow: auto;
}
pre .code-container > a {
position: absolute;
right: 8px;
bottom: 8px;
border-radius: 4px;
border: 1px solid #719af4;
padding: 0 8px;
color: #719af4;
text-decoration: none;
opacity: 0;
transition-timing-function: ease;
transition: opacity 0.3s;
}
@media (prefers-reduced-motion: reduce) {
pre .code-container > a {
transition: none;
}
}
pre .code-container > a:hover {
color: white;
background-color: #719af4;
}
pre .code-container:hover a {
opacity: 1;
}
pre code {
/** Style setup */
font-size: 15px;
font-family: var(--code-font);
white-space: pre;
-webkit-overflow-scrolling: touch;
}
pre code a {
text-decoration: none;
}
pre data-err {
background: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23c94824'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E")
repeat-x bottom left;
padding-bottom: 3px;
}
pre .query {
margin-bottom: 10px;
color: #137998;
display: inline-block;
}
pre .error,
pre .error-behind {
margin-left: -14px;
margin-top: 8px;
margin-bottom: 4px;
padding: 6px;
padding-left: 14px;
width: calc(100% - 19px);
white-space: pre-wrap;
display: block;
}
pre .error {
position: absolute;
background-color: #fee;
border-left: 2px solid #bf1818;
/* Give the space to the error code */
display: flex;
align-items: center;
color: black;
}
pre .error .code {
display: none;
}
pre .error-behind {
user-select: none;
color: #fee;
}
pre .arrow {
/* Transparent background */
background-color: #eee;
position: relative;
top: -7px;
margin-left: 0.1rem;
/* Edges */
border-left: 1px solid #eee;
border-top: 1px solid #eee;
transform: translateY(25%) rotate(45deg);
/* Size */
height: 8px;
width: 8px;
}
pre .popover {
margin-bottom: 10px;
background-color: #eee;
display: inline-block;
padding: 0 0.5rem 0.3rem;
margin-top: 10px;
border-radius: 3px;
}
pre .inline-completions ul.dropdown {
display: inline-block;
position: absolute;
width: 240px;
background-color: gainsboro;
color: grey;
padding-top: 4px;
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, Courier New, monospace;
font-size: 0.8rem;
margin: 0;
padding: 0;
border-left: 4px solid #4b9edd;
}
pre .inline-completions ul.dropdown::before {
background-color: #4b9edd;
width: 2px;
position: absolute;
top: -1.2rem;
left: -3px;
content: " ";
}
pre .inline-completions ul.dropdown li {
overflow-x: hidden;
padding-left: 4px;
margin-bottom: 4px;
}
pre .inline-completions ul.dropdown li.deprecated {
text-decoration: line-through;
}
pre .inline-completions ul.dropdown li span.result-found {
color: #4b9edd;
}
pre .inline-completions ul.dropdown li span.result {
width: 100px;
color: black;
display: inline-block;
}
.dark-theme .markdown pre {
background-color: #d8d8d8;
border-color: #ddd;
filter: invert(98%) hue-rotate(180deg);
}
data-lsp {
/* Ensures there's no 1px jump when the hover happens above */
border-bottom: 1px dotted transparent;
/* Fades in unobtrusively */
transition-timing-function: ease;
transition: border-color 0.3s;
/* Respect people's wishes to not have animations */
}
@media (prefers-reduced-motion: reduce) {
data-lsp {
transition: none;
}
}
/** When you mouse over the pre, show the underlines */
pre:hover data-lsp {
border-color: #747474;
}
/** The tooltip-like which provides the LSP response */
#twoslash-mouse-hover-info {
background-color: #3f3f3f;
color: #fff;
text-align: left;
padding: 5px 8px;
border-radius: 2px;
font-family: "Cascadia Mono-SemiLight", "JetBrains Mono", Menlo, Monaco, Consolas, Courier New, monospace;
font-size: 14px;
white-space: pre-wrap;
border-radius: 2px;
z-index: 100;
pointer-events: none;
}
```
</pre>
*/
1. **Add the JS** for hover info to your component:
In a React codebase:
pre {
/* In theory shiki will overwrite these, but this is to make sure there are defaults regardless */
background-color: white;
color: black;
```jsx
import React, { useEffect } from "react"
import { setupTwoslashHovers } from "shiki-twoslash/dist/dom";
/* Give it some space to breathe */
padding: 12px;
export default () => {
// Add a the hovers
useEffect(setupTwoslashHovers, [])
/* All code samples get a grey border, twoslash ones get a different color */
border-left: 1px solid #999;
border-bottom: 1px solid #999;
// Normal JSX for your component
return </>
}
```
margin-bottom: 3rem;
In a non-React codebase, you can still call `setupTwoslashHovers` via a bundler or module import, it will set up all
of the hovers on the page, this will need to be _after_ the HTML is set up.
/* Important to allow the code to move horizontally; */
overflow-x: auto;
position: relative;
}
pre.shiki {
overflow-x: auto;
}
pre.shiki:hover .dim {
opacity: 1;
}
pre.shiki div.dim {
opacity: 0.5;
}
pre.shiki div.dim, pre.shiki div.highlight {
margin: 0;
padding: 0;
}
pre.shiki div.highlight {
opacity: 1;
background-color: #f1f8ff;
}
pre.shiki div.line {
min-height: 1rem;
}
/* Visually differentiates twoslash code samples */
pre.twoslash {
border-color: #719af4;
}
/** When you mouse over the pre, show the underlines */
pre.twoslash:hover data-lsp {
border-color: #747474;
}
/** The tooltip-like which provides the LSP response */
pre.twoslash data-lsp:hover::before {
content: attr(lsp);
position: absolute;
transform: translate(0, 1rem);
background-color: #3f3f3f;
color: #fff;
text-align: left;
padding: 5px 8px;
border-radius: 2px;
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, Courier New, monospace;
font-size: 14px;
white-space: pre-wrap;
}
pre .code-container {
overflow: auto;
}
/* The try button */
pre .code-container > a {
position: absolute;
right: 8px;
bottom: 8px;
border-radius: 4px;
border: 1px solid #719af4;
padding: 0 8px;
color: #719af4;
text-decoration: none;
opacity: 0;
transition-timing-function: ease;
transition: opacity 0.3s;
}
/* Respect no animations */
@media (prefers-reduced-motion: reduce) {
pre .code-container > a {
transition: none;
}
}
pre .code-container > a:hover {
color: white;
background-color: #719af4;
}
pre .code-container:hover a {
opacity: 1;
}
pre code {
font-size: 15px;
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, Courier New, monospace;;
white-space: pre;
-webkit-overflow-scrolling: touch;
}
pre code a {
text-decoration: none;
}
pre data-err {
/* Extracted from VS Code */
background: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%206%203'%20enable-background%3D'new%200%200%206%203'%20height%3D'3'%20width%3D'6'%3E%3Cg%20fill%3D'%23c94824'%3E%3Cpolygon%20points%3D'5.5%2C0%202.5%2C3%201.1%2C3%204.1%2C0'%2F%3E%3Cpolygon%20points%3D'4%2C0%206%2C2%206%2C0.6%205.4%2C0'%2F%3E%3Cpolygon%20points%3D'0%2C2%201%2C3%202.4%2C3%200%2C0.6'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E") repeat-x bottom left;
padding-bottom: 3px;
}
pre .query {
margin-bottom: 10px;
color: #137998;
display: inline-block;
}
/* In order to have the 'popped out' style design and to not break the layout
/* we need to place a fake and un-selectable copy of the error which _isn't_ broken out
/* behind the actual error message.
/* This sections keeps both of those two in in sync */
pre .error, pre .error-behind {
margin-left: -14px;
margin-top: 8px;
margin-bottom: 4px;
padding: 6px;
padding-left: 14px;
width: calc(100% - 19px);
white-space: pre-wrap;
display: block;
}
pre .error {
position: absolute;
background-color: #fee;
border-left: 2px solid #bf1818;
/* Give the space to the error code */
display: flex;
align-items: center;
color: black;
}
pre .error .code {
display: none;
}
pre .error-behind {
user-select: none;
color: #fee;
}
/* Queries */
pre .arrow {
/* Transparent background */
background-color: #eee;
position: relative;
top: -7px;
margin-left: 0.1rem;
/* Edges */
border-left: 1px solid #eee;
border-top: 1px solid #eee;
transform: translateY(25%) rotate(45deg);
/* Size */
height: 8px;
width: 8px;
}
pre .popover {
margin-bottom: 10px;
background-color: #eee;
display: inline-block;
padding: 0 0.5rem 0.3rem;
margin-top: 10px;
border-radius: 3px;
}
/* Completion */
pre .inline-completions ul.dropdown {
display: inline-block;
position: absolute;
width: 240px;
background-color: gainsboro;
color: grey;
padding-top: 4px;
font-family: var(--code-font);
font-size: 0.8rem;
margin: 0;
padding: 0;
border-left: 4px solid #4b9edd;
}
pre .inline-completions ul.dropdown::before {
background-color: #4b9edd;
width: 2px;
position: absolute;
top: -1.2rem;
left: -3px;
content: " ";
}
pre .inline-completions ul.dropdown li {
overflow-x: hidden;
padding-left: 4px;
margin-bottom: 4px;
}
pre .inline-completions ul.dropdown li.deprecated {
text-decoration: line-through;
}
pre .inline-completions ul.dropdown li span.result-found {
color: #4b9edd;
}
pre .inline-completions ul.dropdown li span.result {
width: 100px;
color: black;
display: inline-block;
}
.dark-theme .markdown pre {
background-color: #d8d8d8;
border-color: #ddd;
filter: invert(98%) hue-rotate(180deg);
}
data-lsp {
/* Ensures there's no 1px jump when the hover happens */
border-bottom: 1px dotted transparent;
/* Fades in unobtrusively */
transition-timing-function: ease;
transition: border-color 0.3s;
}
/* Respect people's wishes to not have animations */
@media (prefers-reduced-motion: reduce) {
data-lsp {
transition: none;
}
}
```
<!-- AUTO-GENERATED-CONTENT:END -->
### Verify

@@ -323,4 +333,8 @@

This plugin passes the config options directly to Shiki and Twoslash. You probably will want to
[set `theme`](https://github.com/octref/shiki/blob/master/packages/themes/README.md#shiki-themes), then also the [TwoslashOptions here](https://www.npmjs.com/package/@typescript/twoslash#api-1).
[set `theme`](https://github.com/octref/shiki/blob/master/packages/themes/README.md#shiki-themes). The full reference for the plugin options [is available here](https://github.com/shikijs/twoslash/blob/main/packages/shiki-twoslash/README.md#user-settings).
### Learning Twoslash
The TypeScript website has a learning environment for twoslash in the [Bug Workbench](https://www.typescriptlang.org/dev/bug-workbench/).
### Light / Dark Modes

@@ -405,1 +419,9 @@

````
### Editor Experience
See [VSCode Twoslash](https://marketplace.visualstudio.com/items?itemName=Orta.vscode-twoslash) to get auto-complete for twoslash markup and quick links to the Twoslash online REPL.
### CLI Tooling
See [twoslash-cli](https://www.npmjs.com/package/twoslash-cli) to have a CI which verifies your code samples.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc