@@ -203,25 +203,9 @@ class Publisher {
203
203
//Remove frontmatter from transclusion
204
204
fileText = fileText . replace ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - / g, "" ) ;
205
205
206
- // Calculate what header to apply to the transclusion
207
- const titleVariable = "{{title}}" ;
208
- if ( headerName && headerName . indexOf ( titleVariable ) > - 1 ) {
209
- headerName = headerName . replace ( titleVariable , linkedFile . basename ) ;
210
- }
211
-
212
- //Defaults to h1
213
- if ( headerName && ! headerName . startsWith ( "#" ) ) {
214
- headerName = "# " + headerName ;
215
- } else if ( headerName ) {
216
- //Add a space to the start of the header if not already there
217
- const headerParts = headerName . split ( "#" ) ;
218
- if ( ! headerParts . last ( ) . startsWith ( " " ) ) {
219
- headerName = headerName . replace ( headerParts . last ( ) , " " + headerParts . last ( ) ) ;
220
- }
221
-
222
- }
206
+ const header = this . generateTransclusionHeader ( headerName , linkedFile ) ;
223
207
224
- const headerSection = headerName ? `${ headerName } \n` : '' ;
208
+ const headerSection = header ? `${ header } \n` : '' ;
225
209
226
210
fileText = "\n```transclusion\n" + headerSection + fileText + '\n```\n'
227
211
//This should be recursive up to a certain depth
@@ -259,6 +243,32 @@ class Publisher {
259
243
260
244
return imageText ;
261
245
}
246
+
247
+ generateTransclusionHeader ( headerName : string , transcludedFile : TFile ) {
248
+ if ( ! headerName ) {
249
+ return headerName ;
250
+ }
251
+
252
+ const titleVariable = "{{title}}" ;
253
+ if ( headerName && headerName . indexOf ( titleVariable ) > - 1 ) {
254
+ headerName = headerName . replace ( titleVariable , transcludedFile . basename ) ;
255
+ }
256
+
257
+ //Defaults to h1
258
+ if ( headerName && ! headerName . startsWith ( "#" ) ) {
259
+ headerName = "# " + headerName ;
260
+ } else if ( headerName ) {
261
+ //Add a space to the start of the header if not already there
262
+ const headerParts = headerName . split ( "#" ) ;
263
+ if ( ! headerParts . last ( ) . startsWith ( " " ) ) {
264
+ headerName = headerName . replace ( headerParts . last ( ) , " " + headerParts . last ( ) ) ;
265
+ }
266
+
267
+ }
268
+ return headerName ;
269
+ }
262
270
}
263
271
264
272
export default Publisher ;
273
+
274
+
0 commit comments