Created
February 15, 2018 08:27
-
-
Save WebReflection/0fb41fe9133fb56ee7cd1b42d1cddbdb to your computer and use it in GitHub Desktop.
Transform IRC logs into Markdown
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
#!/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