gatsby-remark-shiki-twoslash
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -767,6 +767,6 @@ 'use strict'; | ||
var visitor = function visitor(highlighter, twoslashSettings) { | ||
var visitor = function visitor(highlighter, nullSettings) { | ||
return function (node) { | ||
var lang = node.lang; | ||
var settings = twoslashSettings || {}; | ||
var settings = nullSettings || {}; | ||
var shouldDisableTwoslash = process && process.env && !!process.env.TWOSLASH_DISABLE; // Run twoslash | ||
@@ -796,6 +796,13 @@ | ||
if (node.meta && node.meta.includes("twoslash")) { | ||
var results = cachedTwoslashCall(node.value, node.lang, settings); | ||
node.value = results.code; | ||
node.lang = results.extension; | ||
node.twoslash = results; | ||
try { | ||
var results = cachedTwoslashCall(node.value, node.lang, settings); | ||
node.value = results.code; | ||
node.lang = results.extension; | ||
node.twoslash = results; | ||
} catch (error) { | ||
var _node$position; | ||
error.message = "gatsby-remark-shiki-twoslash: Error thrown in code sample on line " + ((_node$position = node.position) == null ? void 0 : _node$position.start.line) + "\n\n" + error.message; | ||
throw error; | ||
} | ||
} | ||
@@ -806,3 +813,3 @@ }; | ||
var cachedTwoslashCall = function cachedTwoslashCall(code, lang, settings, twoslashDefaults) { | ||
var cachedTwoslashCall = function cachedTwoslashCall(code, lang, settings) { | ||
var shasum = crypto.createHash("sha1"); | ||
@@ -816,3 +823,3 @@ var codeSha = shasum.update(code).digest("hex"); | ||
} else { | ||
var results = shikiTwoslash.runTwoSlash(code, lang, settings, twoslashDefaults); | ||
var results = shikiTwoslash.runTwoSlash(code, lang, settings); | ||
if (!fs.existsSync(cacheRoot)) fs.mkdirSync(cacheRoot, { | ||
@@ -838,3 +845,3 @@ recursive: true | ||
/*#__PURE__*/ | ||
runtime_1.mark(function _callee(_ref, shikiSettings, settings) { | ||
runtime_1.mark(function _callee(_ref, settings) { | ||
var markdownAST, highlighter; | ||
@@ -846,10 +853,15 @@ return runtime_1.wrap(function _callee$(_context) { | ||
markdownAST = _ref.markdownAST; | ||
_context.next = 3; | ||
return shikiTwoslash.createShikiHighlighter(shikiSettings); | ||
case 3: | ||
if (settings === void 0) { | ||
settings = {}; | ||
} | ||
_context.next = 4; | ||
return shikiTwoslash.createShikiHighlighter(settings); | ||
case 4: | ||
highlighter = _context.sent; | ||
visit(markdownAST, "code", visitor(highlighter, settings)); | ||
case 5: | ||
case 6: | ||
case "end": | ||
@@ -862,3 +874,3 @@ return _context.stop(); | ||
return function remarkShiki(_x, _x2, _x3) { | ||
return function remarkShiki(_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
@@ -872,3 +884,8 @@ }; | ||
var markdownAST = _ref3.markdownAST; | ||
return visit(markdownAST, "code", runTwoSlashOnNode(settings || {})); | ||
if (settings === void 0) { | ||
settings = {}; | ||
} | ||
return visit(markdownAST, "code", runTwoSlashOnNode(settings)); | ||
}; | ||
@@ -875,0 +892,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("shiki-twoslash"),e=(t=require("unist-util-visit"))&&"object"==typeof t&&"default"in t?t.default:t,n=require("crypto"),o=require("fs"),i=require("path");function a(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function c(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var i=t.apply(r,e);function c(t){a(i,n,o,c,u,"next",t)}function u(t){a(i,n,o,c,u,"throw",t)}c(void 0)}))}}function u(t,r){return t(r={exports:{}},r.exports),r.exports}var s=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",c=o.toStringTag||"@@toStringTag";function u(t,r,e,n){var o=Object.create((r&&r.prototype instanceof y?r:y).prototype),i=new O(n||[]);return o._invoke=function(t,r,e){var n=h;return function(o,i){if(n===l)throw new Error("Generator is already running");if(n===p){if("throw"===o)throw i;return T()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=_(a,e);if(c){if(c===v)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===h)throw n=p,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=l;var u=s(t,r,e);if("normal"===u.type){if(n=e.done?p:f,u.arg===v)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=p,e.method="throw",e.arg=u.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=u;var h="suspendedStart",f="suspendedYield",l="executing",p="completed",v={};function y(){}function d(){}function g(){}var m={};m[i]=function(){return this};var w=Object.getPrototypeOf,x=w&&w(w(k([])));x&&x!==e&&n.call(x,i)&&(m=x);var L=g.prototype=y.prototype=Object.create(m);function E(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function S(t){var r;this._invoke=function(e,o){function i(){return new Promise((function(r,i){!function r(e,o,i,a){var c=s(t[e],t,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==typeof h&&n.call(h,"__await")?Promise.resolve(h.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):Promise.resolve(h).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,a)}))}a(c.arg)}(e,o,r,i)}))}return r=r?r.then(i,i):i()}}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 v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=s(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,v;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,v):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}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 j(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function k(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 d.prototype=L.constructor=g,g.constructor=d,g[c]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},E(S.prototype),S.prototype[a]=function(){return this},t.AsyncIterator=S,t.async=function(r,e,n,o){var i=new S(u(r,e,n,o));return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},E(L),L[c]="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=k,O.prototype={constructor:O,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(j),!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 c.type="throw",c.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],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){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,v):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),v},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),j(e),v}},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;j(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:k(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),v}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),h=function(t,e){return function(n){var o=n.lang;process&&process.env&&process.env.TWOSLASH_DISABLE||f(e||{})(n);var i={json5:"json"};i[o]&&(o=i[o]);var a=r.renderCodeToHTML(n.value,o,n.meta||[],{},t,n.twoslash);n.type="html",n.value=a,n.children=[]}},f=function(t){return function(r){if(r.meta&&r.meta.includes("twoslash")){var e=l(r.value,r.lang,t);r.value=e.code,r.lang=e.extension,r.twoslash=e}}},l=function(t,e,a,c){var u=n.createHash("sha1").update(t).digest("hex"),s=i.join(__dirname,"..","..",".cache","twoslash"),h=i.join(s,u+".json");if(o.existsSync(h))return JSON.parse(o.readFileSync(h,"utf8"));var f=r.runTwoSlash(t,e,a,c);return o.existsSync(s)||o.mkdirSync(s,{recursive:!0}),o.writeFileSync(h,JSON.stringify(f),"utf8"),f},p=function(){var t=c(s.mark((function t(n,o,i){var a;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=n.markdownAST,t.next=3,r.createShikiHighlighter(o);case 3:e(a,"code",h(t.sent,i));case 5:case"end":return t.stop()}}),t)})));return function(r,e,n){return t.apply(this,arguments)}}();exports.cachedTwoslashCall=l,exports.default=p,exports.runTwoSlashAcrossDocument=function(t,r){return e(t.markdownAST,"code",f(r||{}))},exports.runTwoSlashOnNode=f,exports.visitor=h; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,r=require("shiki-twoslash"),e=(t=require("unist-util-visit"))&&"object"==typeof t&&"default"in t?t.default:t,n=require("crypto"),o=require("fs"),i=require("path");function a(t,r,e,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void e(t)}c.done?r(u):Promise.resolve(u).then(n,o)}function c(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var i=t.apply(r,e);function c(t){a(i,n,o,c,u,"next",t)}function u(t){a(i,n,o,c,u,"throw",t)}c(void 0)}))}}function u(t,r){return t(r={exports:{}},r.exports),r.exports}var s=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",c=o.toStringTag||"@@toStringTag";function u(t,r,e,n){var o=Object.create((r&&r.prototype instanceof y?r:y).prototype),i=new k(n||[]);return o._invoke=function(t,r,e){var n=h;return function(o,i){if(n===f)throw new Error("Generator is already running");if(n===p){if("throw"===o)throw i;return T()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=b(a,e);if(c){if(c===v)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===h)throw n=p,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=f;var u=s(t,r,e);if("normal"===u.type){if(n=e.done?p:l,u.arg===v)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=p,e.method="throw",e.arg=u.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=u;var h="suspendedStart",l="suspendedYield",f="executing",p="completed",v={};function y(){}function d(){}function g(){}var m={};m[i]=function(){return this};var w=Object.getPrototypeOf,x=w&&w(w(O([])));x&&x!==e&&n.call(x,i)&&(m=x);var L=g.prototype=y.prototype=Object.create(m);function E(t){["next","throw","return"].forEach((function(r){t[r]=function(t){return this._invoke(r,t)}}))}function S(t){var r;this._invoke=function(e,o){function i(){return new Promise((function(r,i){!function r(e,o,i,a){var c=s(t[e],t,o);if("throw"!==c.type){var u=c.arg,h=u.value;return h&&"object"==typeof h&&n.call(h,"__await")?Promise.resolve(h.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):Promise.resolve(h).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,a)}))}a(c.arg)}(e,o,r,i)}))}return r=r?r.then(i,i):i()}}function b(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,b(t,e),"throw"===e.method))return v;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=s(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,v;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,v):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,v)}function _(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 j(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function O(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 d.prototype=L.constructor=g,g.constructor=d,g[c]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},E(S.prototype),S.prototype[a]=function(){return this},t.AsyncIterator=S,t.async=function(r,e,n,o){var i=new S(u(r,e,n,o));return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},E(L),L[c]="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=O,k.prototype={constructor:k,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(j),!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 c.type="throw",c.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],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){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,v):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),v},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),j(e),v}},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;j(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),v}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}})),h=function(t,e){return function(n){var o=n.lang;process&&process.env&&process.env.TWOSLASH_DISABLE||l(e||{})(n);var i={json5:"json"};i[o]&&(o=i[o]);var a=r.renderCodeToHTML(n.value,o,n.meta||[],{},t,n.twoslash);n.type="html",n.value=a,n.children=[]}},l=function(t){return function(r){if(r.meta&&r.meta.includes("twoslash"))try{var e=f(r.value,r.lang,t);r.value=e.code,r.lang=e.extension,r.twoslash=e}catch(t){var n;throw t.message="gatsby-remark-shiki-twoslash: Error thrown in code sample on line "+(null==(n=r.position)?void 0:n.start.line)+"\n\n"+t.message,t}}},f=function(t,e,a){var c=n.createHash("sha1").update(t).digest("hex"),u=i.join(__dirname,"..","..",".cache","twoslash"),s=i.join(u,c+".json");if(o.existsSync(s))return JSON.parse(o.readFileSync(s,"utf8"));var h=r.runTwoSlash(t,e,a);return o.existsSync(u)||o.mkdirSync(u,{recursive:!0}),o.writeFileSync(s,JSON.stringify(h),"utf8"),h},p=function(){var t=c(s.mark((function t(n,o){var i;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return i=n.markdownAST,void 0===o&&(o={}),t.next=4,r.createShikiHighlighter(o);case 4:e(i,"code",h(t.sent,o));case 6:case"end":return t.stop()}}),t)})));return function(r,e){return t.apply(this,arguments)}}();exports.cachedTwoslashCall=f,exports.default=p,exports.runTwoSlashAcrossDocument=function(t,r){return void 0===r&&(r={}),e(t.markdownAST,"code",l(r))},exports.runTwoSlashOnNode=l,exports.visitor=h; | ||
//# sourceMappingURL=gatsby-remark-shiki-twoslash.cjs.production.min.js.map |
@@ -761,6 +761,6 @@ import { renderCodeToHTML, runTwoSlash, createShikiHighlighter } from 'shiki-twoslash'; | ||
var visitor = function visitor(highlighter, twoslashSettings) { | ||
var visitor = function visitor(highlighter, nullSettings) { | ||
return function (node) { | ||
var lang = node.lang; | ||
var settings = twoslashSettings || {}; | ||
var settings = nullSettings || {}; | ||
var shouldDisableTwoslash = process && process.env && !!process.env.TWOSLASH_DISABLE; // Run twoslash | ||
@@ -790,6 +790,13 @@ | ||
if (node.meta && node.meta.includes("twoslash")) { | ||
var results = cachedTwoslashCall(node.value, node.lang, settings); | ||
node.value = results.code; | ||
node.lang = results.extension; | ||
node.twoslash = results; | ||
try { | ||
var results = cachedTwoslashCall(node.value, node.lang, settings); | ||
node.value = results.code; | ||
node.lang = results.extension; | ||
node.twoslash = results; | ||
} catch (error) { | ||
var _node$position; | ||
error.message = "gatsby-remark-shiki-twoslash: Error thrown in code sample on line " + ((_node$position = node.position) == null ? void 0 : _node$position.start.line) + "\n\n" + error.message; | ||
throw error; | ||
} | ||
} | ||
@@ -800,3 +807,3 @@ }; | ||
var cachedTwoslashCall = function cachedTwoslashCall(code, lang, settings, twoslashDefaults) { | ||
var cachedTwoslashCall = function cachedTwoslashCall(code, lang, settings) { | ||
var shasum = createHash("sha1"); | ||
@@ -810,3 +817,3 @@ var codeSha = shasum.update(code).digest("hex"); | ||
} else { | ||
var results = runTwoSlash(code, lang, settings, twoslashDefaults); | ||
var results = runTwoSlash(code, lang, settings); | ||
if (!existsSync(cacheRoot)) mkdirSync(cacheRoot, { | ||
@@ -832,3 +839,3 @@ recursive: true | ||
/*#__PURE__*/ | ||
runtime_1.mark(function _callee(_ref, shikiSettings, settings) { | ||
runtime_1.mark(function _callee(_ref, settings) { | ||
var markdownAST, highlighter; | ||
@@ -840,10 +847,15 @@ return runtime_1.wrap(function _callee$(_context) { | ||
markdownAST = _ref.markdownAST; | ||
_context.next = 3; | ||
return createShikiHighlighter(shikiSettings); | ||
case 3: | ||
if (settings === void 0) { | ||
settings = {}; | ||
} | ||
_context.next = 4; | ||
return createShikiHighlighter(settings); | ||
case 4: | ||
highlighter = _context.sent; | ||
visit(markdownAST, "code", visitor(highlighter, settings)); | ||
case 5: | ||
case 6: | ||
case "end": | ||
@@ -856,3 +868,3 @@ return _context.stop(); | ||
return function remarkShiki(_x, _x2, _x3) { | ||
return function remarkShiki(_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
@@ -866,3 +878,8 @@ }; | ||
var markdownAST = _ref3.markdownAST; | ||
return visit(markdownAST, "code", runTwoSlashOnNode(settings || {})); | ||
if (settings === void 0) { | ||
settings = {}; | ||
} | ||
return visit(markdownAST, "code", runTwoSlashOnNode(settings)); | ||
}; | ||
@@ -869,0 +886,0 @@ |
@@ -1,5 +0,4 @@ | ||
import { ShikiTwoslashSettings } from "shiki-twoslash"; | ||
import type { Highlighter, Lang, HighlighterOptions } from "shiki"; | ||
import { UserConfigSettings } from "shiki-twoslash"; | ||
import type { Highlighter, Lang } from "shiki"; | ||
import { Node } from "unist"; | ||
import { TwoSlashOptions } from "@typescript/twoslash"; | ||
declare type RichNode = Node & { | ||
@@ -17,3 +16,3 @@ lang: Lang; | ||
*/ | ||
export declare const visitor: (highlighter: Highlighter, twoslashSettings?: ShikiTwoslashSettings | undefined) => (node: RichNode) => void; | ||
export declare const visitor: (highlighter: Highlighter, nullSettings?: UserConfigSettings | undefined) => (node: RichNode) => void; | ||
/** | ||
@@ -23,5 +22,5 @@ * Runs twoslash across an AST node, switching out the text content, and lang | ||
*/ | ||
export declare const runTwoSlashOnNode: (settings: ShikiTwoslashSettings) => (node: RichNode) => void; | ||
export declare const runTwoSlashOnNode: (settings: UserConfigSettings) => (node: RichNode) => void; | ||
/** Keeps a cache of the JSON responses in node_modules/.cache/twoslash */ | ||
export declare const cachedTwoslashCall: (code: string, lang: string, settings?: ShikiTwoslashSettings | undefined, twoslashDefaults?: TwoSlashOptions | undefined) => any; | ||
export declare const cachedTwoslashCall: (code: string, lang: string, settings: UserConfigSettings) => any; | ||
/** | ||
@@ -32,5 +31,5 @@ * The main interface for the remark shiki API, sets up the | ||
* */ | ||
declare const remarkShiki: ({ markdownAST }: any, shikiSettings: HighlighterOptions, settings: ShikiTwoslashSettings) => Promise<void>; | ||
declare const remarkShiki: ({ markdownAST }: any, settings?: UserConfigSettings) => Promise<void>; | ||
/** Sends the twoslash visitor over the existing MD AST and replaces the code samples inline, does not do highlighting */ | ||
export declare const runTwoSlashAcrossDocument: ({ markdownAST }: any, settings?: ShikiTwoslashSettings | undefined) => any; | ||
export declare const runTwoSlashAcrossDocument: ({ markdownAST }: any, settings?: UserConfigSettings) => any; | ||
export default remarkShiki; |
{ | ||
"name": "gatsby-remark-shiki-twoslash", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -31,6 +31,6 @@ "homepage": "https://github.com/microsoft/TypeScript-Website", | ||
"dependencies": { | ||
"@typescript/twoslash": "1.1.4", | ||
"@typescript/vfs": "1.3.2", | ||
"@typescript/twoslash": "1.1.6", | ||
"@typescript/vfs": "1.3.3", | ||
"shiki": "^0.9.1", | ||
"shiki-twoslash": "1.0.0", | ||
"shiki-twoslash": "1.2.4", | ||
"typescript": "*", | ||
@@ -37,0 +37,0 @@ "unist-util-visit": "^2.0.0" |
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
220824
1533
+ Added@typescript/twoslash@1.1.6(transitive)
+ Added@typescript/vfs@1.3.3(transitive)
+ Addedshiki-twoslash@1.2.4(transitive)
- Removed@typescript/twoslash@1.1.4(transitive)
- Removed@typescript/vfs@1.3.2(transitive)
- Removedshiki-twoslash@1.0.0(transitive)
Updated@typescript/twoslash@1.1.6
Updated@typescript/vfs@1.3.3
Updatedshiki-twoslash@1.2.4