Skip to content

Commit

Permalink
Merge pull request #204 from pjkaufman/master
Browse files Browse the repository at this point in the history
Fix Issue with Yaml FrontMatter Including More Than Initial Frontmatter
  • Loading branch information
pjkaufman authored May 20, 2022
2 parents b37a80d + 9ae4347 commit 85abb9a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,14 +532,41 @@ describe('yaml timestamp', () => {
});
});
describe('Insert yaml attributes', () => {
it('Inits yaml is not exist', () => {
it('Inits yaml if it does not exist', () => {
const before = dedent`
`;
const after = dedent`
---
tags:
---
`;
expect(rulesDict['insert-yaml-attributes'].apply(before, {'Text to insert': 'tags:'})).toBe(after);
});
// accounts for https://github.com/platers/obsidian-linter/issues/176
it('Inits yaml when the file has --- in it and no frontmatter', () => {
const before = dedent`
# Heading
Text
# Heading
- Text
- Text
---
`;
const after = dedent`
---
tags:
---
# Heading
Text
# Heading
- Text
- Text
---
`;
expect(rulesDict['insert-yaml-attributes'].apply(before, {'Text to insert': 'tags:'})).toBe(after);
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import remarkGfm from 'remark-gfm';

export const headerRegex = /^(\s*)(#+)(\s+)(.*)$/;
export const fencedRegexTemplate = '^XXX\\.*?\n(?:((?:.|\n)*?)\n)?XXX(?=\\s|$)$';
export const yamlRegex = /^---\n(?:((?:.|\n)*?)\n)?---(?=\n|$)/;
export const yamlRegex = /^---\n((?:(((?!---)(?:.|\n)*?)\n)?))---(?=\n|$)/;
export const backtickBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '`');
export const tildeBlockRegexTemplate = fencedRegexTemplate.replaceAll('X', '~');
export const indentedBlockRegex = '^((\t|( {4})).*\n)+';
Expand Down

0 comments on commit 85abb9a

Please sign in to comment.