obsidian-advanced-paste icon indicating copy to clipboard operation
obsidian-advanced-paste copied to clipboard

Remove links pasting

Open Andrea-28-03 opened this issue 2 years ago • 5 comments

Hi, I use perplexity and it makes citations that when i normally copy and paste them on obsidian they breake and make a lot of blanks lines, image image image image image

Smart join is incredible but it delete all the links and tabulations. Is there a way to fix it also with an custom trasform it would be really usefull It does this only with that site and can't understand why...

Andrea-28-03 avatar Nov 04 '23 15:11 Andrea-28-03

Smart join is incredible but it delete all the links and tabulations.

Because smart join operates in pure text mode. And it is (almost) intended for pasting from PDF.

Is there a way to fix it also with an custom trasform it would be really usefull

Yes, a custom transform could do it.

From the picture you provided, It seems that there are spaces and newlines inside markdown links. I checked it and it looks like a bug in turndown.

So if you want to write a custom transform to do the task, note that remark will produce a bad syntax tree because of it. Of course you can also use regex instead of remark to avoid it.

kxxt avatar Nov 05 '23 00:11 kxxt

The following script might helps. It uses a simple regex.

export async function stripWhiteSpacesInLinks(input, { turndown }) {
  if (input.types.includes("text/html")) {
    const html = await input.getType("text/html");
    const md = turndown.turndown(await html.text());
    return md.replace(/\[\n*(.*)\n*\]\((.*)\)/gm, "[$1]($2)");
  }
  return { kind: "err", value: "No html found in clipboard!" };
}
stripWhiteSpacesInLinks.type = "blob";

kxxt avatar Nov 05 '23 01:11 kxxt

No, I tried it, it works exactly like the normal copy and paste. I think it can't find the link... image

I tried some different replacement or founding methods, but them didn't change anything

export async function fanculo(input, { turndown }) {
  if (input.types.includes("text/html")) {
    const html = await input.getType("text/html");
    const md = turndown.turndown(await html.text());
    return md.replace(/\[\n*(.*)\n*\]\(html:\\(.*)\)/sgu, " [$1]($2)");
    /*return md.replace(/\[.*(\d+).*\].*?\(html:\\(.*?)\)/gms, function (match, text, url) {
      // Personalizza la formattazione dei link come desiderato
      return ` [${text}](${url})`;*/
    }

  return {kind: "err", value: "No html found in clipboard!"};
}
fanculo.type = "blob";

Andrea-28-03 avatar Nov 05 '23 11:11 Andrea-28-03

The script works for me.

Peek 2023-11-05 19-28

It seems I can't expect this bug to be fixed on turndown's side: https://github.com/mixmark-io/turndown/pull/419

When I get more time I will fix it in the default paste command, maybe by maintaining a fork of turndown.

kxxt avatar Nov 05 '23 11:11 kxxt

You are right, using perplexity from the official website and then pasting it with your script does work, really great. But from the custom frame of perplexity it doesn't, it would be great if you knew a workaround about that, but it is ok also like that, thanks

Andrea-28-03 avatar Nov 05 '23 13:11 Andrea-28-03