type Lines = import ( "shiki" ) . IThemedToken [ ] [ ] ; import type { IThemedToken } from "shiki" ; import { escapeHtml , Meta } from "../utils" ; import { tsconfig } from "../tsconfig-oneliners.generated" ; import { HtmlRendererOptions , preOpenerFromRenderingOptsWithExtras } from "./plain" ; /** Uses tmLanguage scopes to determine what the content of the token is */ const tokenIsJSONKey = ( token ) => { if ( ! token . explanation ) return false ; return token . explanation . find ( e => e . scopes . find ( s => s . scopeName . includes ( "support.type.property-name" ) ) ) ; } ; /** Can you look up the token in the tsconfig reference? */ const isKeyInTSConfig = ( token ) => { if ( token . content === '"' ) return ; const name = token . content . slice ( 1 , token . content . length - 1 ) ; return name in tsconfig ; } ; param lines param options export function tsconfigJSONRenderer ( lines , options , meta ) { let html = "" ; html += preOpenerFromRenderingOptsWithExtras ( options , meta , [ "tsconfig" , "lsp" ] ) ; if ( meta . title ) { html += `<div class="code-title">${ meta . title }</div>` ; } if ( options . langId ) { html += `<div class="language-id">${ options . langId }</div>` ; } html += `<div class='code-container'><code>` ; lines . forEach ( l => { if ( l . length === 0 ) { html += `<div class='line'></div>` ; } else { html += `<div class='line'>` ; l . forEach ( token => { if ( tokenIsJSONKey ( token ) && isKeyInTSConfig ( token ) ) { const key = token . content . slice ( 1 , token . content . length - 1 ) ; const oneliner = ( tsconfig as Record < string , string > ) [ key ] ; html += `<span style="color: ${ token . color }">"<a aria-hidden=true tabindex="-1" href='https://www.typescriptlang.org/tsconfig#${ key }'><data-lsp lsp="${ oneliner }">${ escapeHtml ( key ) }</data-lsp></a>"</span>` ; } else { html += `<span style="color: ${ token . color }">${ escapeHtml ( token . content ) }</span>` ; } } ) ; html += `</div>` ; } } ) ; html = html . replace ( /\n*$/ , "" ) ; html += `</code></div></pre>` ; return html ; }