Skip to content

Commit

Permalink
Merge pull request #544 from pjkaufman/master
Browse files Browse the repository at this point in the history
Fix `Consecutive Blank Lines` Affecting Whitedspace at Start of Line after a Blank
  • Loading branch information
pjkaufman authored Dec 9, 2022
2 parents 722812e + 8bff353 commit e300ebb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
54 changes: 54 additions & 0 deletions __tests__/consecutive-blank-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,59 @@ ruleTest({
Line 2
`,
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/538
testName: 'Make sure that lists with a blank line between them are not affected since there are not 2 or more blank lines',
before: dedent`
- Item 1
${''}
- Subitem 1
${''}
- Subitem 2
${''}
- Sub sub item 1
${''}
- Sub sub item 2
`,
after: dedent`
- Item 1
${''}
- Subitem 1
${''}
- Subitem 2
${''}
- Sub sub item 1
${''}
- Sub sub item 2
`,
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/543
testName: 'Make sure that nested code blocks with a blank line between them are not affected since there are not 2 or more blank lines',
before: dedent`
1. \`aaa\` bbbb,
3. xxxxxxxxxxxxxxx
\`\`\`csharp
private IProcessor[] GetProcessors()
{
return returnedProcessors.ToArray();
}
\`\`\`
4. ccccccc,
`,
after: dedent`
1. \`aaa\` bbbb,
3. xxxxxxxxxxxxxxx
\`\`\`csharp
private IProcessor[] GetProcessors()
{
return returnedProcessors.ToArray();
}
\`\`\`
4. ccccccc,
`,
},
],
});
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-linter",
"name": "Linter",
"version": "1.9.0",
"version": "1.9.1",
"minAppVersion": "0.15.6",
"description": "Formats and styles your notes. It can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular markdown contents like list, italics, and bold styles; and more with the use of custom rule options as well.",
"author": "Victor Tao",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-linter",
"version": "1.9.0",
"version": "1.9.1",
"description": "Enforces consistent markdown styling for Obsidian (https://obsidian.md). It can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular markdown contents like list, italics, and bold styles; and more with the use of custom rule options as well.",
"main": "main.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/rules/consecutive-blank-lines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default class ConsecutiveBlankLines extends RuleBuilder<ConsecutiveBlankL
apply(text: string, options: ConsecutiveBlankLinesOptions): string {
return ignoreListOfTypes([IgnoreTypes.code, IgnoreTypes.yaml, IgnoreTypes.link, IgnoreTypes.wikiLink, IgnoreTypes.tag], text, (text) => {
// make sure to account for lines that are purely whitespace as well https://stackoverflow.com/a/3873354/8353749
return text.replace(/(\n([\t\v\f\r \u00a0\u2000-\u200b\u2028-\u2029\u3000]+)?){2,}/g, '\n\n');
// make sure that the match ends in a newline
return text.replace(/(\n([\t\v\f\r \u00a0\u2000-\u200b\u2028-\u2029\u3000]+)?){2,}\n/g, '\n\n');
});
}
get exampleBuilders(): ExampleBuilder<ConsecutiveBlankLinesOptions>[] {
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.9.1": "0.15.6",
"1.9.0": "0.15.6",
"1.8.0": "0.15.6",
"1.7.1": "0.15.6",
Expand Down

0 comments on commit e300ebb

Please sign in to comment.