Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Eskild Steensen committed Mar 11, 2022
1 parent 99bca24 commit 336705c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
46 changes: 28 additions & 18 deletions Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,9 @@ class Publisher {
//Remove frontmatter from transclusion
fileText = fileText.replace(/^---\n([\s\S]*?)\n---/g, "");

// Calculate what header to apply to the transclusion
const titleVariable = "{{title}}";
if (headerName && headerName.indexOf(titleVariable) > -1) {
headerName = headerName.replace(titleVariable, linkedFile.basename);
}

//Defaults to h1
if (headerName && !headerName.startsWith("#")) {
headerName = "# " + headerName;
} else if (headerName) {
//Add a space to the start of the header if not already there
const headerParts = headerName.split("#");
if (!headerParts.last().startsWith(" ")) {
headerName = headerName.replace(headerParts.last(), " " + headerParts.last());
}

}
const header = this.generateTransclusionHeader(headerName, linkedFile);

const headerSection = headerName ? `${headerName}\n` : '';
const headerSection = header ? `${header}\n` : '';

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

return imageText;
}

generateTransclusionHeader(headerName: string, transcludedFile: TFile) {
if(!headerName) {
return headerName;
}

const titleVariable = "{{title}}";
if (headerName && headerName.indexOf(titleVariable) > -1) {
headerName = headerName.replace(titleVariable, transcludedFile.basename);
}

//Defaults to h1
if (headerName && !headerName.startsWith("#")) {
headerName = "# " + headerName;
} else if (headerName) {
//Add a space to the start of the header if not already there
const headerParts = headerName.split("#");
if (!headerParts.last().startsWith(" ")) {
headerName = headerName.replace(headerParts.last(), " " + headerParts.last());
}

}
return headerName;
}
}

export default Publisher;


21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,31 @@ By default, transclusion of other documents just renders the content as is. If y
![[Some Other Note|Heading]]
```

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

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

You can also use the title syntax inside other text:
```
![[Some Other Note|This is a {{title}}]]
```

#### Specifying heading level
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:
```
![[Some Other Note|##Heading]]
```

h4 would look like this:
```
![[Some Other Note|####Heading]]
```

#### Default behaviour
By just using regular translucion, no header will be added:
```
![[Some Other Note]]
Expand Down

0 comments on commit 336705c

Please sign in to comment.