Don't auto-link URLs inside template delimiters

Continuing the discussion from Remove requirement to include https:// for urls:

I’ve written a shortcode that takes a URL as one of its parameters. However, MB turns this into the Markdown for a linked URL. That ends up failing inside the shortcode because it can’t correctly request the URL.

It seems like MB could detect that the URL is inside of {{< ... >}} delimiters and not touch the URL.

This shortcode works fine in my base Hugo install locally so I’m assuming from that and the message referenced above that this is something special that MB is doing.

Make sure you’re on Hugo 0.91 by going to Design → Hugo version. Then try posting using raw string parameters like this:

Hello, world! This is my blog post.

{{< yourshortcode `https://example.com` >}}
2 Likes

To the rescue again! Thank you.

I still think it would be smart to consider not auto-linking inside template/shortcode directives. Unless there’s a use case for it that I haven’t run into.

1 Like

Your help was the final piece to get this into the Plugin registry:

https://micro.blog/account/plugins/view/69

1 Like

Great! I think I’m going to update the auto-linking to skip URLs if they are quoted at all. Currently there are a few cases where it doesn’t try to auto-link them, such as if they are already in HTML or Markdown links, or if there are shortcode params like href="" it will also avoid linking it.

1 Like

Can we get an option to disable/remove the auto-linking, or at least to move the auto-linking to after storing the submitted post? I’m trying to figure out how to get the raw as-i-typed-it content and {{ .RawContent }} is returning [www.sscnet.ucla.edu/comm/mala...](http://www.sscnet.ucla.edu/comm/malamuth/pdf/00arsr11.pdf)\n instead of what I entered (just the URL). The original text that I typed in should be stored somewhere.

A preference would be a good idea for this and would some issues. Currently the auto-linking happens when you save a post and there’s no other way to get the un-linked text. What situation are you in that this is causing a problem? That would help me understand how to make it work.

1 Like

For me, it’s two things:

  1. I want my original data stored as-is. I don’t want to save a post and what gets saved isn’t what I put in when I clicked save. If I can’t trust that my data is saved, then I’m uncomfortable with using it as my primary data store.

  2. I am trying to lean in to this whole IndieWeb thing and mark up everything with the most accurate markup, and no CMS of any kind (micro- or macro-blog) will ever handle everything, so I’m looking for ways to re-parse my posts and add markup after the fact to the result. Right now I’m working on in-reply-to and repost-of (I’d prefer to link directly rather than repost… :wink:). My thought is to add a check in the custom theme “if the entire post is entirely a URL, then add repost-of“.

  3. Adding whatever it’s called that “Twitter cards” uses. I wouldn’t want to insert random junk for every hyperlink, but if a paragraph consists entirely of just a URL then putting in the rich preview would be useful.

That’s interesting. Yeah, in that case we would need a preference to skip any auto-linking of URLs (usernames are also linked).

I think there are probably other ways to do what you want, though. For example, you could have a “Reposts” category, and then check for that category in your template and process the link markup maybe with a regular expression. One disadvantage to just storing a URL and not Markdown/HTML is that the post would also need processing for RSS feeds.

1 Like

On (3), there are several open graph plug ins (and built in open graph stuff) that makes this way easier.

1 Like

Regular expressions: now you have two problems! :wink:

#2 ties in to #1: I don’t have to use M.B, which is exactly what makes M.B so valuable to me. So, in that vein, I want to keep the original content as original as possible. If I use categories to change the meaning of posts, that seems fragile and likely to disappear when changing themes or upgrading engines or moving to a different host.

Front Matter would change the calculus here as that would allow first-class metadata!