Skip to content

Instantly share code, notes, and snippets.

@oieioi
Last active August 29, 2015 14:13
Show Gist options
  • Save oieioi/0c1222024cd90013b302 to your computer and use it in GitHub Desktop.
Save oieioi/0c1222024cd90013b302 to your computer and use it in GitHub Desktop.
convert html list to markdown list
(function(ul, filter){
var getGeneration = function(li){
var f = function(li, count){
var parent = li.parentNode;
if (parent.nodeName !== 'UL'){
return count - 1;
}
return f(parent.parentNode, ++count);
}
return f(li, 0);
};
var getIndent = function(indent){
var r = "";
for(var i = 0;i < indent;i++){
r += ' ';
}
r += '- ';
return r;
};
var re = [];
var lis = document.querySelectorAll(ul);
[].forEach.call(lis, function(node){
var generation = getGeneration(node);
var indentText = getIndent(generation);
var text = node.textContent.trim().split('\n')[0];
if(filter && !filter.test(text)) {
return;
}
re.push(indentText + text);
});
return re;
})('.x-tree-node-ct li', /^filter/)
//.map((v)=>{return v.replace(/^ /, '')})
.join('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment