Skip to content

Commit

Permalink
Allow jumping to anchors with MediaWiki-style underscores
Browse files Browse the repository at this point in the history
Hugo turns whitespace in headers into "-", whereas MediaWiki converts
whitespace to "_". Generate a second id to cover both.
  • Loading branch information
neobrain committed Sep 27, 2024
1 parent d3e1941 commit cddbdd0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions layouts/_default/_markup/render-heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- .Anchor will turn whitespace in header names to "-", but mediawiki uses "_". Attach a second id with "-" changed to "_" here to make both work. -->
<span id="{{ replace (.Anchor | safeURL) "-" "_" }}">
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{ .Text | safeHTML }}
<a class="anchor" href="#{{ .Anchor | safeURL }}">#</a>
</h{{ .Level }}>
</span>

0 comments on commit cddbdd0

Please sign in to comment.