obsidian-auto-link-title icon indicating copy to clipboard operation
obsidian-auto-link-title copied to clipboard

[Feature Request] Arbitrary post-processing of title

Open huyz opened this issue 4 years ago • 7 comments

It would cool if there were a setting which consisted of a JavaScript code-block that would allow us to post-process the title before it's pasted into the document. This is useful for GitHub link titles which are long and have too much information for my taste.

So a setting that would allow me to define a hook like the following:

(url, title) => {
  if (/github\.com/.test(url)) {
    return title.replace(/^GitHub - ([^:]+):.*/, '$1');
  }
  return title;
}

huyz avatar Oct 08 '21 15:10 huyz

If arbitrary code execution is too much, people can do a great deal with regexes only.

NomarCub avatar Jan 22 '22 12:01 NomarCub

+1 - adding a configurable map of URL regex to a templated title would be great for customization

danyim avatar Sep 19 '23 18:09 danyim

Is there any progress on this? I saw there was a new release. Also, this pull request seemed related, and was closed without elaboration: https://github.com/zolrath/obsidian-auto-link-title/issues/98. There are more requests related to this (https://github.com/zolrath/obsidian-auto-link-title/issues/70, https://github.com/zolrath/obsidian-auto-link-title/issues/34, https://github.com/zolrath/obsidian-auto-link-title/issues/80, https://github.com/zolrath/obsidian-auto-link-title/issues/84, https://github.com/zolrath/obsidian-auto-link-title/issues/86). A lot could be solved with simple {{template}} and regex replacements.

NomarCub avatar Jan 04 '24 18:01 NomarCub

Can you provide me with some other examples of how you'd use this feature? I've got a WIP branch with a GUI asking for a domain, a regex to test against, and the replacement regex: image but would like a few more examples of how you'd intend to use it before I commit to that method.

zolrath avatar Jan 05 '24 00:01 zolrath

For example,

  • I'd use this for GitHub:
    • GitHub - [\w\d_]*/(.*) -> $1
    • would make this repo's link title GitHub - zolrath/obsidian-auto-link-title: Automatically fetch the titles of pasted links -> obsidian-auto-link-title: Automatically fetch the titles of pasted links
    • come to think of it multiple regexes for one domain might come in handy
  • this for Wikipedia: - Wikipedia -> | Wikipedia, so this goes Blue jay - Wikipedia -> Blue jay | Wikipedia

But that's just off the top of my head. There are also some sites that have a lot of cruft in their titles. Regexes could also be a workaround for #22 to make the resulting titles now less ugly.

NomarCub avatar Jan 05 '24 18:01 NomarCub

Hi! i would really like this feature! Are you still working on it, or can i create a pull request finishing the implementation in the other branch?

KraXen72 avatar Apr 20 '24 15:04 KraXen72

Hi! i would really like this feature! Are you still working on it, or can i create a pull request finishing the implementation in the other branch?

Hello! I've been pulled into a work project for the last bit, if you'd like to complete the feature I'd gladly accept a pull request!

zolrath avatar May 03 '24 04:05 zolrath