Skip to content

Commit

Permalink
#2 covered CLI in README and tidied CLI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
neocotic committed Dec 10, 2012
1 parent 949dabb commit ac31c19
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
77 changes: 67 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

[![Build Status](https://secure.travis-ci.org/neocotic/html.md.png)](http://travis-ci.org/neocotic/html.md)

[html.md][] can be used normally in any browser as well as in the [node.js][]
environment where it also provides a command line interface.

## Install

Install from [npm][]:
Expand All @@ -19,25 +22,78 @@ Install from [npm][]:
$ npm install html-md
```

## Standard Usage
## Usage

```
Usage: md [options] [ -e html | file.html ] [arguments]
Options:
-d, --debug print additional debug information
-e, --eval pass a string from the command line as input
-h, --help display this help information
-l, --long-ext use long extension for Markdown files
-o, --output DIR set the output directory for converted Markdown
-p, --print print out the converted Markdown
-v, --version display the version number
```

### Examples

Provide HTML to be converted and print it out into the terminal:

``` bash
$ md -ep "I <b>love</b> <a href='https://github.com/neocotic/html.md'>html.md</a>"
I **love** [html.md][0]

[0]: https://github.com/neocotic/html.md
```

Convert HTML files and output them into another directory:

``` javascript
md(html[, options])
``` bash
$ md -o ./markdown ./html/*.html
```

## Configuration
Convert all `.html` files in the current directory into `.markdown` files:

``` javascript
options.debug = true
``` bash
$ md -l .
```

## Miscellaneous
## Programmatically

``` javascript
md.noConflict()
md.VERSION
`md(html[, options])` is used primarily:

``` html
<script src="md.js"></script>
<script>
var markdown = md(document.querySelector('.content'))
console.log(markdown)
</script>
```

### Options

The following options are recognised by this method (all of which are optional);

<table>
<tr>
<th>Property</th>
<th>Description</th>
</tr>
<tr>
<td>debug</td>
<td>Prepends additional debug information to the Markdown output</td>
</tr>
</table>

### Miscellaneous

`md.noConflict()` returns `md` in a no-conflict state, reallocating the `md`
global variable name to its previous owner, where possible.

`md.VERSION` returns the current version.

## Bugs

If you have any problems with this library or would like to see the changes
Expand All @@ -61,4 +117,5 @@ http://neocotic.com/html.md
[html]: http://en.wikipedia.org/wiki/HTML
[html.md]: http://neocotic.com/html.md
[markdown]: http://en.wikipedia.org/wiki/Markdown
[node.js]: http://nodejs.org
[npm]: http://npmjs.org
5 changes: 3 additions & 2 deletions bin/md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NOT_FOUND = 'ENOENT'
R_HIDDEN = /^\.|~$/
# Regular expression used to identify HTML files using common extensions.
R_HTML_EXT = /\.s?html?$/i
#
# Available options/switches.
SWITCHES = [
['-d', '--debug', 'print additional debug information']
['-e', '--eval', 'pass a string from the command line as input']
Expand Down Expand Up @@ -115,7 +115,8 @@ parseHtml = (file, input, base) ->
# Parse the options provided at runtime.
parseOptions = ->
parser = new optparse.OptionParser SWITCHES
parser.banner = 'md [options] [ -e html | file.html ] [arguments]'
parser.banner = 'Usage: md [options] [ -e html | file.html ] [arguments]'
parser.options_title = 'Options:'
rCamel = /-([a-z])/gi
toCamelCase = (str) ->
str.replace rCamel, (match, char) -> char.toUpperCase()
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/sample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit ac31c19

Please sign in to comment.