Skip to content
This repository has been archived by the owner on Aug 6, 2024. It is now read-only.

Remove links pasting #15

Open
Andrea-28-03 opened this issue Nov 4, 2023 · 5 comments
Open

Remove links pasting #15

Andrea-28-03 opened this issue Nov 4, 2023 · 5 comments

Comments

@Andrea-28-03
Copy link

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

@kxxt
Copy link
Owner

kxxt commented Nov 5, 2023

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
Copy link
Owner

kxxt commented Nov 5, 2023

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";

@Andrea-28-03
Copy link
Author

Andrea-28-03 commented Nov 5, 2023

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";

@kxxt
Copy link
Owner

kxxt commented Nov 5, 2023

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: mixmark-io/turndown#419

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

@Andrea-28-03
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants