No empty line between headings/text in clipboard text/plain when copying from reading view

Steps to reproduce

1. Create a note containing the following:

## Heading test

Test Text

2. Switch to reading view
3. Highlight all of the note text | right click | copy
4. Paste the text into an application that only accepts plaintext (e.g. notepad)

Did you follow the troubleshooting guide? [Y/N]

Yes

Expected result

The plaintext that’s copied to the clipboard (text/plain) should have an empty line between the Heading and the text below it (as in the source markdown example), e.g:

Heading test

Test Text

Actual result

In the clipboard (text/plain), there is no empty line between the heading and the text, so what gets pasted is:

Heading test
Test Text

Environment

SYSTEM INFO:
Obsidian version: v1.8.10
Installer version: v1.8.10
Operating system: Windows 11 Pro 10.0.26100
Login status: logged in
Language: en
Catalyst license: insider
Insider build toggle: off
Live preview: on
Base theme: adapt to system
Community theme: none
Snippets enabled: 0
Restricted mode: on

RECOMMENDATIONS:
none


Additional information

This only happens with headings. If your note had bold text instead of a heading, e.g:

**Bold Text**

Test Text

you see the empty line between as expected in the clipboard text/plain

EDIT: The same behavior also happens with code blocks

This is not a bug. This is how markdown works.

You should not expect spaces or blank lines to be maintained between Source Mode and Reading Mode.

I’m aware of how markdown works (and the reading mode display already works as expected, this issue is just about what’s copied to the clipboard from reading mode).

I’m not expecting “extra” blank lines to be maintained. i.e. I’m aware that 1 (or more) blank lines equals just a paragraph in markdown… so extra whitespace beyond a single blank like won’t be maintained.

This isn’t about a difference between source mode and reading mode. In my previous example there’s just a single blank line (markdown paragraph), so there isn’t any visible difference between source and reading mode.

The problem is the text/plain in the clipboard when copying from reading mode. Plaintext has no concept of paragraphs, so any markdown paragraphs should be converted to “empty lines” in the text/plain in the clipboard. This does work as expected for the most part… just not with Headings or Code blocks.

For example, I have the following markdown:

test.md (1.5 KB)

Here’s how it looks in reading mode, where there is empty space (paragraphs) between the headings and text (and code blocks and text) as expected:

However, if you copy the text from reading mode to clipboard and then paste as plaintext, this is what you get:

Where there is no space between headings and text or code blocks and text.

NOTE: If I open the same markdown in another markdown editor (Typora), copy to clipboard from Typora, and then paste as plaintext, it works as I’d expect:

NOTE: Copying from the editor (instead of reading mode) would obviously retain the empty lines when pasting as plaintext, but the reason I don’t copy from editing mode is that I want the plaintext without the markdown formatting characters in the clipboard- I sometimes need to copy text from Obsidian to places that don’t support HTML formatting or Markdown.

I double checked our reference markdown implementation (commonmark).
There is no difference in the HTML output between

# title
text

and

# title

text

There is no extra paragraph added.

Obsidian is the same.

vivaldi_hE9yfP88H0

I’m not expecting an extra paragraph to be displayed in reading mode (markdown never displays “extra” whitespace and I understand that’s expected markdown behavior).

Rather, my expectation is that anything that’s displayed as a paragraph in reading mode should be converted to an empty line in the plaintext that’s copied to the clipboard

in your example, reading mode does seem to render a paragraph below headings without needing to manually add an empty line below the heading (which is fine, I’m not expecting an extra paragraph to be rendered- my example only had an empty line below the heading because I didn’t realize that it defaults to rendering a paragraph below headings without needing to manually add one).

My expectation is that (since the reading mode does render a paragraph between the heading and the text in either case), if I copied that text from reading mode and pasted as plain text, I would get:

title 1

text

That said, it might be possible that this is something obsidian doesn’t have control over:

I noticed that if I export the note to HTML with pandoc and then copy the text from Google Chrome it has the exact same behavior as copying from Obsidian reading mode (no space between headings/text)… but if I open the same HTML file in Firefox and copy the text from Firefox, the clipboard text/plain includes empty lines between headings and text as I’d expect… so it seems like this might be a chromium/electron issue with how the plaintext is extracted from the rendered HTML rather than anything specific to Obsidian.

The reading mode doesn’t “render a paragraph”, that’s just space padding added to the title line via CSS.

For comparison, what happens if you copy a similar piece of text from a website in a browser (which is what reading view essentially is)? I know I sometimes experience quirks when I do that; I don’t remember if this is one of them.

@CawlinTeffid yeah based on the pandoc test from my previous post (I exported the obsidian note to HTML with pandoc, opened the HTML file in Chrome, and then copied the text from Chrome), I’m thinking that this is a chromium/electron thing, because the same behavior occurs when copying from Chrome.

If I copy from Typora (with the typora preference for “copy markdown source as plaintext” disabled) it works as I’d expect- the text/plain in the clipboard always has an empty line below headings, even if there’s no empty line below the heading in the source markdown

But Typora doesn’t have a “reading view” and I suspect that it’s using some kind of custom solution to populate the text/plain in the clipboard rather than relying on default electron/chromium behavior.

Wow, somehow I missed that part of the post. Sorry for suggesting a thing you already did!