Skip to content

Commit

Permalink
found and fixed the issue with loading frontmatter that has a line th…
Browse files Browse the repository at this point in the history
…at starts with any number of tabs in it
  • Loading branch information
pjkaufman committed May 25, 2022
1 parent 11441e0 commit e9926ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,27 @@ describe('Insert yaml attributes', () => {
`;
expect(rulesDict['insert-yaml-attributes'].apply(before, {'Text to insert': 'tags:'})).toBe(after);
});
// accounts for https://github.com/platers/obsidian-linter/issues/157
it('When a file has tabs at the start of a line in the frontmatter, the yaml insertion still works leaving other tabs as they were', () => {
const before = dedent`
---
title: this title\thas a tab
tags:
\t- test1
\t- test2
---
`;
const after = dedent`
---
blob:
title: this title\thas a tab
tags:
\t- test1
\t- test2
---
`;
expect(rulesDict['insert-yaml-attributes'].apply(before, {'Text to insert': 'blob:'})).toBe(after);
});
});

describe('Disabled rules parsing', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ export function stripCr(text: string): string {
}

export function loadYAML(yaml_text: string): any {
const parsed_yaml = load(yaml_text) as {};
// replacing tabs at the beginning of new lines with 2 spaces fixes loading yaml that has tabs at the start of a line
// https://github.com/platers/obsidian-linter/issues/157
const parsed_yaml = load(yaml_text.replace(/\n(\t)+/g, '\n ')) as {};
if (!parsed_yaml) {
return {};
}
Expand Down

0 comments on commit e9926ac

Please sign in to comment.