aboutsummaryrefslogblamecommitdiff
path: root/_plugins/add-anchor-to-header-from-header-id.rb
blob: 33e3ad7d83c8eb4a311947b46018714b889e25c9 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                  
                                                     


                                                           
                                                                                                                                                            


       
Jekyll::Hooks.register [:documents, :pages], :post_render do |doc|
  if doc.output_ext == ".html" && doc.type != :slides
    doc.output =
      doc.output.gsub(
        /<h([1-6])(.*?)id="([\w-]+)"(.*?)>(.*?)<\/h[1-6]>/,
        '<span class="header-anchor"><h\1\2id="\3"\4>\5</h\1><a href="#\3"><img class="simple-icon" src="/images/link.svg" aria-hidden="true" /></a></span>'
      )
  end
end