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).

E.g.
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)

None

Related feature requests (optional)

None that I’m aware of.

5 Likes

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 https://stackoverflow.com/a/37903645 (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:
screenshot.2022-07-20T024413Z

when tested on:

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

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

This doesn’t seem to work on WIndows. In French, non-breaking spaces are essential. They are required for proper typographical compnents like question marks, guillements (« ») and colons, among others. In fact, it’s not even a non-breaking space, sometimes it should really be a thin non-breaking space.

I tried all combinations of Ctrl- Shift- Alt- Win- space and none of them inser a non-breaking space. Maybe this is a regression (I,m on the latest version) or maybe there is a plugin that does this? At any rate, I can’t get it to work and I really would like that to be supported.

That’s because it’s not an Obsidian feature, it’s a MacOS feature that works in any app. Windows unfortunately doesn’t have anything like it that I know of. I believe on Windows there is a way to enter any character by typing its Unicode number. There may also be a way to open a character picker, if that’s a system-wide thing (but maybe Windows makes each app provide their own).

Typing   should still work in Obsidian on Windows.

Ah, I see. In Word and LibreOffice it’s Shift-Ctrl-Spacebar so I guess it’s feasible. Entering the Unicode character or .nbsp; every time is kinda tedious. Maybe an extension.

Thanks for the reply,

L

You could make a template containing only a non-breaking space, and optionally assign a hotkey to it (which I think requires a plugin to do).

Unicode Search - community plugin

I think adding unicode characters via pop up menu could be native feature provided that common use cases are documented in Home - Obsidian Help like ⁠,  , °, ², ³, √. Most users don’t have the knowledge to input these characters. Operating system may provide native feature to input unicode characters but in this case Obsidian could provide documentation in Home - Obsidian Help for common use cases like how to input word joiner in mac (⁠).

In mac unicode search use case-insensitive exact match. Some search terms:

  • no-break for  
  • zero width for ⁠
  • superscript for ², ³ etc

At least search terms for   and ⁠ are not obvious and having them added in favorites in symbol browser looks awkward.

I’m missing non-breaking spaces in Obsidian as well.

I tried to use the HTML tag of   for it, because I have a global Windows keyboard shortcut set up for it, but it appears that unlike other HTML tags, Obsidian doesn’t recognize  .

(I’d be perfectly fine with this solution – if simply the HTML code were recognized, and then the display behaved correspondingly in Reading mode and on an Obsidian Publish page.)

Thank you in advance if this can be made possible. :slightly_smiling_face:

What was your test? I tried Non     space and got extra space between the words. Doubling the number increased the space.

Ah! Thank you! So it does work – just the highlighter doesn’t recognize it as an HTML symbol, and displays the   as regular text, white on black. That’s very confusing, of course, and makes proper spellchecking impossible, among other things. I hope a better/cleaner way to handle   in Obsidian will be found in future, but it’s good to know that it does work in those cases when it would be a top priority (although it makes the text pretty much illegible in editing view).

1 Like

@Faterson Can you be more specific what you mean?

Inline entity references &name; are part of CommonMark and GitHub Flavored Markdown meaning that what you are saying is describing an user problem instead of feature request.

Valid HTML entity references and numeric character references can be used in place of the corresponding Unicode character
Entity references consist of & + any of the valid HTML5 entity names + ;. The document https://html.spec.whatwg.org/multipage/entities.json is used as an authoritative source for the valid entity references and their corresponding code points.
Hexadecimal numeric character references consist of &# + either X or x + a string of 1-6 hexadecimal digits + ; . They too are parsed as the corresponding Unicode character.

Example of useful hexadecimal numeric character references—in MathJax HTML entity references should work but \unicode{} command is available:

  • non-breaking hyphen: a dog-friendly hotel ‑ (in LaTeX this is not needed)
  • en dash: 4:30–5:00 – or – or -- in LaTeX
  • em dash: He is afraid of two things—spiders and senior prom — or — or --- in LaTeX
  • multiplication sign: 5 × 10 × or × or $\times$ in LaTeX
  • minus sign: −3 − or − or $-$ in LaTeX
  • medium mathematical space: a × b   or   or \: in LaTeX (no‑break space in LaTeX but in mathmode spacing is usually done automatically—in MathJax automatic line breaking isn’t supported)
  • thin space: 26 000 000   or   or \, in LaTeX (no‑break space in LaTeX, but usually numbers in LaTeX are written using extra packages like siunitx—not available in MathJax)

In theory one could control line braking in Obsidian using css but generally LaTeX is used to produce documents where line braking can be controlled in many ways. This means some Obsidian users may want to convert markdown to latex using Pandoc.

Sure. I don’t use any Latex whatsoever. I’m talking about normal text where it’s ugly if a single-letter word (or number) ends up being isolated at the end of a line of text, which makes the lines look straggly. This is easily resolved in standard HTML by inserting  , instead of standard space, following such a single-character word or single-digit number.

As we’ve discovered in this thread, this also works in Obsidian, but because the   is not highlighted by Obsidian’s editor in any way, and is treated as standard text (which it obviously is not), this looks very ugly, makes the resulting text difficult to read/parse visually, and also ruins spellcheck.

For example, if I wish to input   in between a and dog, so that it cannot possibly happen for the a to end up isolated at the end of a line, it will look like this in Obsidian’s editor:

a dog

That’s terrible, right? The   should be recognized by Obisidian’s editor as a piece of code, should therefore be highlighted in a different color/in code font, and spellcheck should ignore it, because both a and dog are valid words.

You are right—HTML entity references in Obsidian are not syntax-highlighted in live preview or source mode. This should not be the case. In live preview HTML entity references could be rendered automatically.

Note that option + space produces non-breaking space on mac but similar feature isn’t available on windows. On windows 10 special character input is available using win + dot (.)

In broader sense line braking control isn’t part of serious writing and thus other systems like LaTeX must be used to produce quality documents. This means that programs such as Pandoc are very important for every writer who can transfer content from Obsidian to other documents. I believe later in the future we see more 3rd party solutions offering help for writers and other professionals using Obsidian who may not be technically inclined themselves.

Even if it were… I frequently need to insert a series of three consecutive spaces, so it’s this sequence:

   

(That is,   surrounded by 2 ordinary spaces.) I have set up a keyboard shortcut in Obsidian to insert this sequence of 3 spaces quickly for me, so that’s fine, but it makes the texts in Live Preview look extremely ugly and unreadable, due to the   being displayed as regular text. :roll_eyes:

Whether it were displayed as 3 spaces (as you say, which would correspond to Live Preview), or whether the   would be highlighted as HTML code, the situation shouldn’t be what it is now, with   being displayed as regular text.

The situation is a lot worse, of course, when you simply need to insert a single non-breaking space between 2 words. You currently end up with a single merger of two separate words, with   inserted in between them in regular text, visually ruining both words in Live Preview, and ruining spellcheck, too.

Thank you. Can’t readily see non-breaking spaces there, although I guess it is there somewhere, but can’t be located quickly. So, it’s not really a solution, because pressing WIN+. and then searching for the non-breaking space in the pop-up menu is a lot slower than inserting   via the keyboard shortcut I have set up in Obsidian.

I strongly disagree, and I’m a linguist. Line-breaking control very frequently is an integral part of “serious writing”; for example, in quoting poetry, but in numerous other instances of regular text as well.

Bottom line: regular websites (such as WordPress) make it possible to control line breaks easily via  , so Obsidian Publish should make it possible as well. Which it already does, so that’s great, but the current implementation is visually distracting/ugly, so all we’re asking for, I guess, is for Obsidian to handle   better than it does now. :blush:

I’m not sure what I tried to convey but I mean if line break control is desired then it should implicate such serious writing to which Obsidian isn’t optimal or right tool to use. I’m saying that I would be surprised if they want to make Obsidian better tool for writers who already can use other better tools designed for serious writing. Obviously I’m going to make your upset by saying that :slightly_smiling_face:

Yes actually that has nothing to do with “support for non‑breaking space” and the core issue is about how live preview currently treats HTML entity references.

Obviously! :joy: I assure you that some of what I publish in Obsidian Publish is as “serious” as can be.

For example, I maintain my collection of literary quotations there. None of the writers I quote, alive or dead, would appreciate if their writing occurred in a mangled form anywhere on the Internet, regardless of the publishing platform. Line breaks are frequently irrelevant, but sometimes essential.

Yeah, we could rephrase this feature request or bug report as "the proper display of   in Live Preview", because the essential   itself, thankfully, is supported in Obsidian – just not displayed helpfully for you as you compose your note.

1 Like

Beautifully said, I give my respect to this! Let’s hope it will get official recognition by the developer team.

2 Likes