@@ -81,11 +81,17 @@ export function transpileTemplate(input: string, tag?: string, raw?: boolean): s
81
81
export function transpileTemplate ( cell : Cell ) : string ;
82
82
export function transpileTemplate ( input : string | Cell , tag = "" , raw = false ) : string {
83
83
let cell : Cell | undefined ;
84
+ let prefix : string ;
85
+ let suffix : string ;
84
86
if ( typeof input !== "string" ) {
85
87
cell = input ;
86
88
input = cell . value ;
87
- tag = getTag ( cell ) ;
89
+ prefix = getPrefix ( cell ) ;
90
+ suffix = getSuffix ( cell ) ;
88
91
raw = getRaw ( cell ) ;
92
+ } else {
93
+ prefix = tag ;
94
+ suffix = "" ;
89
95
}
90
96
if ( ! input ) return input ;
91
97
const source = new Sourcemap ( input ) ;
@@ -100,34 +106,33 @@ export function transpileTemplate(input: string | Cell, tag = "", raw = false):
100
106
( raw ? escapeRawTemplateElements : escapeTemplateElements ) ( source , template ) ;
101
107
node = template ;
102
108
}
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 ) ;
107
112
}
108
113
109
114
function getRaw ( cell : Cell ) : boolean {
110
115
return cell . mode !== "md" ;
111
116
}
112
117
113
- function getTag ( cell : Cell ) : string {
118
+ function getPrefix ( cell : Cell ) : string {
114
119
return cell . mode === "tex"
115
120
? "tex.block"
116
121
: cell . mode === "sql"
117
- ? getSqlTag ( cell )
122
+ ? getSqlPrefix ( cell )
118
123
: isInterpreter ( cell . mode )
119
- ? getInterpreterTag ( cell )
124
+ ? getInterpreterPrefix ( cell )
120
125
: cell . mode ;
121
126
}
122
127
123
- function getSqlTag ( cell : Cell ) : string {
128
+ function getSqlPrefix ( cell : Cell ) : string {
124
129
const { id, database = "var:db" , since} = cell ;
125
130
return database . startsWith ( "var:" )
126
131
? `${ database . slice ( "var:" . length ) } .sql`
127
132
: `DatabaseClient(${ JSON . stringify ( database ) } , {id: ${ id } ${ since === undefined ? "" : `, since: ${ JSON . stringify ( since ) } ` } }).sql` ;
128
133
}
129
134
130
- function getInterpreterTag ( cell : Cell ) : string {
135
+ function getInterpreterPrefix ( cell : Cell ) : string {
131
136
const { id, mode, format, since} = cell ;
132
137
return `Interpreter(${ JSON . stringify ( mode ) } , {id: ${ id } ${ format === undefined ? "" : `, format: ${ JSON . stringify ( format ) } ` } ${ since === undefined ? "" : `, since: ${ JSON . stringify ( since ) } ` } }).run(` ;
133
138
}
@@ -142,7 +147,7 @@ function getSuffix(cell: Cell): string {
142
147
143
148
function getInterpreterSuffix ( cell : Cell ) : string {
144
149
const method = getInterpreterMethod ( cell . format ) ;
145
- return method ? `).then((file) => file${ method } )` : "" ;
150
+ return method ? `).then((file) => file${ method } )` : ") " ;
146
151
}
147
152
148
153
function escapeTemplateElements ( source : Sourcemap , node : TemplateLiteral ) : void {
0 commit comments