SHARE
TWEET

Untitled

a guest Apr 20th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Took me a bit to wrap my head around the regex and capturing groups. It’s powerful once I understood it. Here is my adapted solution.
  2.  
  3. Call the partial in my `layouts/post/single.html` template like
  4.  
  5. ```
  6. {{ partial "header-link.html" .Content }}
  7. ```
  8.  
  9. The partial is defined as
  10.  
  11. ```
  12. {{ . | replaceRE "(<h[2] id=\"([^\"]+)\">)(.+)(</h[2]+>)" `${1}<a class="header-icon-link" href="#${2}"><i data-feather="link"></i></a> ${3}${4}` | safeHTML }}
  13. ```
  14.  
  15. Which will take take html like this
  16.  
  17. ```
  18. <h2 id="text">Text</h2>
  19. ```
  20.  
  21. And convert it to this
  22.  
  23. ```
  24. <h2 id="text"><a class="header-icon-link" href="#text"><i data-feather="link"></i></a> Text</h2>
  25. ```
  26.  
  27. Then feather.js will convert `<i data-feather="link"></i>` to an svg icon
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top