platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.17k stars 81 forks source link

FR: Auto insert NO-BREAK SPACE(U+00A0) between numbers & units, or change normal space to it #816

Open Tylannn opened 1 year ago

Tylannn commented 1 year ago

Auto insert NO-BREAK SPACE(U+00A0) between numbers & units, or change normal space to it

"In word processing and digital typesetting, a non-breaking space - also called NBSP, required space, hard space, or fixed space - is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space."

It's an elegant feature to improve our note, and it's 100% compatible when copied to other apps.

For example,

You can copy the below text into another place and add space before the "1 km", then you will see the feature.

- NO-BREAK SPACE: 1 km
- NORMAL SPACE: 1 km

Normally, this is the look
`NO-BREAK SPACE: 
1 km
`
`NORMAL SPACE: 1 
km`

There are so many units like mya, ly, hr, km, min and sec, etc. It is weird and less to know. So I also recommend supporting users to input units they often use.

I'm a beginner in English, SRY if you feel uncomfortable. :)

Tylannn commented 1 year ago

Supplement: This is a Unicode feature, no need to use  , " "(U+00A0) is more compatible.

pjkaufman commented 1 year ago

This seems like something that would be addressed by a custom command added through Quick Add to me. But if there is a desire from the community to have this added as a rule in the Linter that can be done as well.

Tylannn commented 1 year ago

Yeah, it can be done by custom command. Here is an example: (?<=\d) ?(?=km|mya) ->   But I thought it's a basic feature, people may love it.

koralfx commented 1 year ago

I will expand on the subject. In Polish (and possibly Czech) it is not allowed to leave one-letter words at the end of a line. Not only after numbers. Could you just consider adding an option to change a regular space to a non-breakable space after single letter words? I know it can be done with regex, but it will be easier for normal users...