Skip to content

Commit ed076ca

Browse files
committed
Fix #17 and fix for bug if templates are empty
1 parent ab6e17e commit ed076ca

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

exampleVault/.obsidian/plugins/obsidian-meta-bind-plugin/main.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exampleVault/examples.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ rating: 31
33
title: test title test test
44
completed: false
55
toggle1: false
6-
slider1: 5
7-
slider2: 5
6+
slider1: 7
7+
slider2: 6
88
text1: Test text
99
text_area1: Test test
1010
date1: 2022-05-28
@@ -88,6 +88,8 @@ option(option d)
8888
> [!INFO]
8989
> `INPUT[slider(addLabels, minValue(1), maxValue(10)):slider1]`
9090
91+
---
92+
9193
## Linking to a different note
9294
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque sit amet porttitor arcu. Quisque scelerisque dolor augue, et posuere nulla bibendum nec. Curabitur sed rhoncus nisl.
9395

exampleVault/other note.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: asdasd
2+
title: asdasds sdf sdsdlkfnosdijn sdaskdjasbokbfosdasdasdasd asd asdasda f
33
select: option b
44
multi-select:
55
- option b
66
- option c
7-
date: 2029-05-11
7+
date: Wednesday, September 19th 2029
88
time: 19:20
99
---

src/main.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export default class MetaBindPlugin extends Plugin {
1515
// @ts-ignore defined in `onload`
1616
markDownInputFieldIndex: number;
1717

18+
frontMatterRexExpPattern = '^(---)\\n[\\s\\S]*?\\n---'
19+
1820
async onload(): Promise<void> {
1921
await this.loadSettings();
2022

@@ -118,7 +120,7 @@ export default class MetaBindPlugin extends Plugin {
118120
return;
119121
}
120122

121-
const regExp = new RegExp('^(---)\\n[\\s\\S]*\\n---');
123+
const regExp = new RegExp(this.frontMatterRexExpPattern);
122124
fileContent = fileContent.replace(regExp, '');
123125

124126
metadata[key] = value;
@@ -164,8 +166,9 @@ export default class MetaBindPlugin extends Plugin {
164166
// Logger.logDebug(`reading metadata`);
165167
let metadata: any;
166168

167-
const regExp = new RegExp('^(---)\\n[\\s\\S]*\\n---');
169+
const regExp = new RegExp(this.frontMatterRexExpPattern);
168170
const frontMatterRegExpResult = regExp.exec(fileContent);
171+
// console.log('regexres: ', frontMatterRegExpResult);
169172
if (!frontMatterRegExpResult) {
170173
return {};
171174
}
@@ -184,7 +187,7 @@ export default class MetaBindPlugin extends Plugin {
184187
metadata = {};
185188
}
186189

187-
//console.log(metadata);
190+
// console.log('metadata: ', metadata);
188191

189192
return metadata;
190193
}

src/parsers/InputFieldDeclarationParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class InputFieldDeclarationParser {
127127
}
128128

129129
static parseTemplates(templates: string): void {
130-
let templateDeclarations = ParserUtils.split(templates, '\n', InputFieldDeclarationParser.squareBracesPair);
130+
let templateDeclarations = templates ? ParserUtils.split(templates, '\n', InputFieldDeclarationParser.squareBracesPair) : [];
131131
templateDeclarations = templateDeclarations.map(x => x.trim()).filter(x => x.length > 0);
132132

133133
for (const templateDeclaration of templateDeclarations) {

0 commit comments

Comments
 (0)