Markdown Link Generator
When viewing any page on the internet, if you click this bookmark, it will pull the page's title and URL and create a markdown link which you can paste into a bearblog post.
- Copy the code below
- Create a bookmark with the name 'MD Link' (or whatever you want) and PASTE the below code into the "URL" field.
- Replace
YOUR_USERNAMEso that links to your own blog do not contain| YourBlog's Blog. For mine, it looks like"| ReedyBear's Blog";
The Code
javascript:
remove_end = "| YOUR_USERNAME's Blog";
url = window.location.href;
title = document.querySelector("title") /* select the <title>Page Title</title> */
.textContent /* Get just the "Page Title" part */
.trim() /* Remove any spaces around the title */
.replace(/<[^>]*>?/gm, ''); /* Remove HTML tags. See https://stackoverflow.com/a/822464 */
split_title = title.split(remove_end);
if (split_title.pop() == '')title = split_title.join("").trim();
md_link = "["+title +"]("+url+")";
navigator.clipboard.writeText(md_link);
Explanation of Regex
Regex is a special language for matching text. This is an explanation of the regex /<[^>]*>?/gm, used in the code above:
/ # Starts a regex, is not part of the regex
< # Find a less-than character
[^>] # Find the next character if it is NOT a greater-than character
* # Do the last step zero or more times
> # Find the next character if it is a greater-than character
? # The previous character (>) is optional & does not have to be present
/ # Ends a regex, is not part of the regex
gm # configurations that tell the regex engine how to parse.
# I believe g is "global" and m is "multiline" but idr how they work