Created
June 26, 2012 01:55
-
-
Save yamitake/2992689 to your computer and use it in GitHub Desktop.
htmlの要素からlessのスケルトンを作成
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
| 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