Giter Club home page Giter Club logo

Comments (7)

pjkaufman avatar pjkaufman commented on September 22, 2024

Hey @AndreiSager . The Linter does not directly support this use case. However it does allow you to use custom regex for this situation. How familiar are you with regex?

from obsidian-linter.

AndreiSager avatar AndreiSager commented on September 22, 2024

Thanks for responding! I am not familiar with regex, but I have heard of it.

from obsidian-linter.

LV avatar LV commented on September 22, 2024

For those reading this, these are the steps necessary to make this happen:

  1. Open Settings > Linter > Custom
  2. Add new regex replacement, do the following:
  • regex to find: ([^ \t\r\n\v\f])\n(#)
  • gm
  • regex to replace: $1\n\n$2

from obsidian-linter.

AndreiSager avatar AndreiSager commented on September 22, 2024

For those reading this, these are the steps necessary to make this happen:

  1. Open Settings > Linter > Custom
  2. Add new regex replacement, do the following:
  • regex to find: ([^ \t\r\n\v\f])\n(#)
  • gm
  • regex to replace: $1\n\n$2

Thank you for your solution! I have tried it and it is not working. Am I supposed to disable or enable a setting to make it work?

image

from obsidian-linter.

pjkaufman avatar pjkaufman commented on September 22, 2024

The regex you need will be based on the following logic in the code:

      text = text.replace(/^(#+\s.*)/gm, '\n\n$1\n\n'); // add blank line before and after headings
      text = text.replace(/\n+(#+\s.*)/g, '\n\n$1'); // trim blank lines before headings
      text = text.replace(/(^#+\s.*)\n+/gm, '$1\n\n'); // trim blank lines after headings
    }

    text = text.replace(/^\n+(#+\s.*)/, '$1'); // remove blank lines before first heading
    text = text.replace(/(#+\s.*)\n+$/, '$1'); // remove blank lines after last heading

So if you want to make it so that all headings have something like /^(#+\s.*)/gm and the \n\n\n$1 for the replace.
Then you need to trim blank lines before headings if they are too long: /\n{2,}(#+\s.*)/g for find and \n\n\n$1 for replace.
Lastly, you nedd to remove the blank lines before the first heading:
^\n+(#+\s.*) and the replace $1 and make sure it has no flags.

Thus it looks something like this:

Search Flags Replace
^(#+\s.*) gm \n\n\n$1
\n{2,}(#+\s.*) g \n\n\n$1
^\n+(#+\s.*) $1

Note: I have not tested this and cannot really do so at this time. But hopefully this gets you roughly to wherw you need to be.

from obsidian-linter.

AndreiSager avatar AndreiSager commented on September 22, 2024

@pjkaufman Thank you very much for helping solve my problem! The solution you gave works wonders!

image
image

from obsidian-linter.

pjkaufman avatar pjkaufman commented on September 22, 2024

I am glad that it works!

from obsidian-linter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.