Skip to content

Commit 336705c

Browse files
author
Ole Eskild Steensen
committed
Update docs
1 parent 99bca24 commit 336705c

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

Publisher.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,25 +203,9 @@ class Publisher {
203203
//Remove frontmatter from transclusion
204204
fileText = fileText.replace(/^---\n([\s\S]*?)\n---/g, "");
205205

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);
223207

224-
const headerSection = headerName ? `${headerName}\n` : '';
208+
const headerSection = header ? `${header}\n` : '';
225209

226210
fileText = "\n```transclusion\n" + headerSection + fileText + '\n```\n'
227211
//This should be recursive up to a certain depth
@@ -259,6 +243,32 @@ class Publisher {
259243

260244
return imageText;
261245
}
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+
}
262270
}
263271

264272
export default Publisher;
273+
274+

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,31 @@ By default, transclusion of other documents just renders the content as is. If y
9696
![[Some Other Note|Heading]]
9797
```
9898

99-
This will add a header with the value "Heading" at the start of your transclusion.
99+
This will add a h1 header with the value "Heading" at the start of your transclusion.
100100

101-
If you want the header to be equal to the title of the transcluded document, you can use this special syntax:
101+
If you want the header to be equal to the title of the transcluded document, you can use this custom syntax:
102102
```
103103
![[Some Other Note|{{title}}]]
104104
```
105105
This will replace the heading with the title of the transcluded document when the note is published.
106106

107+
You can also use the title syntax inside other text:
108+
```
109+
![[Some Other Note|This is a {{title}}]]
110+
```
111+
112+
#### Specifying heading level
113+
You may also specify what heading level you want your transclusion to have. If you want the header to be a h2, you can use this syntax:
114+
```
115+
![[Some Other Note|##Heading]]
116+
```
117+
118+
h4 would look like this:
119+
```
120+
![[Some Other Note|####Heading]]
121+
```
122+
123+
#### Default behaviour
107124
By just using regular translucion, no header will be added:
108125
```
109126
![[Some Other Note]]

0 commit comments

Comments
 (0)