From 336705c2c1ac1f525963c8689d62a1c9fa9e5e64 Mon Sep 17 00:00:00 2001 From: Ole Eskild Steensen Date: Fri, 11 Mar 2022 12:58:03 +0100 Subject: [PATCH] Update docs --- Publisher.ts | 46 ++++++++++++++++++++++++++++------------------ README.md | 21 +++++++++++++++++++-- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/Publisher.ts b/Publisher.ts index 417aed72..5ab75013 100644 --- a/Publisher.ts +++ b/Publisher.ts @@ -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 @@ -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; + + diff --git a/README.md b/README.md index bef0e6dd..14d4670e 100644 --- a/README.md +++ b/README.md @@ -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]]