Skip to content

Instantly share code, notes, and snippets.

@paazmaya
Last active November 13, 2018 10:36
Show Gist options
  • Select an option

  • Save paazmaya/4b278ce7f96464ba19e63fa0470b15ae to your computer and use it in GitHub Desktop.

Select an option

Save paazmaya/4b278ce7f96464ba19e63fa0470b15ae to your computer and use it in GitHub Desktop.
Split single markdown file (list of sprints) to several (one for each sprint)
const fs = require('fs');
const MATCH_SPRINT = /^## Sprint (\d+):[\S\s]+?demo<\/a>/ugm;
const HEADER_LEVEL = /^##/ugm;
const SUFFIX = /\.md$/;
const original = fs.readFileSync('sprints-2018.md', 'utf8');
console.log(`Original file has ${original.length} lines`);
const index = [];
let list;
while ((list = MATCH_SPRINT.exec(original)) !== null) {
console.log(list[1]);
const filename = `sprints/sprint-${String(list[1]).trim()}.md`;
const data = list[0].replace(HEADER_LEVEL, '#');
fs.writeFileSync(filename, data, 'utf8');
index.push(`* [Sprint ${list[1]}](${filename.replace(SUFFIX, '')})`);
}
const content = `# Sprints
${index.join('\n')}
`;
fs.writeFileSync('sprints.md', content, 'utf8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment