@@ -81,11 +81,17 @@ export function transpileTemplate(input: string, tag?: string, raw?: boolean): s
8181export function transpileTemplate ( cell : Cell ) : string ;
8282export function transpileTemplate ( input : string | Cell , tag = "" , raw = false ) : string {
8383 let cell : Cell | undefined ;
84+ let prefix : string ;
85+ let suffix : string ;
8486 if ( typeof input !== "string" ) {
8587 cell = input ;
8688 input = cell . value ;
87- tag = getTag ( cell ) ;
89+ prefix = getPrefix ( cell ) ;
90+ suffix = getSuffix ( cell ) ;
8891 raw = getRaw ( cell ) ;
92+ } else {
93+ prefix = tag ;
94+ suffix = "" ;
8995 }
9096 if ( ! input ) return input ;
9197 const source = new Sourcemap ( input ) ;
@@ -100,34 +106,33 @@ export function transpileTemplate(input: string | Cell, tag = "", raw = false):
100106 ( raw ? escapeRawTemplateElements : escapeTemplateElements ) ( source , template ) ;
101107 node = template ;
102108 }
103- source . insertLeft ( node . start , "`" ) ;
104- source . insertRight ( node . end , "`" ) ;
105- source . insertLeft ( node . start , tag ) ;
106- return String ( source ) + ( cell ? getSuffix ( cell ) : "" ) ;
109+ source . insertLeft ( node . start , `${ prefix } \`` ) ;
110+ source . insertRight ( node . end , `\`${ suffix } ` ) ;
111+ return String ( source ) ;
107112}
108113
109114function getRaw ( cell : Cell ) : boolean {
110115 return cell . mode !== "md" ;
111116}
112117
113- function getTag ( cell : Cell ) : string {
118+ function getPrefix ( cell : Cell ) : string {
114119 return cell . mode === "tex"
115120 ? "tex.block"
116121 : cell . mode === "sql"
117- ? getSqlTag ( cell )
122+ ? getSqlPrefix ( cell )
118123 : isInterpreter ( cell . mode )
119- ? getInterpreterTag ( cell )
124+ ? getInterpreterPrefix ( cell )
120125 : cell . mode ;
121126}
122127
123- function getSqlTag ( cell : Cell ) : string {
128+ function getSqlPrefix ( cell : Cell ) : string {
124129 const { id, database = "var:db" , since} = cell ;
125130 return database . startsWith ( "var:" )
126131 ? `${ database . slice ( "var:" . length ) } .sql`
127132 : `DatabaseClient(${ JSON . stringify ( database ) } , {id: ${ id } ${ since === undefined ? "" : `, since: ${ JSON . stringify ( since ) } ` } }).sql` ;
128133}
129134
130- function getInterpreterTag ( cell : Cell ) : string {
135+ function getInterpreterPrefix ( cell : Cell ) : string {
131136 const { id, mode, format, since} = cell ;
132137 return `Interpreter(${ JSON . stringify ( mode ) } , {id: ${ id } ${ format === undefined ? "" : `, format: ${ JSON . stringify ( format ) } ` } ${ since === undefined ? "" : `, since: ${ JSON . stringify ( since ) } ` } }).run(` ;
133138}
@@ -142,7 +147,7 @@ function getSuffix(cell: Cell): string {
142147
143148function getInterpreterSuffix ( cell : Cell ) : string {
144149 const method = getInterpreterMethod ( cell . format ) ;
145- return method ? `).then((file) => file${ method } )` : "" ;
150+ return method ? `).then((file) => file${ method } )` : ") " ;
146151}
147152
148153function escapeTemplateElements ( source : Sourcemap , node : TemplateLiteral ) : void {
0 commit comments