Clipboard: Special requirements

Hello again,

all the best for 2024 and happy coding!

I do a lot of research on the Internet and have collections with thousands of links.
I would like to manage these with TiddlyDesktop in the future.

Using an browser add-on, I can save the links to the clipboard with the following structure:
TITLE[CR][LF]
URL

Example (I replaced ‘h’ from https with ‘x’ due to the two link rectriction for new users):
TiddlyDesktop: TiddlyWiki — a non-linear personal web notebook
xttps://tiddlywiki.com/static/TiddlyDesktop.html

If I now paste the clipboard into a wiki, [CR][LF] are ignored and I get everything in one line with a space:
TiddlyDesktop: TiddlyWiki — a non-linear personal web notebook xttps://tiddlywiki.com/static/TiddlyDesktop.html

Now looking for a (simple) way how I can automatically change the content of the clipboard before pasting.

The most flexible solution would of course be events that are triggered when the clipboard is accessed, like:
GitHub - sudhakar3697/node-clipboard-event: Clipboard change event for Node.js/Electron.js/NW.js

Many thanks and greeting
FoxTheTiddler

1 Like

I’m not sure how you’re pasting here. Are you pasting into the text edit box for a tiddler? If so, then it should preserve the CRLF, in its text form. So you’ll see it correctly inside the edit box. But when you save, and your view is rendered to HTML, then extra whitespace, including CRs and LFs and compressed into single spaces for viewing. That’s how HTML works. If you were to set the type of the tiddler to text/plain. then you should see the line-breaks rendered.

If you’re just pasting to the root of the wiki, then you will likely get one import called Untitled text/plain, and possibly others with other clipboard metadata. I’m not sure what you would do with them.

You could create some sort of Dropzone that can parse this simple format and store the results where you wanted, but I think we’d need to know more about what you’re trying to do.

I would hazard a guess that the cr/lf is being cleared out by your extension. When I try copying and pasting with the standard copy option or copycat (an extension), the linefeeds are retained. What add-on are you using?

I have two extensions for cloud services that I never use exactly because they throw away the line feeds. So it seems to be a common extension problem.

If you were using the browser instead of TD, you could use tiddlyclip, which knows how to grab the title and url and let’s you format the output as you want.

There is a TW browser-addOn + a TW plugin that, in combination, should work as expected.

See: TiddlyClip — Project Documentation

First of all thanks for the answers!

Some additional infos:

  1. I paste into the text edit box (Type: content type).
  2. [CR][LF] are not cleaned out, otherwise multiline pasting in an standard app wouldn’t work.
  3. Same behaviour with any multiline text.

Summarized, the text should be modified with the <br />-tag just before inserting:
TITLE<br />[CR][LF]
URL

BTW, when I copy the text in non-edit mode the <br />-tag is correctly removed.

If the new line is visible in the editor but not in view mode, this is standard wiki behaviour. It wraps sentences up into paragraphs. This is frustrating until you come to terms with it.

However in your case we need to ask what are you going to do with this link once it is pasted into your tiddlers?

  • I have created a browser bookmarklet to capture address links as a html a record, with target and more set. When I past this into my tiddlers it becomes a full html link.
  • Perhaps the behaviour you want is [[TITLE|URL]] ?
  • Have a look at the markdown plugin. On mark down tiddlers pasing the url may result in [title](url) like here in talk.tiddlywiki.com
  • In another case when I drop a link on a tiddler dropzone it places it in a fieldname…

You are capturing with browser add-on and pasting as text content from clipboard into a tiddler. Accessing and changing clipboard contents is a OS security issue today. There are other ways:

  • You could use a different browser add-on like TiddlyClip as suggested.

  • If you don’t mind using a bookmarklet (Bookmarklet - Wikipedia), here’s a simple one to do what you requested:

javascript: (function () { navigator.clipboard.writeText( document.title + "<br>" + window.location.href + "<br>" ) .then(() => {}) .catch(() => {alert("unable to copy to clipboard");});})();

The javascript string being copied to the clipboard is document.title + "<br>" + window.location.href + "<br>" where title=document.title and url=window.location.href. You get the idea.

A little more fancy is document.title + "<br>" + window.location.href + "<br>" + window.getSelection().toString() where window.getSelection().toString() = optional text you select in the web site before invoking the bookmarklet.

Or "[[" + document.title + "|" + window.location.href + "]]" to paste as [[TITLE|URL]].

  • Another alternative is to change the clipboard content after pasting. You use a dropzone or even a text input box to capture the text string, and do what you need using Wikitext, such as to create a tiddler.

Thanks @jacng for sharing for @FoxTheTiddler

  • Doesa this assume you want to copy the address in the browser address bar, rather than a link in the content?
  • For ikis we can set Settings > Tiddlywiki " Navigation Address Bar" to get the current tiddler “Include the target tiddler”

I just want to say I have had a lot of success getting ChatGPT to write the javascript functions for bookmarklets. If first you give ChatGPT an existing bookmarklet that installs tiddlers (Silently) it can even produce those as well.

Yes, the assumption is the Bookmarklet is capturing the web address of the web site currently visiting, not extracting a html link from the web contents. Done that often in my own web research.

we can set Settings > Tiddlywiki " Navigation Address Bar" to get the current tiddler “Include the target tiddler”

Now you lose me. This is for the case when the web site being captured is a TW showing a tiddler ?

Yes

  • It can be a common need of tiddlywiki users, including to tiddlywiki.com
  • Then you can use the same method we have discussed here to capture that link from the address bar.
  • However I have built my own button for tiddlers and wikis to copy any address as a html a record. Not just a permalink.
1 Like