Last active
August 29, 2015 14:13
-
-
Save oieioi/0c1222024cd90013b302 to your computer and use it in GitHub Desktop.
convert html list to markdown list
This file contains 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
(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