How do I reference subheadings and anchors of each subheading?

Hi all!
Say I have a subheading and anchor as such:

/* ## Text {#anchor} */

in the html layout, I want to pass each h2 heading as well as each #anchor as an attribute so for example

<a href = “##text” class="#anchor

How do I get the /##Text/ and /#anchor/ as variables ?

I’m not familiar with that markup; where are you putting that?

Ref: Links and cross references | Hugo