Add support for non breaking space

Use case or problem

From time to time a non-breaking space is needed (Unicode U+00A0). E.g. for connecting dates 3 June or June 3 or numbers 5 g of salt), words King Louis XIV or some symbols (e.g. dashes in a sentence (sentence – some insert – continuation) in some languages like German).

Proposed solution

Allow the insertion of non-breaking spaces (Shift+Space on my machine), convert them to   and show a slightly greyed space in live-preview mode (similar to Word).

Raw: 3 June
Live-Preview: 3 June (gray white space indicating a nbsp)
Reading: 3 June (with actual non breaking space)

In Live-Preview mode it would not be necessary to be able to edit the actual  . If your cursor is at the whitespace symbol, it doesn’t get expanded. You’d be able to delete the space by hitting backspace once, and you’d navigate over it by pressing left/right only once.

So, King Louis |XIV [backspace] becomes → King Louis|XIV
And King Louis |XIV [left] becomes → King Louis| XIV

Current workaround (optional)


Related feature requests (optional)

None that I’m aware of.

Non-breaking space seems to work in my vault (either entered by keyboard on Mac [Opt+Space] or entered as  ). What support do you want? Just the highlighting?

1 Like

It seems I entered the non-breaking spaces wrongly. So, support is there.

Then I’ll request just the highlighting.

If the core devs are going to work on highlighting non-breaking space, then I would also suggest they handle all sorts of whitespace characters.

Here’s how I highlight in vim:

set listchars=tab:→\ ,nbsp:␣,trail:·

highlight UnicodeWhitespace term=reverse ctermfg=red ctermbg=NONE cterm=underline guifg=red guibg=NONE gui=reverse
" The list is from (with `\t`, `\n`, ` `, `\xa0` removed):
call matchadd('UnicodeWhitespace', '[\x0b\x0c\r\x1c\x1d\x1e\x1f\x85\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000]')

The best is how IntelliJ handles it out of the box:

when tested on:

 " Test: [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]

(who knows if Discourse will accept my pasting of unicode chars above though)