import { escapeHtml , Meta } from "../utils" ; export interface HtmlRendererOptions { langId ? : string ; fg ? : string ; bg ? : string ; themeName ? : string ; } /** A func for setting a consistent <pre> */ export const preOpenerFromRenderingOptsWithExtras = ( opts , meta , classes ? ) => { const bg = opts . bg || "#fff" ; const fg = opts . fg || "black" ; const theme = opts . themeName || "" ; const classList = [ "shiki" , theme , meta . class , meta . title ? "with-title" : "" , ... ( classes || [ ] ) ] . filter ( Boolean ) . join ( " " ) . trim ( ) ; const attributes = Object . entries ( meta ) . filter ( entry => { return ( [ "string" , "number" , "boolean" ] . includes ( typeof entry [ 1 ] ) && ! [ "class" , "twoslash" ] . includes ( entry [ 0 ] ) && entry [ 1 ] !== false ) ; } ) . map ( ( [ key , value ] ) => `${ key }="${ value }"` ) . join ( " " ) . trim ( ) ; return `<pre class="${ classList }" style="background-color: ${ bg }; color: ${ fg }"${ attributes ? ` ${ attributes }` : '' }>` ; } ; /** You don't have a language which shiki twoslash can handle, make a DOM compatible version  */ export function plainTextRenderer ( code , options , meta ) { let html = "" ; html += preOpenerFromRenderingOptsWithExtras ( options , meta , [ ] ) ; 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>` ; html += escapeHtml ( code ) ; html = html . replace ( /\n*$/ , "" ) ; html += `</code></div></pre>` ; return html ; }