shiki-twoslash
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -7,4 +7,8 @@ import { Highlighter, HighlighterOptions } from "shiki"; | ||
import { tsconfigJSONRenderer } from "./renderers/tsconfig"; | ||
/** The possible user config, a combination of all shiki and twoslash options */ | ||
export declare type UserConfigSettings = HighlighterOptions & TwoSlashOptions; | ||
export interface TwoslashShikiOptions { | ||
/** A way too turn on the try buttons seen on the TS website */ | ||
addTryButton?: true; | ||
} | ||
/** The possible user config, a combination of all shiki, twoslash and twoslash-shiki options */ | ||
export declare type UserConfigSettings = HighlighterOptions & TwoSlashOptions & TwoslashShikiOptions; | ||
/** | ||
@@ -11,0 +15,0 @@ * Creates a *cached singleton* Shiki highlighter, this is an async call because of the call to WASM to get |
declare type Lines = import("shiki").IThemedToken[][]; | ||
declare type TwoSlash = import("@typescript/twoslash").TwoSlashReturn; | ||
import { TwoslashShikiOptions } from ".."; | ||
import { HtmlRendererOptions } from "./plain"; | ||
export declare function twoslashRenderer(lines: Lines, options: HtmlRendererOptions, twoslash: TwoSlash, codefenceMeta: any): string; | ||
export declare function twoslashRenderer(lines: Lines, options: HtmlRendererOptions & TwoslashShikiOptions, twoslash: TwoSlash, codefenceMeta: any): string; | ||
export {}; |
@@ -261,3 +261,3 @@ 'use strict'; | ||
function createHighlightedString2(ranges, text, targetedWord) { | ||
function createHighlightedString(ranges, text, targetedWord) { | ||
if (targetedWord === void 0) { | ||
@@ -275,2 +275,5 @@ targetedWord = ""; | ||
if (r.classes === "lsp") { | ||
// console.log(ranges, text, targetedWord) | ||
// The LSP response lives inside a dom attribute, which _can_ have < inside it, so switch them ahead of time. | ||
var lsp = htmlAttrReplacer(r.lsp || ""); | ||
var underLineTargetedWord = r.lsp === targetedWord ? "style=⇯border-bottom: solid 2px lightgrey;⇯" : ""; | ||
@@ -282,3 +285,3 @@ actions.push({ | ||
actions.push({ | ||
text: "\u21CDdata-lsp lsp=\u21EF" + (r.lsp || "") + "\u21EF " + underLineTargetedWord + "\u21CF", | ||
text: "\u21CDdata-lsp lsp=\xBF" + lsp + "\xBF " + underLineTargetedWord + "\u21CF", | ||
index: r.begin | ||
@@ -307,4 +310,14 @@ }); | ||
if (hasErrors) html = "\u21CDdata-err\u21CF" + html + "\u21CD/data-err\u21CF"; | ||
return replaceTripleArrow(stripHTML(html)); | ||
} | ||
return htmlAttrUnReplacer(replaceTripleArrow(stripHTML(html))); | ||
} // HTML attributes have different rules, | ||
var htmlAttrReplacer = function htmlAttrReplacer(str) { | ||
return str.replace(/"/g, "⃟"); | ||
}; | ||
var htmlAttrUnReplacer = function htmlAttrUnReplacer(str) { | ||
return str.replace(/⃟/g, '"'); | ||
}; // Inline strings which are shown at HTML level | ||
var subTripleArrow = function subTripleArrow(str) { | ||
@@ -314,3 +327,3 @@ return str.replace(/</g, "⇍").replace(/>/g, "⇏").replace(/'/g, "⇯"); | ||
var replaceTripleArrow = function replaceTripleArrow(str) { | ||
return str.replace(/⇍/g, "<").replace(/⇏/g, ">").replace(/⇯/g, "'"); | ||
return str.replace(/⇍/g, "<").replace(/⇏/g, ">").replace(/⇯/g, "'").replace(/¿/g, "'"); | ||
}; | ||
@@ -458,3 +471,3 @@ var replaceTripleArrowEncoded = function replaceTripleArrowEncoded(str) { | ||
range.classes = "lsp"; | ||
range["lsp"] = stripHTML(token.text); | ||
range["lsp"] = token.text; | ||
} | ||
@@ -464,3 +477,3 @@ | ||
}); | ||
tokenContent += createHighlightedString2(ranges, token.content, (_targetedQueryWord = targetedQueryWord) == null ? void 0 : _targetedQueryWord.text); | ||
tokenContent += createHighlightedString(ranges, token.content, (_targetedQueryWord = targetedQueryWord) == null ? void 0 : _targetedQueryWord.text); | ||
} else { | ||
@@ -539,4 +552,10 @@ tokenContent += subTripleArrow(token.content); | ||
var playgroundLink = "<a class='playground-link' href='" + twoslash.playgroundURL + "'>Try</a>"; | ||
html += "</code>" + playgroundLink + "</div></pre>"; | ||
if (options.addTryButton) { | ||
var playgroundLink = "<a class='playground-link' href='" + twoslash.playgroundURL + "'>Try</a>"; | ||
html += "</code>" + playgroundLink; | ||
} else { | ||
html += "</code>"; | ||
} | ||
html += "</div></pre>"; | ||
return html; | ||
@@ -543,0 +562,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("shiki"),t=require("@typescript/twoslash");function n(){return(n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var r=/[a-z0-9-–—_+#]/i,i=/\s/,o=/[0-9-.]/,a=/[0-9-.e]/;function s(e,t){return void 0!==e&&t.test(e)}function c(e,t){var n=t.replace("twoslash",""),c=0,l={},p="",d=[e,n].filter(Boolean).join(" ");v(),h()||"{"===f()||(p=y());var u=c;return v(),h()||"{"!==f()||(l=S()),h()||u!==c?{languageName:p,meta:l}:g("Invalid character in language name: '"+f()+"'");function f(){return h()?g("Unexpected end of input"):d[c]}function h(){return c>=d.length}function g(e){throw new Error("Failed parsing code fence header '"+d+"' at position "+c+": "+e)}function m(e){if(h()||f()!==e)return g("Expected '"+e+"'");c++}function y(e){void 0===e&&(e="Expected identifier, but got nothing");for(var t="";!h()&&s(f(),r);)t+=f(),c++;return t||g(e)}function v(){for(;!h()&&s(f(),i);)c++}function b(){switch(f()){case"{":return S();case"'":case'"':return function(){var e,t="",n=f();for(c++;;){var r=(e=void 0,"\\"===(e=f())&&(c++,e+=f()),c++,e);if(r===n)break;t+=r.replace(/\\/,"")}return t}()}return s(f(),o)?function(){var e=f();for(c++;!h()&&s(f(),a);)e+=f(),c++;return parseFloat(e)}():function(){var e=y("Expected expression, but got nothing");switch(e){case"true":return!0;case"false":return!1;case"":return g("Expected expression, but got nothing");default:return g("Unrecognized input '"+e+"'")}}()}function S(){var e={};for(m("{"),v();!h()&&"}"!==f();){var t=y(),n=!0;v(),":"===f()&&(c++,v(),n=b(),v()),e[t]=n,","===f()&&c++,v()}return m("}"),e}}function l(e){var t={"<":"lt",'"':"quot","'":"apos","&":"amp","\r":"#10","\n":"#13"};return e.toString().replace(/[<"'\r\n&]/g,(function(e){return"&"+t[e]+";"}))}function p(e){return e.replace(/</g,"<").replace(/>/g,">")}var d=function(e,t,n){var r=e.bg||"#fff",i=e.fg||"black";return'<pre class="shiki '+(t&&t.class||"")+" "+(e.themeName||"")+" "+(n&&n.join(" ")||"")+'" style="background-color: '+r+"; color: "+i+'">'};function u(e,t,n){var r="";return r+=d(t,n,[]),t.langId&&(r+='<div class="language-id">'+t.langId+"</div>"),r+="<div class='code-container'><code>",(r=(r+=p(e)).replace(/\n*$/,""))+"</code></div></pre>"}function f(e,t,n,r){var i="",o=!!Object.keys(r).find((function(e){return!!e.includes("-")||NaN!==parseInt(e)})),a=function(e){var t=[];return Object.keys(e).find((function(e){if(NaN!==parseInt(e)&&t.push(parseInt(e)),e.includes("-"))for(var n=e.split("-"),r=n[0],i=parseInt(n[1])+1,o=parseInt(r);o<i;o++)t.push(o)})),function(e){return t.includes(e)}}(r);i+=d(t,r,["twoslash","lsp"]),t.langId&&(i+='<div class="language-id">'+t.langId+"</div>"),i+="<div class='code-container'><code>";var s,c=h(n.errors,(function(e){return e.line}))||new Map,u=h(n.staticQuickInfos,(function(e){return e.line}))||new Map,f=h(n.queries,(function(e){return e.line-1}))||new Map,g=0;return e.forEach((function(e,t){var n=c.get(t)||[],r=u.get(t)||[],s=f.get(t)||[];if(0===e.length&&0===t)g+=1;else if(0===e.length)g+=1,i+="\n";else{var d=o?a(t)?" highlight":" dim":"";i+="<div class='line"+d+"'>";var h=0;e.forEach((function(e){var t,o="",a=function(t){return function(n){return t<=n.character&&t+e.content.length>=n.character+n.length}},c=n.filter(a(h)),p=r.filter(a(h)),d=s.filter(a(h));t=t||p.find((function(e){return e.text===(s.length&&s[0].text)}));var u,f=[].concat(c,p,d).sort((function(e,t){return(e.start||0)-(t.start||0)}));o+=f.length?function(e,t,n){void 0===n&&(n="");var r=[],i=!1;e.forEach((function(e){if("lsp"===e.classes){var t=e.lsp===n?"style=⇯border-bottom: solid 2px lightgrey;⇯":"";r.push({text:"⇍/data-lsp⇏",index:e.end}),r.push({text:"⇍data-lsp lsp=⇯"+(e.lsp||"")+"⇯ "+t+"⇏",index:e.begin})}else"err"===e.classes?i=!0:"query"===e.classes&&(r.push({text:"⇍/data-highlight⇏",index:e.end}),r.push({text:"⇍data-highlight'⇏",index:e.begin}))}));var o=(" "+t).slice(1);return r.sort((function(e,t){return t.index-e.index})).forEach((function(e){var t,n,r;r=e.text,o=(t=o).slice(0,n=e.index)+r+t.slice(n+Math.abs(0))})),i&&(o="⇍data-err⇏"+o+"⇍/data-err⇏"),function(e){return e.replace(/⇍/g,"<").replace(/⇏/g,">").replace(/⇯/g,"'")}(l(o))}(f.map((function(e){var t={begin:e.start-g,end:e.start+e.length-g};return"renderedMessage"in e&&(t.classes="err"),"kind"in e&&(t.classes=e.kind),"targetString"in e&&(t.classes="lsp",t.lsp=l(e.text)),t})),e.content,null==(u=t)?void 0:u.text):e.content.replace(/</g,"⇍").replace(/>/g,"⇏").replace(/'/g,"⇯"),i+='<span style="color: '+e.color+'">'+o+"</span>",h+=e.content.length,g+=e.content.length})),i+="</div>",g+=1}if(n.length){var m=n.map((function(e){return p(e.renderedMessage)})).join("</br>"),y=n.map((function(e){return e.code})).join("<br/>");i+='<span class="error"><span>'+m+'</span><span class="code">'+y+"</span></span>",i+='<span class="error-behind">'+m+"</span>"}s.length&&(s.forEach((function(e){switch(e.kind){case"query":var n=p(e.text),r=(u.get(t)||[]).find((function(e){return e.text===(s.length&&s[0].text)}));i+="<span class='popover-prefix'>"+" ".repeat((r&&r.character+(null==r?void 0:r.length)/2)-1||0)+"</span><span class='popover'><div class='arrow'></div>"+n+"</span>";break;case"completions":if(e.completions){var o=e.completions.filter((function(t){return t.name.startsWith(e.completionsPrefix||"____")})).sort((function(e,t){return e.name.localeCompare(t.name)})).map((function(t){var n,r,i=t.name.substr((null==(n=e.completionsPrefix)?void 0:n.length)||0),o="<span><span class='result-found'>"+(e.completionsPrefix||"")+"</span>"+i+"<span>";return"<li class='"+((null==(r=t.kindModifiers)?void 0:r.split(",").includes("deprecated"))?"deprecated":"")+"'>"+o+"</li>"})).join("");i+="".padStart(e.offset)+"<span class='inline-completions'><ul class='dropdown'>"+o+"</ul></span>"}else i+="<span class='query'>//"+"".padStart(e.offset-2)+"^ - No completions found</span>"}})),i+="\n")})),s=i.replace(/\n*$/,""),i=s.replace(/⇍/g,"<").replace(/⇏/g,">").replace(/⇯/g,"'"),i+="</code><a class='playground-link' href='"+n.playgroundURL+"'>Try</a></div></pre>"}function h(e,t){var n=new Map;return e.forEach((function(e){var r=t(e),i=n.get(r);i?i.push(e):n.set(r,[e])})),n}function g(e,t,n){var r="";return r+=d(t,n,[]),t.langId&&(r+='<div class="language-id">'+t.langId+"</div>"),r+="<div class='code-container'><code>",e.forEach((function(e){0===e.length?r+="<div class='line'></div>":(r+="<div class='line'>",e.forEach((function(e){r+='<span style="color: '+e.color+'">'+p(e.content)+"</span>"})),r+="</div>")})),r=r.replace(/\n*$/,""),r+="</code></div></pre>"}var m={compilerOptions:"The set of compiler options for your project",allowJs:"Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.",allowSyntheticDefaultImports:"Allow 'import x from y' when a module doesn't have a default export.",allowUmdGlobalAccess:"Allow accessing UMD globals from modules.",allowUnreachableCode:"Disable error reporting for unreachable code.",allowUnusedLabels:"Disable error reporting for unused labels.",alwaysStrict:"Ensure 'use strict' is always emitted.",assumeChangesOnlyAffectDirectDependencies:"Have recompiles in projects that use `incremental` and `watch` mode assume that changes within a file will only affect files directly depending on it.",baseUrl:"Specify the base directory to resolve non-relative module names.",charset:"No longer supported. In early versions, manually set the text encoding for reading files.",checkJs:"Enable error reporting in type-checked JavaScript files.",clean:"Delete the outputs of all projects.",composite:"Enable constraints that allow a TypeScript project to be used with project references.",declaration:"Generate .d.ts files from TypeScript and JavaScript files in your project.",declarationDir:"Specify the output directory for generated declaration files.",declarationMap:"Create sourcemaps for d.ts files.",diagnostics:"Output compiler performance information after building.",disableFilenameBasedTypeAcquisition:"Disables inference for type acquisition by looking at filenames in a project.",disableReferencedProjectLoad:"Reduce the number of projects loaded automatically by TypeScript.",disableSizeLimit:"Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.",disableSolutionSearching:"Opt a project out of multi-project reference checking when editing.",disableSourceOfProjectReferenceRedirect:"Disable preferring source files instead of declaration files when referencing composite projects",downlevelIteration:"Emit more compliant, but verbose and less performant JavaScript for iteration.",emitBOM:"Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.",emitDeclarationOnly:"Only output d.ts files and not JavaScript files.",emitDecoratorMetadata:"Emit design-type metadata for decorated declarations in source files.",enable:"Disable the type acquisition for JavaScript projects",esModuleInterop:"Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility.",exclude:"Filters results from the `include` option.",excludeDirectories:"Remove a list of directories from the watch process.",excludeFiles:"Remove a list of files from the watch mode's processing.",experimentalDecorators:"Enable experimental support for TC39 stage 2 draft decorators.",explainFiles:"Print files read during the compilation including why it was included.",extendedDiagnostics:"Output more detailed compiler performance information after building.",extends:"Specify one or more path or node module references to base configuration files from which settings are inherited.",fallbackPolling:"Specify what approach the watcher should use if the system runs out of native file watchers.",files:"Include a list of files. This does not support glob patterns, as opposed to `include`.",force:"Build all projects, including those that appear to be up to date",forceConsistentCasingInFileNames:"Ensure that casing is correct in imports.",generateCpuProfile:"Emit a v8 CPU profile of the compiler run for debugging.",importHelpers:"Allow importing helper functions from tslib once per project, instead of including them per-file.",importsNotUsedAsValues:"Specify emit/checking behavior for imports that are only used for types.",include:"Specify a list of glob patterns that match files to be included in compilation.",incremental:"Save .tsbuildinfo files to allow for incremental compilation of projects.",inlineSourceMap:"Include sourcemap files inside the emitted JavaScript.",inlineSources:"Include source code in the sourcemaps inside the emitted JavaScript.",isolatedModules:"Ensure that each file can be safely transpiled without relying on other imports.",jsx:"Specify what JSX code is generated.",jsxFactory:"Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'",jsxFragmentFactory:"Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'.",jsxImportSource:"Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.`",keyofStringsOnly:"Make keyof only return strings instead of string, numbers or symbols. Legacy option.",lib:"Specify a set of bundled library declaration files that describe the target runtime environment.",listEmittedFiles:"Print the names of emitted files after a compilation.",listFiles:"Print all of the files read during the compilation.",locale:"Set the language of the messaging from TypeScript. This does not affect emit.",mapRoot:"Specify the location where debugger should locate map files instead of generated locations.",maxNodeModuleJsDepth:"Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`.",module:"Specify what module code is generated.",moduleResolution:"Specify how TypeScript looks up a file from a given module specifier.",newLine:"Set the newline character for emitting files.",noEmit:"Disable emitting file from a compilation.",noEmitHelpers:"Disable generating custom helper functions like `__extends` in compiled output.",noEmitOnError:"Disable emitting files if any type checking errors are reported.",noErrorTruncation:"Disable truncating types in error messages.",noFallthroughCasesInSwitch:"Enable error reporting for fallthrough cases in switch statements.",noImplicitAny:"Enable error reporting for expressions and declarations with an implied `any` type..",noImplicitOverride:"Ensure overriding members in derived classes are marked with an override modifier.",noImplicitReturns:"Enable error reporting for codepaths that do not explicitly return in a function.",noImplicitThis:"Enable error reporting when `this` is given the type `any`.",noImplicitUseStrict:"Disable adding 'use strict' directives in emitted JavaScript files.",noLib:"Disable including any library files, including the default lib.d.ts.",noPropertyAccessFromIndexSignature:"Enforces using indexed accessors for keys declared using an indexed type",noResolve:"Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project.",noStrictGenericChecks:"Disable strict checking of generic signatures in function types.",noUncheckedIndexedAccess:"Add `undefined` to a type when accessed using an index.",noUnusedLocals:"Enable error reporting when a local variables aren't read.",noUnusedParameters:"Raise an error when a function parameter isn't read",out:"Deprecated setting. Use `outFile` instead.",outDir:"Specify an output folder for all emitted files.",outFile:"Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output.",paths:"Specify a set of entries that re-map imports to additional lookup locations.",plugins:"Specify a list of language service plugins to include.",preserveConstEnums:"Disable erasing `const enum` declarations in generated code.",preserveSymlinks:"Disable resolving symlinks to their realpath. This correlates to the same flag in node.",preserveWatchOutput:"Disable wiping the console in watch mode",pretty:"Enable color and formatting in output to make compiler errors easier to read",reactNamespace:"Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit.",references:"Specify an array of objects that specify paths for projects. Used in project references.",removeComments:"Disable emitting comments.",resolveJsonModule:"Enable importing .json files",rootDir:"Specify the root folder within your source files.",rootDirs:"Allow multiple folders to be treated as one when resolving modules.",skipDefaultLibCheck:"Skip type checking .d.ts files that are included with TypeScript.",skipLibCheck:"Skip type checking all .d.ts files.",sourceMap:"Create source map files for emitted JavaScript files.",sourceRoot:"Specify the root path for debuggers to find the reference source code.",strict:"Enable all strict type checking options.",strictBindCallApply:"Check that the arguments for `bind`, `call`, and `apply` methods match the original function.",strictFunctionTypes:"When assigning functions, check to ensure parameters and the return values are subtype-compatible.",strictNullChecks:"When type checking, take into account `null` and `undefined`.",strictPropertyInitialization:"Check for class properties that are declared but not set in the constructor.",stripInternal:"Disable emitting declarations that have `@internal` in their JSDoc comments.",suppressExcessPropertyErrors:"Disable reporting of excess property errors during the creation of object literals.",suppressImplicitAnyIndexErrors:"Suppress `noImplicitAny` errors when indexing objects that lack index signatures.",synchronousWatchDirectory:"Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively.",target:"Set the JavaScript language version for emitted JavaScript and include compatible library declarations.",traceResolution:"Log paths used during the `moduleResolution` process.",tsBuildInfoFile:"Specify the folder for .tsbuildinfo incremental compilation files.",typeAcquisition:"Specify options for automatic acquisition of declaration files.",typeRoots:"Specify multiple folders that act like `./node_modules/@types`.",types:"Specify type package names to be included without being referenced in a source file.",useDefineForClassFields:"Emit ECMAScript-standard-compliant class fields.",verbose:"Enable verbose logging",watchDirectory:"Specify how directories are watched on systems that lack recursive file-watching functionality.",watchFile:"Specify how the TypeScript watch mode works."};function y(e,t,n){var r="";return r+=d(t,n,["tsconfig","lsp"]),t.langId&&(r+='<div class="language-id">'+t.langId+"</div>"),r+="<div class='code-container'><code>",e.forEach((function(e){0===e.length?r+="<div class='line'></div>":(r+="<div class='line'>",e.forEach((function(e){if(function(e){return!!e.explanation&&e.explanation.find((function(e){return e.scopes.find((function(e){return e.scopeName.includes("support.type.property-name")}))}))}(e)&&function(e){if('"'!==e.content)return e.content.slice(1,e.content.length-1)in m}(e)){var t=e.content.slice(1,e.content.length-1);r+='<span style="color: '+e.color+'">"<a aria-hidden=true tabindex="-1" href=\'https://www.typescriptlang.org/tsconfig#'+t+"'><data-lsp lsp=\""+m[t]+'">'+p(t)+'</data-lsp></a>"</span>'}else r+='<span style="color: '+e.color+'">'+p(e.content)+"</span>"})),r+="</div>")})),r=r.replace(/\n*$/,""),r+="</code></div></pre>"}var v=null,b={plainTextRenderer:u,defaultShikiRenderer:g,twoslashRenderer:f,tsconfigJSONRenderer:y};exports.createShikiHighlighter=function(t){return v?Promise.resolve(v):e.getHighlighter(t).then((function(e){return v=e}))},exports.parseCodeFenceInfo=c,exports.renderCodeToHTML=function(e,t,r,i,o,a){if(!o&&!v)throw new Error("The highlighter object hasn't been initialised via `setupHighLighter` yet in shiki-twoslash");var s,l=o||v,p=c(t,(r&&"string"==typeof r?r:r.join(" "))||""),d=n({fg:l.getForegroundColor(),bg:l.getBackgroundColor()},i);try{s=l.codeToThemedTokens(e,t)}catch(t){return u(e,d,p.meta)}return r.includes("twoslash")&&a?f(s,d,a,p.meta):t&&t.startsWith("json")&&r.includes("tsconfig")?y(s,d,p.meta):g(s,n({},d,{langId:t}),p.meta)},exports.renderers=b,exports.runTwoSlash=function(e,n,r){void 0===r&&(r={});var i={json5:"json",yml:"yaml"};return i[n]&&(n=i[n]),t.twoslasher(e,n,r)}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("shiki"),t=require("@typescript/twoslash");function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}var n=/[a-z0-9-–—_+#]/i,i=/\s/,o=/[0-9-.]/,a=/[0-9-.e]/;function s(e,t){return void 0!==e&&t.test(e)}function c(e,t){var r=t.replace("twoslash",""),c=0,l={},p="",d=[e,r].filter(Boolean).join(" ");v(),h()||"{"===f()||(p=y());var u=c;return v(),h()||"{"!==f()||(l=S()),h()||u!==c?{languageName:p,meta:l}:g("Invalid character in language name: '"+f()+"'");function f(){return h()?g("Unexpected end of input"):d[c]}function h(){return c>=d.length}function g(e){throw new Error("Failed parsing code fence header '"+d+"' at position "+c+": "+e)}function m(e){if(h()||f()!==e)return g("Expected '"+e+"'");c++}function y(e){void 0===e&&(e="Expected identifier, but got nothing");for(var t="";!h()&&s(f(),n);)t+=f(),c++;return t||g(e)}function v(){for(;!h()&&s(f(),i);)c++}function b(){switch(f()){case"{":return S();case"'":case'"':return function(){var e,t="",r=f();for(c++;;){var n=(e=void 0,"\\"===(e=f())&&(c++,e+=f()),c++,e);if(n===r)break;t+=n.replace(/\\/,"")}return t}()}return s(f(),o)?function(){var e=f();for(c++;!h()&&s(f(),a);)e+=f(),c++;return parseFloat(e)}():function(){var e=y("Expected expression, but got nothing");switch(e){case"true":return!0;case"false":return!1;case"":return g("Expected expression, but got nothing");default:return g("Unrecognized input '"+e+"'")}}()}function S(){var e={};for(m("{"),v();!h()&&"}"!==f();){var t=y(),r=!0;v(),":"===f()&&(c++,v(),r=b(),v()),e[t]=r,","===f()&&c++,v()}return m("}"),e}}function l(e){return e.replace(/</g,"<").replace(/>/g,">")}var p=function(e,t,r){var n=e.bg||"#fff",i=e.fg||"black";return'<pre class="shiki '+(t&&t.class||"")+" "+(e.themeName||"")+" "+(r&&r.join(" ")||"")+'" style="background-color: '+n+"; color: "+i+'">'};function d(e,t,r){var n="";return n+=p(t,r,[]),t.langId&&(n+='<div class="language-id">'+t.langId+"</div>"),n+="<div class='code-container'><code>",(n=(n+=l(e)).replace(/\n*$/,""))+"</code></div></pre>"}function u(e,t,r,n){var i="",o=!!Object.keys(n).find((function(e){return!!e.includes("-")||NaN!==parseInt(e)})),a=function(e){var t=[];return Object.keys(e).find((function(e){if(NaN!==parseInt(e)&&t.push(parseInt(e)),e.includes("-"))for(var r=e.split("-"),n=r[0],i=parseInt(r[1])+1,o=parseInt(n);o<i;o++)t.push(o)})),function(e){return t.includes(e)}}(n);i+=p(t,n,["twoslash","lsp"]),t.langId&&(i+='<div class="language-id">'+t.langId+"</div>"),i+="<div class='code-container'><code>";var s,c=f(r.errors,(function(e){return e.line}))||new Map,d=f(r.staticQuickInfos,(function(e){return e.line}))||new Map,u=f(r.queries,(function(e){return e.line-1}))||new Map,h=0;return e.forEach((function(e,t){var r=c.get(t)||[],n=d.get(t)||[],s=u.get(t)||[];if(0===e.length&&0===t)h+=1;else if(0===e.length)h+=1,i+="\n";else{var p=o?a(t)?" highlight":" dim":"";i+="<div class='line"+p+"'>";var f=0;e.forEach((function(e){var t,o="",a=function(t){return function(r){return t<=r.character&&t+e.content.length>=r.character+r.length}},c=r.filter(a(f)),l=n.filter(a(f)),p=s.filter(a(f));t=t||l.find((function(e){return e.text===(s.length&&s[0].text)}));var d,u=[].concat(c,l,p).sort((function(e,t){return(e.start||0)-(t.start||0)}));o+=u.length?function(e,t,r){void 0===r&&(r="");var n=[],i=!1;e.forEach((function(e){if("lsp"===e.classes){var t=function(e){return e.replace(/"/g,"⃟")}(e.lsp||""),o=e.lsp===r?"style=⇯border-bottom: solid 2px lightgrey;⇯":"";n.push({text:"⇍/data-lsp⇏",index:e.end}),n.push({text:"⇍data-lsp lsp=¿"+t+"¿ "+o+"⇏",index:e.begin})}else"err"===e.classes?i=!0:"query"===e.classes&&(n.push({text:"⇍/data-highlight⇏",index:e.end}),n.push({text:"⇍data-highlight'⇏",index:e.begin}))}));var o=(" "+t).slice(1);return n.sort((function(e,t){return t.index-e.index})).forEach((function(e){var t,r,n;n=e.text,o=(t=o).slice(0,r=e.index)+n+t.slice(r+Math.abs(0))})),i&&(o="⇍data-err⇏"+o+"⇍/data-err⇏"),function(e){return e.replace(/⃟/g,'"')}(function(e){return e.replace(/⇍/g,"<").replace(/⇏/g,">").replace(/⇯/g,"'").replace(/¿/g,"'")}(function(e){var t={"<":"lt",'"':"quot","'":"apos","&":"amp","\r":"#10","\n":"#13"};return e.toString().replace(/[<"'\r\n&]/g,(function(e){return"&"+t[e]+";"}))}(o)))}(u.map((function(e){var t={begin:e.start-h,end:e.start+e.length-h};return"renderedMessage"in e&&(t.classes="err"),"kind"in e&&(t.classes=e.kind),"targetString"in e&&(t.classes="lsp",t.lsp=e.text),t})),e.content,null==(d=t)?void 0:d.text):e.content.replace(/</g,"⇍").replace(/>/g,"⇏").replace(/'/g,"⇯"),i+='<span style="color: '+e.color+'">'+o+"</span>",f+=e.content.length,h+=e.content.length})),i+="</div>",h+=1}if(r.length){var g=r.map((function(e){return l(e.renderedMessage)})).join("</br>"),m=r.map((function(e){return e.code})).join("<br/>");i+='<span class="error"><span>'+g+'</span><span class="code">'+m+"</span></span>",i+='<span class="error-behind">'+g+"</span>"}s.length&&(s.forEach((function(e){switch(e.kind){case"query":var r=l(e.text),n=(d.get(t)||[]).find((function(e){return e.text===(s.length&&s[0].text)}));i+="<span class='popover-prefix'>"+" ".repeat((n&&n.character+(null==n?void 0:n.length)/2)-1||0)+"</span><span class='popover'><div class='arrow'></div>"+r+"</span>";break;case"completions":if(e.completions){var o=e.completions.filter((function(t){return t.name.startsWith(e.completionsPrefix||"____")})).sort((function(e,t){return e.name.localeCompare(t.name)})).map((function(t){var r,n,i=t.name.substr((null==(r=e.completionsPrefix)?void 0:r.length)||0),o="<span><span class='result-found'>"+(e.completionsPrefix||"")+"</span>"+i+"<span>";return"<li class='"+((null==(n=t.kindModifiers)?void 0:n.split(",").includes("deprecated"))?"deprecated":"")+"'>"+o+"</li>"})).join("");i+="".padStart(e.offset)+"<span class='inline-completions'><ul class='dropdown'>"+o+"</ul></span>"}else i+="<span class='query'>//"+"".padStart(e.offset-2)+"^ - No completions found</span>"}})),i+="\n")})),s=i.replace(/\n*$/,""),i=s.replace(/⇍/g,"<").replace(/⇏/g,">").replace(/⇯/g,"'"),i+=t.addTryButton?"</code><a class='playground-link' href='"+r.playgroundURL+"'>Try</a>":"</code>",i+="</div></pre>"}function f(e,t){var r=new Map;return e.forEach((function(e){var n=t(e),i=r.get(n);i?i.push(e):r.set(n,[e])})),r}function h(e,t,r){var n="";return n+=p(t,r,[]),t.langId&&(n+='<div class="language-id">'+t.langId+"</div>"),n+="<div class='code-container'><code>",e.forEach((function(e){0===e.length?n+="<div class='line'></div>":(n+="<div class='line'>",e.forEach((function(e){n+='<span style="color: '+e.color+'">'+l(e.content)+"</span>"})),n+="</div>")})),n=n.replace(/\n*$/,""),n+="</code></div></pre>"}var g={compilerOptions:"The set of compiler options for your project",allowJs:"Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files.",allowSyntheticDefaultImports:"Allow 'import x from y' when a module doesn't have a default export.",allowUmdGlobalAccess:"Allow accessing UMD globals from modules.",allowUnreachableCode:"Disable error reporting for unreachable code.",allowUnusedLabels:"Disable error reporting for unused labels.",alwaysStrict:"Ensure 'use strict' is always emitted.",assumeChangesOnlyAffectDirectDependencies:"Have recompiles in projects that use `incremental` and `watch` mode assume that changes within a file will only affect files directly depending on it.",baseUrl:"Specify the base directory to resolve non-relative module names.",charset:"No longer supported. In early versions, manually set the text encoding for reading files.",checkJs:"Enable error reporting in type-checked JavaScript files.",clean:"Delete the outputs of all projects.",composite:"Enable constraints that allow a TypeScript project to be used with project references.",declaration:"Generate .d.ts files from TypeScript and JavaScript files in your project.",declarationDir:"Specify the output directory for generated declaration files.",declarationMap:"Create sourcemaps for d.ts files.",diagnostics:"Output compiler performance information after building.",disableFilenameBasedTypeAcquisition:"Disables inference for type acquisition by looking at filenames in a project.",disableReferencedProjectLoad:"Reduce the number of projects loaded automatically by TypeScript.",disableSizeLimit:"Remove the 20mb cap on total source code size for JavaScript files in the TypeScript language server.",disableSolutionSearching:"Opt a project out of multi-project reference checking when editing.",disableSourceOfProjectReferenceRedirect:"Disable preferring source files instead of declaration files when referencing composite projects",downlevelIteration:"Emit more compliant, but verbose and less performant JavaScript for iteration.",emitBOM:"Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files.",emitDeclarationOnly:"Only output d.ts files and not JavaScript files.",emitDecoratorMetadata:"Emit design-type metadata for decorated declarations in source files.",enable:"Disable the type acquisition for JavaScript projects",esModuleInterop:"Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility.",exclude:"Filters results from the `include` option.",excludeDirectories:"Remove a list of directories from the watch process.",excludeFiles:"Remove a list of files from the watch mode's processing.",experimentalDecorators:"Enable experimental support for TC39 stage 2 draft decorators.",explainFiles:"Print files read during the compilation including why it was included.",extendedDiagnostics:"Output more detailed compiler performance information after building.",extends:"Specify one or more path or node module references to base configuration files from which settings are inherited.",fallbackPolling:"Specify what approach the watcher should use if the system runs out of native file watchers.",files:"Include a list of files. This does not support glob patterns, as opposed to `include`.",force:"Build all projects, including those that appear to be up to date",forceConsistentCasingInFileNames:"Ensure that casing is correct in imports.",generateCpuProfile:"Emit a v8 CPU profile of the compiler run for debugging.",importHelpers:"Allow importing helper functions from tslib once per project, instead of including them per-file.",importsNotUsedAsValues:"Specify emit/checking behavior for imports that are only used for types.",include:"Specify a list of glob patterns that match files to be included in compilation.",incremental:"Save .tsbuildinfo files to allow for incremental compilation of projects.",inlineSourceMap:"Include sourcemap files inside the emitted JavaScript.",inlineSources:"Include source code in the sourcemaps inside the emitted JavaScript.",isolatedModules:"Ensure that each file can be safely transpiled without relying on other imports.",jsx:"Specify what JSX code is generated.",jsxFactory:"Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'",jsxFragmentFactory:"Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'.",jsxImportSource:"Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.`",keyofStringsOnly:"Make keyof only return strings instead of string, numbers or symbols. Legacy option.",lib:"Specify a set of bundled library declaration files that describe the target runtime environment.",listEmittedFiles:"Print the names of emitted files after a compilation.",listFiles:"Print all of the files read during the compilation.",locale:"Set the language of the messaging from TypeScript. This does not affect emit.",mapRoot:"Specify the location where debugger should locate map files instead of generated locations.",maxNodeModuleJsDepth:"Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`.",module:"Specify what module code is generated.",moduleResolution:"Specify how TypeScript looks up a file from a given module specifier.",newLine:"Set the newline character for emitting files.",noEmit:"Disable emitting file from a compilation.",noEmitHelpers:"Disable generating custom helper functions like `__extends` in compiled output.",noEmitOnError:"Disable emitting files if any type checking errors are reported.",noErrorTruncation:"Disable truncating types in error messages.",noFallthroughCasesInSwitch:"Enable error reporting for fallthrough cases in switch statements.",noImplicitAny:"Enable error reporting for expressions and declarations with an implied `any` type..",noImplicitOverride:"Ensure overriding members in derived classes are marked with an override modifier.",noImplicitReturns:"Enable error reporting for codepaths that do not explicitly return in a function.",noImplicitThis:"Enable error reporting when `this` is given the type `any`.",noImplicitUseStrict:"Disable adding 'use strict' directives in emitted JavaScript files.",noLib:"Disable including any library files, including the default lib.d.ts.",noPropertyAccessFromIndexSignature:"Enforces using indexed accessors for keys declared using an indexed type",noResolve:"Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project.",noStrictGenericChecks:"Disable strict checking of generic signatures in function types.",noUncheckedIndexedAccess:"Add `undefined` to a type when accessed using an index.",noUnusedLocals:"Enable error reporting when a local variables aren't read.",noUnusedParameters:"Raise an error when a function parameter isn't read",out:"Deprecated setting. Use `outFile` instead.",outDir:"Specify an output folder for all emitted files.",outFile:"Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output.",paths:"Specify a set of entries that re-map imports to additional lookup locations.",plugins:"Specify a list of language service plugins to include.",preserveConstEnums:"Disable erasing `const enum` declarations in generated code.",preserveSymlinks:"Disable resolving symlinks to their realpath. This correlates to the same flag in node.",preserveWatchOutput:"Disable wiping the console in watch mode",pretty:"Enable color and formatting in output to make compiler errors easier to read",reactNamespace:"Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit.",references:"Specify an array of objects that specify paths for projects. Used in project references.",removeComments:"Disable emitting comments.",resolveJsonModule:"Enable importing .json files",rootDir:"Specify the root folder within your source files.",rootDirs:"Allow multiple folders to be treated as one when resolving modules.",skipDefaultLibCheck:"Skip type checking .d.ts files that are included with TypeScript.",skipLibCheck:"Skip type checking all .d.ts files.",sourceMap:"Create source map files for emitted JavaScript files.",sourceRoot:"Specify the root path for debuggers to find the reference source code.",strict:"Enable all strict type checking options.",strictBindCallApply:"Check that the arguments for `bind`, `call`, and `apply` methods match the original function.",strictFunctionTypes:"When assigning functions, check to ensure parameters and the return values are subtype-compatible.",strictNullChecks:"When type checking, take into account `null` and `undefined`.",strictPropertyInitialization:"Check for class properties that are declared but not set in the constructor.",stripInternal:"Disable emitting declarations that have `@internal` in their JSDoc comments.",suppressExcessPropertyErrors:"Disable reporting of excess property errors during the creation of object literals.",suppressImplicitAnyIndexErrors:"Suppress `noImplicitAny` errors when indexing objects that lack index signatures.",synchronousWatchDirectory:"Synchronously call callbacks and update the state of directory watchers on platforms that don`t support recursive watching natively.",target:"Set the JavaScript language version for emitted JavaScript and include compatible library declarations.",traceResolution:"Log paths used during the `moduleResolution` process.",tsBuildInfoFile:"Specify the folder for .tsbuildinfo incremental compilation files.",typeAcquisition:"Specify options for automatic acquisition of declaration files.",typeRoots:"Specify multiple folders that act like `./node_modules/@types`.",types:"Specify type package names to be included without being referenced in a source file.",useDefineForClassFields:"Emit ECMAScript-standard-compliant class fields.",verbose:"Enable verbose logging",watchDirectory:"Specify how directories are watched on systems that lack recursive file-watching functionality.",watchFile:"Specify how the TypeScript watch mode works."};function m(e,t,r){var n="";return n+=p(t,r,["tsconfig","lsp"]),t.langId&&(n+='<div class="language-id">'+t.langId+"</div>"),n+="<div class='code-container'><code>",e.forEach((function(e){0===e.length?n+="<div class='line'></div>":(n+="<div class='line'>",e.forEach((function(e){if(function(e){return!!e.explanation&&e.explanation.find((function(e){return e.scopes.find((function(e){return e.scopeName.includes("support.type.property-name")}))}))}(e)&&function(e){if('"'!==e.content)return e.content.slice(1,e.content.length-1)in g}(e)){var t=e.content.slice(1,e.content.length-1);n+='<span style="color: '+e.color+'">"<a aria-hidden=true tabindex="-1" href=\'https://www.typescriptlang.org/tsconfig#'+t+"'><data-lsp lsp=\""+g[t]+'">'+l(t)+'</data-lsp></a>"</span>'}else n+='<span style="color: '+e.color+'">'+l(e.content)+"</span>"})),n+="</div>")})),n=n.replace(/\n*$/,""),n+="</code></div></pre>"}var y=null,v={plainTextRenderer:d,defaultShikiRenderer:h,twoslashRenderer:u,tsconfigJSONRenderer:m};exports.createShikiHighlighter=function(t){return y?Promise.resolve(y):e.getHighlighter(t).then((function(e){return y=e}))},exports.parseCodeFenceInfo=c,exports.renderCodeToHTML=function(e,t,n,i,o,a){if(!o&&!y)throw new Error("The highlighter object hasn't been initialised via `setupHighLighter` yet in shiki-twoslash");var s,l=o||y,p=c(t,(n&&"string"==typeof n?n:n.join(" "))||""),f=r({fg:l.getForegroundColor(),bg:l.getBackgroundColor()},i);try{s=l.codeToThemedTokens(e,t)}catch(t){return d(e,f,p.meta)}return n.includes("twoslash")&&a?u(s,f,a,p.meta):t&&t.startsWith("json")&&n.includes("tsconfig")?m(s,f,p.meta):h(s,r({},f,{langId:t}),p.meta)},exports.renderers=v,exports.runTwoSlash=function(e,r,n){void 0===n&&(n={});var i={json5:"json",yml:"yaml"};return i[r]&&(r=i[r]),t.twoslasher(e,r,n)}; | ||
//# sourceMappingURL=shiki-twoslash.cjs.production.min.js.map |
@@ -257,3 +257,3 @@ import { getHighlighter } from 'shiki'; | ||
function createHighlightedString2(ranges, text, targetedWord) { | ||
function createHighlightedString(ranges, text, targetedWord) { | ||
if (targetedWord === void 0) { | ||
@@ -271,2 +271,5 @@ targetedWord = ""; | ||
if (r.classes === "lsp") { | ||
// console.log(ranges, text, targetedWord) | ||
// The LSP response lives inside a dom attribute, which _can_ have < inside it, so switch them ahead of time. | ||
var lsp = htmlAttrReplacer(r.lsp || ""); | ||
var underLineTargetedWord = r.lsp === targetedWord ? "style=⇯border-bottom: solid 2px lightgrey;⇯" : ""; | ||
@@ -278,3 +281,3 @@ actions.push({ | ||
actions.push({ | ||
text: "\u21CDdata-lsp lsp=\u21EF" + (r.lsp || "") + "\u21EF " + underLineTargetedWord + "\u21CF", | ||
text: "\u21CDdata-lsp lsp=\xBF" + lsp + "\xBF " + underLineTargetedWord + "\u21CF", | ||
index: r.begin | ||
@@ -303,4 +306,14 @@ }); | ||
if (hasErrors) html = "\u21CDdata-err\u21CF" + html + "\u21CD/data-err\u21CF"; | ||
return replaceTripleArrow(stripHTML(html)); | ||
} | ||
return htmlAttrUnReplacer(replaceTripleArrow(stripHTML(html))); | ||
} // HTML attributes have different rules, | ||
var htmlAttrReplacer = function htmlAttrReplacer(str) { | ||
return str.replace(/"/g, "⃟"); | ||
}; | ||
var htmlAttrUnReplacer = function htmlAttrUnReplacer(str) { | ||
return str.replace(/⃟/g, '"'); | ||
}; // Inline strings which are shown at HTML level | ||
var subTripleArrow = function subTripleArrow(str) { | ||
@@ -310,3 +323,3 @@ return str.replace(/</g, "⇍").replace(/>/g, "⇏").replace(/'/g, "⇯"); | ||
var replaceTripleArrow = function replaceTripleArrow(str) { | ||
return str.replace(/⇍/g, "<").replace(/⇏/g, ">").replace(/⇯/g, "'"); | ||
return str.replace(/⇍/g, "<").replace(/⇏/g, ">").replace(/⇯/g, "'").replace(/¿/g, "'"); | ||
}; | ||
@@ -454,3 +467,3 @@ var replaceTripleArrowEncoded = function replaceTripleArrowEncoded(str) { | ||
range.classes = "lsp"; | ||
range["lsp"] = stripHTML(token.text); | ||
range["lsp"] = token.text; | ||
} | ||
@@ -460,3 +473,3 @@ | ||
}); | ||
tokenContent += createHighlightedString2(ranges, token.content, (_targetedQueryWord = targetedQueryWord) == null ? void 0 : _targetedQueryWord.text); | ||
tokenContent += createHighlightedString(ranges, token.content, (_targetedQueryWord = targetedQueryWord) == null ? void 0 : _targetedQueryWord.text); | ||
} else { | ||
@@ -535,4 +548,10 @@ tokenContent += subTripleArrow(token.content); | ||
var playgroundLink = "<a class='playground-link' href='" + twoslash.playgroundURL + "'>Try</a>"; | ||
html += "</code>" + playgroundLink + "</div></pre>"; | ||
if (options.addTryButton) { | ||
var playgroundLink = "<a class='playground-link' href='" + twoslash.playgroundURL + "'>Try</a>"; | ||
html += "</code>" + playgroundLink; | ||
} else { | ||
html += "</code>"; | ||
} | ||
html += "</div></pre>"; | ||
return html; | ||
@@ -539,0 +558,0 @@ } |
@@ -14,3 +14,3 @@ declare type Range = { | ||
*/ | ||
export declare function createHighlightedString2(ranges: Range[], text: string, targetedWord?: string): string; | ||
export declare function createHighlightedString(ranges: Range[], text: string, targetedWord?: string): string; | ||
export declare const subTripleArrow: (str: string) => string; | ||
@@ -17,0 +17,0 @@ export declare const replaceTripleArrow: (str: string) => string; |
{ | ||
"name": "shiki-twoslash", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "homepage": "https://github.com/shikijs/twoslash", | ||
"update": "node scripts/generateTSConfigOneliners.js", | ||
"build": "tsdx build && npx tsc src/dom.ts --outDir dist", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
@@ -34,15 +34,11 @@ "lint": "tsdx lint" | ||
"shiki": "^0.9.3", | ||
"typescript": "*" | ||
"typescript": ">3" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^25.1.3", | ||
"gatsby-remark-shiki-twoslash": "2.0.0", | ||
"rehype-stringify": "^6.0.1", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^1.10.0", | ||
"typescript": "*", | ||
"unified": "^8.4.2", | ||
"unist-util-visit": "^2.0.0", | ||
"gray-matter": "^4.0.3" | ||
"gray-matter": "^4.0.3", | ||
"prettier": "^2.3.0" | ||
} | ||
} |
@@ -55,5 +55,2 @@ ### shiki-twoslash | ||
themes?: IThemeRegistration[] | ||
/** | ||
* Paths for loading themes and langs. Relative to the package's root. | ||
*/ | ||
paths?: IHighlighterPaths | ||
@@ -87,10 +84,18 @@ } | ||
Most people will want to set a `theme`, and _maybe_ `vfsRoot` if they want to do twoslash with custom libraries in a monorepo: | ||
And one extra for good luck: | ||
```ts | ||
export interface TwoslashShikiOptions { | ||
/** A way to turn on the try buttons seen on the TS website */ | ||
addTryButton?: true | ||
} | ||
``` | ||
That said, most people will just want to set a `theme`: | ||
```ts | ||
{ | ||
resolve: "gatsby-remark-shiki-twoslash", | ||
options: { | ||
theme: "github-light", | ||
vfsRoot: path.join(__dirname, "..", "..") | ||
theme: "github-light" | ||
}, | ||
@@ -100,2 +105,4 @@ } | ||
You can find all [built-in themes here](https://github.com/shikijs/shiki/tree/master/packages/shiki/themes) and all [built-in languages here](https://github.com/shikijs/shiki/tree/master/packages/shiki/languages). | ||
### Common Use Case | ||
@@ -120,3 +127,3 @@ | ||
The user-exposed parts of the API is a single file, you might find it easier to just read that: [`src/index.ts`](https://github.com/microsoft/TypeScript-website/blob/v2/packages/shiki-twoslash/src/index.ts). | ||
The user-exposed parts of the API is a well documented single file, you might find it easier to just read that: [`src/index.ts`](https://github.com/shikijs/twoslash/blob/main/packages/shiki-twoslash/src/index.ts). | ||
@@ -204,6 +211,1 @@ ##### `createShikiHighlighter` | ||
``` | ||
### Used in: | ||
- [gatsby-remark-shiki-twoslash](https://www.npmjs.com/package/gatsby-remark-shiki-twoslash) | ||
- [remark-shiki-twoslash](https://www.npmjs.com/package/remark-shiki-twoslash) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
287362
5
0
207
19
1807
Updatedtypescript@>3