Improving copy-paste into Marknote

I’ve been using Marknote for a while and think it has a lot of potential, so thought I’d look into a few issues to help. I’m not sure if Marknote developers hang out here much, but thought I’d try.

One issue I’m looking at is that when I copy text from LibreOffice and paste into Marknote, it preserves style from LibreOffice that is not supported by Marknote (often by Markdown generally). So, for example, take the following in LibreOffice:

I’ve set a custom font here too that isn’t so obvious. I copy and paste that into Marknote and it looks like this (note font is different from the surrounds, and one can’t usually format text like this in Marknote):

If I navigate away from the note and back again, it now looks like this:

The final format is fine, that’s what one would expect (besides the funny character at the end: that’s another issue). Ideally it would just look correct from the outset though.

Now, LibreOffice actually puts a bunch of MIME types on the clipboard when copying:

$ wl-paste --list-types
application/x-openoffice-embed-source-xml;windows_formatname="Star Embed Source (XML)"
text/rtf
text/richtext
text/html
text/markdown
text/plain;charset=utf-16
application/x-openoffice-link;windows_formatname="Link"
application/x-openoffice-objectdescriptor-xml;windows_formatname="Star Object Descriptor (XML)";classname="8BC6B165-B1B2-4EDD-aa47-dae2ee689dd6";typename="LibreOffice 26.2 Text Document";displayname="file:///home/lawrence/Documents/example.odt";viewaspect="1";width="17000";height="3000";posx="0";posy="0"
text/plain;charset=utf-8
text/plain

Marknote prioritises text/html over text/markdown (in rich_documenthandler.cpp, pasteFromClipboard()). That’s easy enough to switch, I tried, it works, but actually it’s not without it’s own complications, because in this case LibreOffice is not preserving all the formatting in the Markdown when putting it on the clipboard!

$ wl-paste --type text/markdown
Lorem **ipsum** *dolor* sit amet.

Note the underline has disappeared (there is no standard underline in Markdown I believe), vs the HTML, which preserves it, but also includes a bunch of style, which is where the different font is coming from:

$ wl-paste --type text/html
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title></title>
        <meta name="generator" content="LibreOffice 26.2.5.2 (Linux)"/>
        <style type="text/css">
                @page { size: 21cm 29.7cm; margin: 2cm }
                p { margin-bottom: 0.25cm; line-height: 115%; background: transparent }
                a:link { color: #000080; text-decoration: underline }
                a:visited { color: #800000; text-decoration: underline }
        </style>
</head>
<body lang="en-GB" link="#000080" vlink="#800000" dir="ltr"><p style="line-height: 100%; margin-bottom: 0cm">
<font face="Noto Serif, serif">Lorem <b>ipsum</b> <i>dolor</i> <u>sit</u>
amet.</font></p>
</body>
</html>

I have some approaches to improve the situation, but wanted to run them by developers:

  1. When pasting, it’s very easy to prioritise text/markdown over text/html when available on the clipboard, just swapping a couple of lines. The downside is that some formatting may be lost, as in the underline in this case.
  2. Generally, when pasting any text/html, one could preprocess the HTML to remove style information: <style> tags and perhaps style attributes. I think it would mop up a lot of cases. I was thinking to use QXmlStreamReader to try that and see how it goes.

There are so many apps called “Marknote”; since you’re posting here I presume it’s the KDE Marknote (Marknote - KDE Applications).

I can’t find it mentioned anywhere, but does Ctrl+Shift+V paste the text without formatting? It does in a lot of other apps.

Yes, this is about the KDE app Marknote.

It does not have a Ctrl+Shift+V, no. Somewhat related, this ticket suggests that after copying plain text that is formatted as Markdown, someone may want a “paste as Markdown” option, too.

Try my hacky solution that gives you the Ctrl+Shift+v option.

Sure, I can see how that forces a plain text paste. But, in case it’s not so clear, I’m offering to contribute a little code to Marknote to tidy this up a bit, just want to run the proposed approach past developers first.

In case you’re interested in contributing to Marknote yourself, the relevant code seems to be rich_documentandler.cpp:1041. There’s a function pasteFromClipboard() that gets called on Ctrl+V, and I’m suggesting to add some additional logic there for when text/html or text/markdown appears on the clipboard. But you could create a similar function that gets called on Ctrl+Shift+V that always takes the text/plain data from the clipboard, regardless of what else is there. What your workaround does is basically delete all the other MIME types on the clipboard, so that there is only text/plain, and pasteFromClipboard() will use that (similar for other apps, presumably).

Right, now I understand. In that case a baked in approach rather than a hacky one would be much better, but I believe there were some roadblocks on the Wayland end that prevents this happening (sorry I can’t find a reference for this).