I have a string:
<ul>
<li><a href="/<%= @home %>/">welcome</a></li>
</ul>
I'm using Nokogiri to grab the href
properties of all its a
tags and build an array of hashes. I am expecting:
[{
:href => "/#{ @home }/",
:title => "welcome"
}]
I tried this script:
doc = Nokogiri::HTML(open(file))
menu = []
doc.css('a').each do |item|
menu.push({
:href => item[:href].gsub(/<%=(.*)%-?>/, "#{\1}"),
:title => item.text
})
end
The resulting string is automatically escaped; notice the extra backslash before the hash sign:
[{
:href => "/#{ @home }/",
:title => "welcome"
}]
I can't figure out why. Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…