Created
March 14, 2018 21:25
-
-
Save dimensi/472ffaaf8820a60b7c729ab61aac8872 to your computer and use it in GitHub Desktop.
readline.js for md
This file contains 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
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