Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions bin/marky-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,47 @@
var fs = require('fs')
var path = require('path')
var marky = require('..')
var information = require('../marky.json')

if (process.argv.length < 3) {
console.log('Usage:\n\nmarky-markdown some.md > some.html')
var executable = process.argv[0]
var script = process.argv[1]
var parameters = process.argv.slice(2)

function printHelp () {
console.log('Usage: marky-markdown [filename]')
console.log('')
console.log('Options: ')
console.log(' -h, --help show this help message')
console.log(' -v, --version print the marky-markdown version')
console.log('')
console.log('Example: `marky-markdown readme.md`')
}

function help () {
if (parameters[0] === '-h' || parameters[0] === '--help') {
printHelp()
process.exit()
}
}

function version () {
if (parameters[0] === '-V' || parameters[0] === '--version') {
console.log(information.version)
process.exit()
}
}

if (parameters.length === 0) {
printHelp()
process.exit()
}

var filePath = path.resolve(process.cwd(), process.argv[2])
help()
version()

var filename = path.resolve(process.cwd(), argv[0])

fs.readFile(filePath, function (err, data) {
fs.readFile(filename, function (err, data) {
if (err) throw err
var html = marky(data.toString())
process.stdout.write(html)
Expand Down