Created
November 30, 2009 16:55
-
-
Save mironov/245549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
span_trans = lambda do |el| | |
if el[:node].name == "span" | |
if el[:node].has_attribute?("style") | |
rules = el[:node].attribute("style").value.split(";") | |
new_rules = rules.map do |rule| | |
rule.match(/text-decoration:\s*(underline|overline|line-through)\b/) || | |
rule.match(/font-weight:\s*bold\b/) || | |
rule.match(/font-style:\s*italic\b/) | |
end | |
new_style = new_rules.compact.map{|r| r.to_s}.join("; ") | |
end | |
if new_style == "" || !el[:node].has_attribute?("style") | |
el[:node].children.each { |n| el[:node].add_previous_sibling(n) } | |
el[:node].unlink | |
end | |
end | |
{:node => el[:node]} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, I'm not seeing where the
new_style
is being added back to the node, am I missing something?