Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Call the partial in my `layouts/post/single.html` template like
- ```
- {{ partial "header-link.html" .Content }}
- ```
- The partial is defined as
- ```
- {{ . | replaceRE "(<h[2] id=\"([^\"]+)\">)(.+)(</h[2]+>)" `${1}<a class="header-icon-link" href="#${2}"><i data-feather="link"></i></a> ${3}${4}` | safeHTML }}
- ```
- Which will take take html like this
- ```
- <h2 id="text">Text</h2>
- ```
- And convert it to this
- ```
- <h2 id="text"><a class="header-icon-link" href="#text"><i data-feather="link"></i></a> Text</h2>
- ```
- Then feather.js will convert `<i data-feather="link"></i>` to an svg icon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement