HUGO

Get line number from raw file

Kia ora!

I’m writing a documentation theme and would like to add links from headings in my document to specific lines in Github, so that the page is most easily accessible.

The format is this is simply achieved by adding #L23on the end of a Github URL.

Is there a way I can access the line number in Hugo? For example, in the render-heading.html hook template?

Thanks for your help :slight_smile:

# [bla](https://somewhere.com#L456)

Maybe I misunderstand what you want to achieve, maybe your theme is removing the markdown from headings. I would do it with markdown and fix the template file.

If not, then (ab)use the title of the markdown header and indeed use a render heading hook, parse the title somehow and build your link. But this probably will end up ALL your headings if you don’t have it set up for only one single post type.

# A markdown title ###L123

Then take .Title, and split it.

{{ $newTitle := split .Title "###" }}
{{ index $newTitle 0 }} <-- A markdown title
{{ index $newTitle 1 }} <-- L123

Hacky, I know.

Helped me, thx :slightly_smiling_face: