Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement