Skip to content

Instantly share code, notes, and snippets.

@yamitake
Created June 26, 2012 01:55
Show Gist options
  • Select an option

  • Save yamitake/2992689 to your computer and use it in GitHub Desktop.

Select an option

Save yamitake/2992689 to your computer and use it in GitHub Desktop.
htmlの要素からlessのスケルトンを作成
var result = "";
var depth = 0;
function dive(elem){
result += indent(depth) + (elem.get(0).tagName.toLowerCase() + "{\n");
//idが会ったら
var id = elem.get(0).id;
if(id){
console.log("id aru");
result += indent(depth + 1) + "&#" + id + "{}\n";
}
console.log(elem.get(0).tagName.toLowerCase());
elem.children().each(function(){
depth++;
dive($(this));
depth--;
});
result += indent(depth) + "}\n";
}
function indent(depth){
var tab = "";
for(var i = 0; i < depth; i++){
tab += " ";
}
return tab;
}
dive($("header"));//要素を指定
alert(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment