Created
October 20, 2018 16:03
-
-
Save zetavg/6725b22fdeb3ccedf132f472e146f03f to your computer and use it in GitHub Desktop.
Generate TaskPaper to track progress of reading the CSS specifications on www.w3.org.
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
/** | |
* Execute this function on a CSS spicificaiton page to get TaskPaper tasks. | |
*/ | |
function generateTaskPaperFromTOC() { | |
function getDataFromLi(li) { | |
const children = Array.from(li.children) | |
const a = children.find(node => node.tagName === 'A') | |
const data = { | |
title: Array.from(a.children).map(node => node.innerText).join(' '), | |
url: a.href, | |
} | |
const ol = children.find(node => node.tagName === 'OL') | |
if (ol) { | |
data.children = Array.from(ol.children).filter(node => node.tagName === 'LI') | |
.map(node => getDataFromLi(node)) | |
} | |
return data | |
} | |
function getTaskPaperFromData(data) { | |
const task = `- ${data.title}\n\t${data.url}` | |
if (data.children) { | |
const subTasks = data.children.map(d => getTaskPaperFromData(d)) | |
const parentTask = task.replace(/\n\t/, ' @parallel(false) @autodone(true)\n\t') | |
const childrenTasks = [task, ...subTasks] | |
.map(text => text.replace(/^\t/mg, '\t\t').replace(/^- /mg, '\t- ')) | |
return [parentTask, ...childrenTasks].join('\n') | |
} | |
return task | |
} | |
const lis = Array.from(document.querySelector('#toc .toc').children).filter(node => node.tagName === 'LI') | |
const data = lis.map(li => getDataFromLi(li)) | |
return data.map(d => getTaskPaperFromData(d)).join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment