diff --git a/doctoc.js b/doctoc.js index 578dfa9..31bc67c 100755 --- a/doctoc.js +++ b/doctoc.js @@ -2,7 +2,8 @@ 'use strict'; -var path = require('path') +var os = require('os') + , path = require('path') , fs = require('fs') , minimist = require('minimist') , file = require('./lib/file') @@ -16,6 +17,28 @@ function cleanPath(path) { return homeExpanded.replace(/\s/g, '\\ '); } +function readFile(path, encoding) { + var content = fs.readFileSync(path, encoding); + + // On Windows platform, convert CRLF line endings to LF line endings. + // The line ending style is unified for easier handling. + if (os.EOL === '\r\n') { + content = content.replace(/\r\n/g, '\n'); + } + + return content; +} + +function writeFile(path, data, encoding) { + + // On Windows platform, convert LF line endings to CRLF line endings. + if (os.EOL === '\r\n') { + data = data.replace(/(?