Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created February 15, 2018 08:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save WebReflection/0fb41fe9133fb56ee7cd1b42d1cddbdb to your computer and use it in GitHub Desktop.
Save WebReflection/0fb41fe9133fb56ee7cd1b42d1cddbdb to your computer and use it in GitHub Desktop.
Transform IRC logs into Markdown
#!/usr/bin/env node
require('fs').readFile(process.argv[2], (err, data) => {
if (err) return;
const content = data.toString().trim();
const re = /^\[(.+?)\]\s+<(.+?)>\s(.*)$/gm;
const chat = [];
let current = {};
while (match = re.exec(content)) {
if (match[2] !== current.name) {
chat.push(current = {
time: match[1],
name: match[2],
content: match[3]
});
} else {
current.content += '\n\n' + match[3];
}
}
console.log(chat.map(user =>
`<sub><sup>[${user.time}]</sup></sub> **${user.name}**
${user.content.replace(/```[\S\s]+?```/g, $0 => $0.replace(/\n\n/g, '\n'))}
- - -`
).join('\n\n'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment