Smart Paste to parse and modify pasted text

Provide a smart paste command to automatically convert pasted links or text based on user-provided regexps or callbacks.

Use Cases

Videos

Turn links of the form https://www.youtube.com/watch?v... automatically into {{video ...}}.
Add date/title/channel as attributes to block.

Map links

Recognize links to maps and extract the location. For example, the link
https://www.google.com/maps/place/The+White+House/@38.8979696,-77.0367791,17z/data=!3m1!5s0x89b7b7bce13fc169:0xb825fceceddb4d3c!4m8!1m2!3m1!2sThe+White+House!3m4!1s0x89b7b7bcdecbb1df:0x715969d86d0b76bf!8m2!3d38.8976763!4d-77.0365298
should be turned into this block that has the location as an attribute (use case is to create maps of Logseq entries):

# The White House
location:: (38.8979696,-77.0367791)
[Google Maps]([linkurl](https://www.google.com/maps/place/The+White+House/@38.8979696,-77.0367791,17z/data=!3m1!5s0x89b7b7bce13fc169:0xb825fceceddb4d3c!4m8!1m2!3m1!2sThe+White+House!3m4!1s0x89b7b7bcdecbb1df:0x715969d86d0b76bf!8m2!3d38.8976763!4d-77.0365298))
... screenshot of the maps link as an offline image ...

Book links

Recognize links to google books etc.

Text blocks

Convert BibTeX entries into blocks with attributes.

Implementation

  • User provides regex and a Markdown template with placeholders that will be expanded, e.g. https:\/\/www\.google\.com\/maps\/place\/(?<place>[\w+]+)\/@(?<lat>\d+\.\d+),(?<lon>-?\d+\.\d+), #<place>\nlocation::(<lat>,<lon>)
  • For more complex webpages, allow user-defined callback functions that can download the webpage, create attachments etc. For example, this function could store a screenshot of a google maps page or create block for a book including author, title and cover image.