Linter: Need help removing double line breaks after Headlines

What I’m trying to do

I am using linter, and want to easily convert (often imported) text like this

# Headline

Text

to this

# Headline
Text

This is the way I have always written Markdown, and it has consistently worked for me. Now i am tired of meticulously stepping through the document, deleting every break between headline and body text manually.

Things I have tried

I see that Linter has a setting called Heading Blank lines. This even has a toggle to disable line before and after the heading, but linting it with the “after” setting off provides no results.

While it does remove more than 2 line breaks after Heading, it only deletes line breaks that extends two line breaks. Although it doesn’t add line breaks If it is just a single br, it also doesn’t remove it, which seems weird when there is even a setting for removing the “bottom” part of the blank line argument.

I have meticulously walked through the myriad of settings in Linter to see if I have any potential settings that provides this disobedience to my want, but can’t seem to find it.

Can I make Linter do this? To simply remove the double line break after Headings?

1 Like

I have looked into this just now.
I decided to make a custom rule in a Sandbox vault to try.

In the last but one tab (Custom) add a Custom Regex Replacement:

Call the rule whatever you want (you can use what I named it: Remove Blank Lines After Headings). Then add match first and replacement in the second bar. Leave gm (global multiline flags) as it is.
Match: (^#{1,6}\s.+)(\n{2,3})
Replacement: $1\n

Lint a file or whole folders to bring your texts right below any headings (H1-H6).

\n{2,3} means this currently removes 1 or 2 empty lines. I think this should be sufficient to go on.

You can leave the rule there for ever, of course. That’s the point of linting: to standardize markdown notes structure across your vault.

2 Likes

I have to get some sleep now, but just want to say the speed and helping hand of the people in this forum is incredible. Thanks. Will check this in the mornin, thanks. :raised_hands:t2:

No problem.

It worked like a charm. Thanks!

1 Like