Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Add more robust CLI that provides rendering options
Browse files Browse the repository at this point in the history
  • Loading branch information
knksmith57 committed Mar 20, 2016
1 parent 0302f9f commit af62076
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
61 changes: 55 additions & 6 deletions bin/marky-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,65 @@
var fs = require('fs')
var path = require('path')
var marky = require('..')
var yargs = require('yargs')
var omit = require('lodash').omit

if (process.argv.length < 3) {
console.log('Usage:\n\nmarky-markdown some.md > some.html')
process.exit()
}
var argv = yargs
.usage([
'npm\'s markdown parser',
'',
'Usage: $0 [options] some.md > some.html'
].join('\n'))
.version(function () {
return require('../package.json').version
})
.example(
'$0 --no-sanitize some.md > some.html',
'Parse "some.md" without sanitizing and redirect result to "some.html"'
)
.example(
'$0 --no-highlight README.md > index.html',
'Parse "README.md" without highlighting fenced code blocks and redirect result to "index.html"'
)
.option('sanitize', {
default: true,
describe: 'remove script tags and stuff',
type: 'boolean'
})
.option('linkify', {
default: true,
describe: 'turn orphan URLs into hyperlinks',
type: 'boolean'
})
.option('highlightSyntax', {
alias: 'highlight',
default: true,
describe: 'run highlights on fenced code blocks',
type: 'boolean'
})
.option('prefixHeadingIds', {
alias: 'prefix',
default: true,
describe: 'prevent DOM id collisions',
type: 'boolean'
})
.option('serveImagesWithCDN', {
alias: 'cdn',
default: false,
describe: 'use npm\'s CDN to proxy images over HTTPS',
type: 'boolean'
})
.demand(1)
.wrap(Math.min(125, yargs.terminalWidth()))
.argv

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

var options = omit(argv, ['_', 'version', 'highlight', 'prefix', 'cdn', '$0']);

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

fs.readFile(filePath, function (err, data) {
if (err) throw err
var $ = marky(data.toString())
var $ = marky(data.toString(), options)
process.stdout.write($.html())
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"markdown-it-expand-tabs": "^1.0.7",
"property-ttl": "^1.0.0",
"sanitize-html": "^1.6.1",
"similarity": "^1.0.1"
"similarity": "^1.0.1",
"yargs": "^3.32.0"
},
"devDependencies": {
"glob": "^7.0.0",
Expand Down

0 comments on commit af62076

Please sign in to comment.