Skip to content

Commit b1cb567

Browse files
authored
Merge pull request #1171 from thomas-forbes/master
horizontal rule spacing
2 parents 55a7e62 + e0a5f6d commit b1cb567

File tree

8 files changed

+565
-1
lines changed

8 files changed

+565
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ Each rule is its own set of logic and is designed to be run independently. This
7474
- [convert-spaces-to-tabs](https://platers.github.io/obsidian-linter/settings/spacing-rules/#convert-spaces-to-tabs)
7575
- [empty-line-around-blockquotes](https://platers.github.io/obsidian-linter/settings/spacing-rules/#empty-line-around-blockquotes)
7676
- [empty-line-around-code-fences](https://platers.github.io/obsidian-linter/settings/spacing-rules/#empty-line-around-code-fences)
77+
- [empty-line-around-horizontal-rules](https://platers.github.io/obsidian-linter/settings/spacing-rules/#empty-line-around-horizontal-rules)
7778
- [empty-line-around-math-blocks](https://platers.github.io/obsidian-linter/settings/spacing-rules/#empty-line-around-math-blocks)
7879
- [empty-line-around-tables](https://platers.github.io/obsidian-linter/settings/spacing-rules/#empty-line-around-tables)
7980
- [heading-blank-lines](https://platers.github.io/obsidian-linter/settings/spacing-rules/#heading-blank-lines)
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
import dedent from 'ts-dedent';
2+
import EmptyLineAroundHorizontalRules from '../src/rules/empty-line-around-horizontal-rules';
3+
import {ruleTest} from './common';
4+
5+
ruleTest({
6+
RuleBuilderClass: EmptyLineAroundHorizontalRules,
7+
testCases: [
8+
{
9+
testName:
10+
'Horizontal rules that start a document do get an empty line before them.',
11+
before: dedent`
12+
***
13+
${''}
14+
${''}
15+
Content
16+
`,
17+
after: dedent`
18+
***
19+
${''}
20+
Content
21+
`,
22+
},
23+
{
24+
testName: 'Horizontal rules that end a document do not get an empty line after them.',
25+
before: dedent`
26+
***
27+
Content
28+
***
29+
`,
30+
after: dedent`
31+
***
32+
${''}
33+
Content
34+
${''}
35+
***
36+
`,
37+
},
38+
{
39+
testName: 'YAML frontmatter is not affected by this rule',
40+
before: dedent`
41+
---
42+
prop: value
43+
---
44+
${''}
45+
Content
46+
`,
47+
after: dedent`
48+
---
49+
prop: value
50+
---
51+
${''}
52+
Content
53+
`,
54+
},
55+
{
56+
testName: 'All types of horizontal rules are affected by this rule',
57+
before: dedent`
58+
- Content 1
59+
***
60+
- Content 2
61+
---
62+
- Content 3
63+
___
64+
- Content 4
65+
`,
66+
after: dedent`
67+
- Content 1
68+
${''}
69+
***
70+
${''}
71+
- Content 2
72+
${''}
73+
---
74+
${''}
75+
- Content 3
76+
${''}
77+
___
78+
${''}
79+
- Content 4
80+
`,
81+
},
82+
{
83+
testName: 'Paragraphs above `---` are treated as a heading and not spaced apart',
84+
before: dedent`
85+
Content
86+
---
87+
`,
88+
after: dedent`
89+
Content
90+
---
91+
`,
92+
},
93+
{
94+
testName: 'Horizontal rules between blockquotes',
95+
before: dedent`
96+
> Blockquote
97+
> > Nested Blockquote
98+
---
99+
> Blockquote
100+
> > Nested Blockquote
101+
`,
102+
after: dedent`
103+
> Blockquote
104+
> > Nested Blockquote
105+
${''}
106+
---
107+
${''}
108+
> Blockquote
109+
> > Nested Blockquote
110+
`,
111+
},
112+
{
113+
testName: 'Horizontal rules inside blockquotes',
114+
before: dedent`
115+
> Blockquote
116+
---
117+
> > Nested Blockquote
118+
> Blockquote
119+
> > Nested Blockquote
120+
`,
121+
after: dedent`
122+
> Blockquote
123+
${''}
124+
---
125+
${''}
126+
> > Nested Blockquote
127+
> Blockquote
128+
> > Nested Blockquote
129+
`,
130+
},
131+
{
132+
testName:
133+
'Make sure that basic dash horizontal rules have lines added around them',
134+
before: dedent`
135+
- asdf
136+
---
137+
- qwer
138+
`,
139+
after: dedent`
140+
- asdf
141+
${''}
142+
---
143+
${''}
144+
- qwer
145+
`,
146+
},
147+
{
148+
testName: 'Make sure that basic asterisk horizontal rules have lines added around them',
149+
before: dedent`
150+
asdf
151+
***
152+
qwer
153+
`,
154+
after: dedent`
155+
asdf
156+
${''}
157+
***
158+
${''}
159+
qwer
160+
`,
161+
},
162+
{
163+
testName: 'Make sure that basic underscore horizontal rules have lines added around them',
164+
before: dedent`
165+
asdf
166+
___
167+
qwer
168+
`,
169+
after: dedent`
170+
asdf
171+
${''}
172+
___
173+
${''}
174+
qwer
175+
`,
176+
},
177+
{
178+
testName: 'Make sure that horizontal rules for frontmatter don\'t have lines added around them',
179+
before: dedent`
180+
---
181+
prop: value
182+
---
183+
${''}
184+
asdf
185+
___
186+
qwer
187+
`,
188+
after: dedent`
189+
---
190+
prop: value
191+
---
192+
${''}
193+
asdf
194+
${''}
195+
___
196+
${''}
197+
qwer
198+
`,
199+
},
200+
],
201+
});

docs/docs/settings/spacing-rules.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,128 @@ var text = 'some string';
386386
``````
387387
</details>
388388

389+
## Empty Line Around Horizontal Rules
390+
391+
Alias: `empty-line-around-horizontal-rules`
392+
393+
Ensures that there is an empty line around horizontal rules unless they start or end a document.
394+
395+
396+
397+
398+
399+
### Examples
400+
401+
<details><summary>Horizontal rules that start a document do not get an empty line before them.</summary>
402+
403+
Before:
404+
405+
`````` markdown
406+
***
407+
408+
409+
Content
410+
``````
411+
412+
After:
413+
414+
`````` markdown
415+
***
416+
417+
Content
418+
``````
419+
</details>
420+
<details><summary>Horizontal rules that end a document do not get an empty line after them.</summary>
421+
422+
Before:
423+
424+
`````` markdown
425+
***
426+
Content
427+
***
428+
``````
429+
430+
After:
431+
432+
`````` markdown
433+
***
434+
435+
Content
436+
437+
***
438+
``````
439+
</details>
440+
<details><summary>All types of horizontal rules are affected by this rule</summary>
441+
442+
Before:
443+
444+
`````` markdown
445+
- Content 1
446+
***
447+
- Content 2
448+
---
449+
- Content 3
450+
___
451+
- Content 4
452+
``````
453+
454+
After:
455+
456+
`````` markdown
457+
- Content 1
458+
459+
***
460+
461+
- Content 2
462+
463+
---
464+
465+
- Content 3
466+
467+
___
468+
469+
- Content 4
470+
``````
471+
</details>
472+
<details><summary>YAML frontmatter is not affected by this rule</summary>
473+
474+
Before:
475+
476+
`````` markdown
477+
---
478+
prop: value
479+
---
480+
481+
Content
482+
``````
483+
484+
After:
485+
486+
`````` markdown
487+
---
488+
prop: value
489+
---
490+
491+
Content
492+
``````
493+
</details>
494+
<details><summary>Paragraphs above `---` are treated as a heading and not spaced apart</summary>
495+
496+
Before:
497+
498+
`````` markdown
499+
Content
500+
---
501+
``````
502+
503+
After:
504+
505+
`````` markdown
506+
Content
507+
---
508+
``````
509+
</details>
510+
389511
## Empty Line Around Math Blocks
390512

391513
Alias: `empty-line-around-math-blocks`

0 commit comments

Comments
 (0)