Skip to content

Instantly share code, notes, and snippets.

@dimensi
Created March 14, 2018 21:25
Show Gist options
  • Save dimensi/472ffaaf8820a60b7c729ab61aac8872 to your computer and use it in GitHub Desktop.
Save dimensi/472ffaaf8820a60b7c729ab61aac8872 to your computer and use it in GitHub Desktop.
readline.js for md
const readline = require('readline')
const fs = require('fs')
const { format } = require('util')
async function start() {
const rl = readline.createInterface({
input: fs.createReadStream('./text.html'),
crlfDelay: Infinity
})
let getYaml = false;
let yamlText = '';
let htmlText = '';
rl.on('line', (line) => {
if (line === '==') {
getYaml = true
return;
}
if (!getYaml) {
yamlText += format('%s\n', line)
} else {
htmlText += format('%s\n', line)
}
})
await new Promise(resolve => rl.on('close', resolve))
console.log('<<< END >>>')
console.log('YAML: ', yamlText)
console.log('HTML: ', htmlText)
}
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment