I just started using Hugo a couple days ago so I’m still getting familiar with everything. Anyways, I have some markdown files, which get converted to HTML just fine using Hugo. The headers in the markdown files get surrounded by <h2> tags and the paragraphs get surrounded by
tags. However, I was wondering if it would be possible to, when generating the HTML files, surround each paragraph with the tags (i.e. the <h2> tag and all <p> tags underneath this current header would get surrounded by a block). I would also like to be able to set the id of the section to be equal to the id of the <h2> tag.
I’ve been trying to figure out a way to do this using regular expressions but I think it might not be possible that way. Here’s a little funky regex I came up with, but it wouldn’t work because it ends up skipping every other paragraph since I have to somehow capture the next <h2> tag to know when this paragraph ends.
@shsh This sounds like one of those cases where we need you to back up and explain why you want this. Unless you use HTML (.html) instead of Markdown (.md) for your content files, I think you’d need to use shortcodes, but if we know what you are after, we might know of another way to achieve what you want.
Speaking of shortcodes, have you read up on how to create them?
So I’m using the Hugo Codex theme and it has a table-of-contents.js file that should ideally show you your location in the document through the table of contents sidebar. However, the way it is currently set up, it shows your position based on the currently visible headers on screen. This seems to work fairly well in most cases, but if you have a section with a very large body, it doesn’t accurately show your position in the table of contents anymore, until you scroll down enough to reach the next header.
To make this functionality work, I was thinking of enclosing each section of the article in tags so that the script will be able to know when an entire section is visible or not, rather than just the header.
Maybe there’s a way to alter the javascript to make this work as well, but I couldn’t figure that out either.