Last active
December 27, 2021 17:54
-
-
Save trestles/5ce272b60a20bb3ea5a2fcad117554db to your computer and use it in GitHub Desktop.
This file contains hidden or 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
=begin | |
doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML | |
<style>.emphasized { font-weight: bold } </style> | |
<h1>Three's Company</h1> | |
<div class='something'><strong>A love triangle.</strong></div> | |
<h1>other things</h1> | |
<style>.more-bold { font-weight: bold }</style> | |
EOHTML | |
does this make sense | |
=end | |
doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML | |
<body> | |
<style>.emphasized { font-weight: bold } </style> | |
<h1>Three's Company</h1> | |
<div class='something'><strong>A love triangle.</strong></div> | |
<h1>other things</h1> | |
<style>.more-bold { font-weight: bold }</style> | |
</body> | |
EOHTML | |
divs = doc.css 'div' | |
divs.each { |d| d.name = 'p' } | |
divs.each { |div| p.attributes.each { |a| a.map(&:remove) } } | |
styles = doc.css 'style' | |
styles.each { |s| s.content.remove } | |
styles.map(&:remove) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment