I'd like to find headings and give them an id
attribute. For example, I might want to add id="my-new-id"
to <h2>
or something like <h2 class="class-1 class-2">
. The parser method looks like this:
def parse_toc(text)
p = []
text.split("\n").each do |line|
if line.match(/\<h2.*?\>/)
# need to add id
end
p.push line
end
return p.join("\n")
end
I have trouble keeping wildcards as part of the string. How can I keep a wildcard in a string while changing what surrounds it?