Thank you so much for Hugo. I love how fast it is and how it allows me to use Go in more places.
I’m attempting to add the ability for titles within my generated pages to be linked to. Before stumbling upon the BlackFriday extension that will do this for me automatically, I was attempting to accomplish this using replaceRE in my template:
This did not do what I was hoping for and instead resulted in {{My Title | anchorize}} being rendered as the title instead.
I will be changing my approach to allow BlackFriday to do this for me, but I’m curious if this approach could be made to work. It might be a useful tool to have in my toolbelt going forward.
May be you just need to change $1 (and so on) to ${1}? I know for fact that this works
(because it looks like you are doing something similar Looks like you are doing something else … not sure why you are inserting the id, because Hugo/Blackfriday is already doing that for you)
You’re right, @kaushalmodi, BlackFriday will indeed generate the ids for me automatically. I was trying to do this myself as I was confused at the time as I shot myself in the foot with a custom shortcode. I realize now that I don’t get the benefits of BlackFriday while in a shortcode. It makes perfect sense now that @maikihelped me through it.
With that said, I’m still curious if it’s possible to do what I was trying to do. The regex works fine and I’m able to print the captured group perfectly fine. What I’m not sure is feasible or not is to perform some functions on $1 or if I’m limited to straight up insertion into the replacement string. I played with it some more and thought maybe something like this would work:
I think it’s not possible to do what you want in exactly the same manner. But you can “extract” each subgroup into a different var and work on that … (below is not tested … but you will get the idea):