Is there a way to extract hardcoded styles in html documents to external css file ? If not, do you have an idea on how to do this? Have you ever done it before ?
Example, from:
<div style="background-color: red">
<a style="font-weight: bold"></a>
</div>
to
<div id='st-01'>
<a id='st-02'><a/>
</div>
#st-01 { background-color: red }
#st-02 { font-weight: bold }
asked Aug 3, 2013 at 11:46
Alex
2,0764 gold badges22 silver badges32 bronze badges
2 Answers 2
Not exactly what you are looking for but if you don't mind copying and pasting your HTML, try this. Not too many features but it does the job!
answered Aug 3, 2013 at 12:01
Christopher
62011 silver badges34 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use some JS/JQuery code to extract the styles, clear them, give elements an ID and add up css. Check this example, you may extend it further.
$(document).ready(function(){
var i = 0;
var css = "";
$("div,a").each(function(){
$(this).attr("id","st-"+i);
css += "#"+$(this).attr("id")+"{"+$(this).attr("style")+"}";
$(this).removeAttr("style");
i++;
});
$("style").html(css);
});
answered Aug 3, 2013 at 12:09
Khaled
8,63311 gold badges41 silver badges59 bronze badges
Comments
default