mayaaファイルひな形生成

mayaaファイル作るのが面倒なので、HTMLのIDを抽出してmayaaのひな形を作るbookmarkletを作ってみた。firefoxでしか動かないみたいだけど。

javascript:(function(){var ids=new Object();function traverse(node){var nodes=node.childNodes;if(node.nodeType==1){attributes=node.attributes;for(var i=0;i<attributes.length;i++){if(attributes[i].name==%22id%22){ids[attributes[i].value]=attributes[i].value;}}}for(var i=0;i<nodes.length;i++){traverse(nodes[i]);}}var newWin=window.open();traverse(document);var mayaa=%22<m:mayaa xmlns:m=\%22http://mayaa.seasar.org\%22>\n%22;for(var i in ids){if(ids[i]!=%22%22){mayaa+=%22<m:with id=\%22%22+ids[i]+%22\%22><m:echo><m:doBody /></m:echo></m:with>\n%22;}}mayaa+=%22</m:mayaa>%22;newWin.document.open();newWin.document.write(%22<textarea rows=\%2220\%22 cols=\%22100\%22>%22+mayaa+%22</textarea>%22);newWin.document.close();})();

今はm:withとか出してるだけだけど、HTMLのタグに応じて出すタグを代えると面白いかも。
input type="text"の場合はvalue属性を出すとか、textareaならm:writeを書くとか、子要素があるときだけm:doBody出すとか。