diff --git a/bld.sh b/bld.sh index 6024da6c3..6dce60d91 100755 --- a/bld.sh +++ b/bld.sh @@ -84,6 +84,14 @@ node ./tiddlywiki.js \ --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/codemirrordemo.html text/plain \ || exit 1 -# Seventh, run the test edition to run the node.js tests and to generate test.html for tests in the browser +# Seventh, codemirrordemo.html: wiki to demo codemirror plugin + +node ./tiddlywiki.js \ + ./editions/markdowndemo \ + --verbose \ + --new_rendertiddler $:/core/templates/tiddlywiki5.template.html $TW5_BUILD_OUTPUT/markdowndemo.html text/plain \ + || exit 1 + +# Eighth, run the test edition to run the node.js tests and to generate test.html for tests in the browser ./test.sh diff --git a/editions/markdowndemo/tiddlers/DefaultTiddlers.tid b/editions/markdowndemo/tiddlers/DefaultTiddlers.tid new file mode 100644 index 000000000..0f4e00095 --- /dev/null +++ b/editions/markdowndemo/tiddlers/DefaultTiddlers.tid @@ -0,0 +1,4 @@ +title: $:/DefaultTiddlers + +[[HelloThere]] +[[MarkdownExample]] diff --git a/editions/markdowndemo/tiddlers/HelloThere.tid b/editions/markdowndemo/tiddlers/HelloThere.tid new file mode 100644 index 000000000..132293e03 --- /dev/null +++ b/editions/markdowndemo/tiddlers/HelloThere.tid @@ -0,0 +1,9 @@ +title: HelloThere + +This is a demo of TiddlyWiki5 incorporating a plugin for the [[markdown-js|https://github.com/evilstreak/markdown-js]] Markdown parser. + +The MarkdownExample tiddler below is written in Markdown. + +To add the plugin to your own TiddlyWiki5, just drag this link to the browser window: + +[[$:/plugins/tiddlywiki/markdown]] diff --git a/editions/markdowndemo/tiddlers/MarkdownExample.tid b/editions/markdowndemo/tiddlers/MarkdownExample.tid new file mode 100644 index 000000000..ce6553d53 --- /dev/null +++ b/editions/markdowndemo/tiddlers/MarkdownExample.tid @@ -0,0 +1,301 @@ +title: MarkdownExample +type: text/x-markdown + +Markdown: Basics +================ + +Getting the Gist of Markdown's Formatting Syntax +------------------------------------------------ + +This page offers a brief overview of what it's like to use Markdown. +The [syntax page] [s] provides complete, detailed documentation for +every feature, but Markdown should be very easy to pick up simply by +looking at a few examples of it in action. The examples on this page +are written in a before/after style, showing example syntax and the +HTML output produced by Markdown. + +It's also helpful to simply try Markdown out; the [Dingus] [d] is a +web application that allows you type your own Markdown-formatted text +and translate it to XHTML. + +**Note:** This document is itself written using Markdown; you +can [see the source for it by adding '.text' to the URL] [src]. + + [s]: /projects/markdown/syntax "Markdown Syntax" + [d]: /projects/markdown/dingus "Markdown Dingus" + [src]: /projects/markdown/basics.text + + +## Paragraphs, Headers, Blockquotes ## + +A paragraph is simply one or more consecutive lines of text, separated +by one or more blank lines. (A blank line is any line that looks like +a blank line -- a line containing nothing but spaces or tabs is +considered blank.) Normal paragraphs should not be indented with +spaces or tabs. + +Markdown offers two styles of headers: *Setext* and *atx*. +Setext-style headers for `

` and `

` are created by +"underlining" with equal signs (`=`) and hyphens (`-`), respectively. +To create an atx-style header, you put 1-6 hash marks (`#`) at the +beginning of the line -- the number of hashes equals the resulting +HTML header level. + +Blockquotes are indicated using email-style '`>`' angle brackets. + +Markdown: + + A First Level Header + ==================== + + A Second Level Header + --------------------- + + Now is the time for all good men to come to + the aid of their country. This is just a + regular paragraph. + + The quick brown fox jumped over the lazy + dog's back. + + ### Header 3 + + > This is a blockquote. + > + > This is the second paragraph in the blockquote. + > + > ## This is an H2 in a blockquote + + +Output: + +

A First Level Header

+ +

A Second Level Header

+ +

Now is the time for all good men to come to + the aid of their country. This is just a + regular paragraph.

+ +

The quick brown fox jumped over the lazy + dog's back.

+ +

Header 3

+ +
+

This is a blockquote.

+ +

This is the second paragraph in the blockquote.

+ +

This is an H2 in a blockquote

+
+ + + +### Phrase Emphasis ### + +Markdown uses asterisks and underscores to indicate spans of emphasis. + +Markdown: + + Some of these words *are emphasized*. + Some of these words _are emphasized also_. + + Use two asterisks for **strong emphasis**. + Or, if you prefer, __use two underscores instead__. + +Output: + +

Some of these words are emphasized. + Some of these words are emphasized also.

+ +

Use two asterisks for strong emphasis. + Or, if you prefer, use two underscores instead.

+ + + +## Lists ## + +Unordered (bulleted) lists use asterisks, pluses, and hyphens (`*`, +`+`, and `-`) as list markers. These three markers are +interchangable; this: + + * Candy. + * Gum. + * Booze. + +this: + + + Candy. + + Gum. + + Booze. + +and this: + + - Candy. + - Gum. + - Booze. + +all produce the same output: + + + +Ordered (numbered) lists use regular numbers, followed by periods, as +list markers: + + 1. Red + 2. Green + 3. Blue + +Output: + +
    +
  1. Red
  2. +
  3. Green
  4. +
  5. Blue
  6. +
+ +If you put blank lines between items, you'll get `

` tags for the +list item text. You can create multi-paragraph list items by indenting +the paragraphs by 4 spaces or 1 tab: + + * A list item. + + With multiple paragraphs. + + * Another item in the list. + +Output: + +

+ + + +### Links ### + +Markdown supports two styles for creating links: *inline* and +*reference*. With both styles, you use square brackets to delimit the +text you want to turn into a link. + +Inline-style links use parentheses immediately after the link text. +For example: + + This is an [example link](http://example.com/). + +Output: + +

This is an + example link.

+ +Optionally, you may include a title attribute in the parentheses: + + This is an [example link](http://example.com/ "With a Title"). + +Output: + +

This is an + example link.

+ +Reference-style links allow you to refer to your links by names, which +you define elsewhere in your document: + + I get 10 times more traffic from [Google][1] than from + [Yahoo][2] or [MSN][3]. + + [1]: http://google.com/ "Google" + [2]: http://search.yahoo.com/ "Yahoo Search" + [3]: http://search.msn.com/ "MSN Search" + +Output: + +

I get 10 times more traffic from Google than from Yahoo or MSN.

+ +The title attribute is optional. Link names may contain letters, +numbers and spaces, but are *not* case sensitive: + + I start my morning with a cup of coffee and + [The New York Times][NY Times]. + + [ny times]: http://www.nytimes.com/ + +Output: + +

I start my morning with a cup of coffee and + The New York Times.

+ + +### Images ### + +Image syntax is very much like link syntax. + +Inline (titles are optional): + + ![alt text](/path/to/img.jpg "Title") + +Reference-style: + + ![alt text][id] + + [id]: /path/to/img.jpg "Title" + +Both of the above examples produce the same output: + + alt text + + + +### Code ### + +In a regular paragraph, you can create code span by wrapping text in +backtick quotes. Any ampersands (`&`) and angle brackets (`<` or +`>`) will automatically be translated into HTML entities. This makes +it easy to use Markdown to write about HTML example code: + + I strongly recommend against using any `` tags. + + I wish SmartyPants used named entities like `—` + instead of decimal-encoded entites like `—`. + +Output: + +

I strongly recommend against using any + <blink> tags.

+ +

I wish SmartyPants used named entities like + &mdash; instead of decimal-encoded + entites like &#8212;.

+ + +To specify an entire block of pre-formatted code, indent every line of +the block by 4 spaces or 1 tab. Just like with code spans, `&`, `<`, +and `>` characters will be escaped automatically. + +Markdown: + + If you want your page to validate under XHTML 1.0 Strict, + you've got to put paragraph tags in your blockquotes: + +
+

For example.

+
+ +Output: + +

If you want your page to validate under XHTML 1.0 Strict, + you've got to put paragraph tags in your blockquotes:

+ +
<blockquote>
+        <p>For example.</p>
+    </blockquote>
+    
diff --git a/editions/markdowndemo/tiddlers/SiteSubtitle.tid b/editions/markdowndemo/tiddlers/SiteSubtitle.tid new file mode 100644 index 000000000..3f207803a --- /dev/null +++ b/editions/markdowndemo/tiddlers/SiteSubtitle.tid @@ -0,0 +1,3 @@ +title: SiteSubtitle + +a demo of the Markdown plugin for TiddlyWiki5 \ No newline at end of file diff --git a/editions/markdowndemo/tiddlers/SiteTitle.tid b/editions/markdowndemo/tiddlers/SiteTitle.tid new file mode 100644 index 000000000..654809a22 --- /dev/null +++ b/editions/markdowndemo/tiddlers/SiteTitle.tid @@ -0,0 +1,3 @@ +title: SiteTitle + +markdowndemo \ No newline at end of file diff --git a/editions/markdowndemo/tiddlywiki.info b/editions/markdowndemo/tiddlywiki.info new file mode 100644 index 000000000..79b5d405c --- /dev/null +++ b/editions/markdowndemo/tiddlywiki.info @@ -0,0 +1,12 @@ +{ + "plugins": [ + "tiddlywiki/markdown" + ], + "themes": [ + "tiddlywiki/snowwhite" + ], + "doNotSave": [ + ], + "includeWikis": [ + ] +} diff --git a/editions/tw5.com/tiddlers/Features.tid b/editions/tw5.com/tiddlers/Features.tid index b78828130..2fa8d4e39 100644 --- a/editions/tw5.com/tiddlers/Features.tid +++ b/editions/tw5.com/tiddlers/Features.tid @@ -16,6 +16,7 @@ title: Features * Try out the <$button message="tw-full-screen">full screen support * Explore the [[D3.js visualisation plugin|http://five.tiddlywiki.com/d3demo.html]] * Try out the [[CodeMirror plugin|http://five.tiddlywiki.com/codemirrordemo.html]] +* Try out the [[Markdown plugin|http://five.tiddlywiki.com/markdowndemo.html]] * Many internal improvements: ** TiddlyWiki can now be run under [[node.js]] as well as in the browser, allowing it to be used as a personal web server ** An elegant [[microkernel architecture|PluginMechanism]], that allows infinite customisation by replacing and augmenting the core modules diff --git a/node_modules/.bin/md2html b/node_modules/.bin/md2html new file mode 120000 index 000000000..ebcab9ae9 --- /dev/null +++ b/node_modules/.bin/md2html @@ -0,0 +1 @@ +../markdown/bin/md2html.js \ No newline at end of file diff --git a/node_modules/markdown/.npmignore b/node_modules/markdown/.npmignore new file mode 100644 index 000000000..0ec905315 --- /dev/null +++ b/node_modules/markdown/.npmignore @@ -0,0 +1,2 @@ +.seed.yml +test diff --git a/node_modules/markdown/.travis.yml b/node_modules/markdown/.travis.yml new file mode 100644 index 000000000..90cc39db5 --- /dev/null +++ b/node_modules/markdown/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - "0.6" + - "0.8" + - "0.9" + - "0.10" + - "0.11" diff --git a/node_modules/markdown/Changes.markdown b/node_modules/markdown/Changes.markdown new file mode 100644 index 000000000..9dae3b1ea --- /dev/null +++ b/node_modules/markdown/Changes.markdown @@ -0,0 +1,35 @@ +# Changelog for markdown + +## v0.5.0 - 2013-07-26 + +There might be other bug fixes then the ones listed - I've been a bit lax at +updating the changes file, sorry :( + +- Fix 'undefined' appearing in output for some cases with blockquotes +- Fix (multiple) global variable leaks. Ooops +- Fix IE8 issues (#68, #74, #97) +- Fix IE8 issue (#86) +- Handle windows line endings (#58) +- Allow spaces in img/link paths (#48) +- Add explicit text of the license to the readme (#74) +- Style tweaks by Xhmikosr (#83, #81, #82) +- Build now tested by TravisCI thanks to sebs (#85) +- Fix 'cuddled' header parsing (#94) +- Fix images inside links mistakenly requiring a title attribute to parse + correctly (#71) + + +## v0.4.0 - 2012-06-09 + +- Fix for anchors enclosed by parenthesis (issue #46) +- `npm test` will now run the entire test suite cleanly. (switch tests over to + node-tap). (#21) +- Allow inline elements to appear inside link text (#27) +- Improve link parsing when link is inside parenthesis (#38) +- Actually render image references (#36) +- Improve link parsing when multiple on a line (#5) +- Make it work in IE7/8 (#37) +- Fix blockquote merging/implicit conversion between string/String (#44, #24) +- md2html can now process stdin (#43) +- Fix jslint warnings (#42) +- Fix to correctly render self-closing tags (#40, #35, #28) diff --git a/node_modules/markdown/README.markdown b/node_modules/markdown/README.markdown new file mode 100644 index 000000000..d3f231e42 --- /dev/null +++ b/node_modules/markdown/README.markdown @@ -0,0 +1,185 @@ +# markdown-js + +Yet another markdown parser, this time for JavaScript. There's a few +options that precede this project but they all treat markdown to HTML +conversion as a single step process. You pass markdown in and get HTML +out, end of story. We had some pretty particular views on how the +process should actually look, which include: + + * producing well-formed HTML. This means that `em` and `strong` nesting + is important, as is the ability to output as both HTML and XHTML + + * having an intermediate representation to allow processing of parsed + data (we in fact have two, both [JsonML]: a markdown tree and an HTML tree) + + * being easily extensible to add new dialects without having to + rewrite the entire parsing mechanics + + * having a good test suite. The only test suites we could find tested + massive blocks of input, and passing depended on outputting the HTML + with exactly the same whitespace as the original implementation + +[JsonML]: http://jsonml.org/ "JSON Markup Language" + +## Installation + +Just the `markdown` library: + + npm install markdown + +Optionally, install `md2html` into your path + + npm install -g markdown + +## Usage + +### Node + +The simple way to use it with node is: + +```js +var markdown = require( "markdown" ).markdown; +console.log( markdown.toHTML( "Hello *World*!" ) ); +``` + +### Browser + +It also works in a browser; here is a complete example: + +```html + + + + +
+ + + + +``` + +### Command line + +Assuming you've installed the `md2html` script (see Installation, +above), you can convert markdown to html: + +```bash +# read from a file +md2html /path/to/doc.md > /path/to/doc.html + +# or from stdin +echo 'Hello *World*!' | md2html +``` + +### More options + +If you want more control check out the documentation in +[lib/markdown.js] which details all the methods and parameters +available (including examples!). One day we'll get the docs generated +and hosted somewhere for nicer browsing. + +[lib/markdown.js]: http://github.com/evilstreak/markdown-js/blob/master/lib/markdown.js + +Meanwhile, here's an example of using the multi-step processing to +make wiki-style linking work by filling in missing link references: + +```js +var md = require( "markdown" ).markdown, + text = "[Markdown] is a simple text-based [markup language]\n" + + "created by [John Gruber]\n\n" + + "[John Gruber]: http://daringfireball.net"; + +// parse the markdown into a tree and grab the link references +var tree = md.parse( text ), + refs = tree[ 1 ].references; + +// iterate through the tree finding link references +( function find_link_refs( jsonml ) { + if ( jsonml[ 0 ] === "link_ref" ) { + var ref = jsonml[ 1 ].ref; + + // if there's no reference, define a wiki link + if ( !refs[ ref ] ) { + refs[ ref ] = { + href: "http://en.wikipedia.org/wiki/" + ref.replace(/\s+/, "_" ) + }; + } + } + else if ( Array.isArray( jsonml[ 1 ] ) ) { + jsonml[ 1 ].forEach( find_link_refs ); + } + else if ( Array.isArray( jsonml[ 2 ] ) ) { + jsonml[ 2 ].forEach( find_link_refs ); + } +} )( tree ); + +// convert the tree into html +var html = md.renderJsonML( md.toHTMLTree( tree ) ); +console.log( html ); +``` + +## Intermediate Representation + +Internally the process to convert a chunk of markdown into a chunk of +HTML has three steps: + + 1. Parse the markdown into a JsonML tree. Any references found in the + parsing are stored in the attribute hash of the root node under the + key `references`. + + 2. Convert the markdown tree into an HTML tree. Rename any nodes that + need it (`bulletlist` to `ul` for example) and lookup any references + used by links or images. Remove the references attribute once done. + + 3. Stringify the HTML tree being careful not to wreck whitespace where + whitespace is important (surrounding inline elements for example). + +Each step of this process can be called individually if you need to do +some processing or modification of the data at an intermediate stage. +For example, you may want to grab a list of all URLs linked to in the +document before rendering it to HTML which you could do by recursing +through the HTML tree looking for `a` nodes. + +## Running tests + +To run the tests under node you will need tap installed (it's listed as a +`devDependencies` so `npm install` from the checkout should be enough), then do + + $ npm test + +## Contributing + +Do the usual github fork and pull request dance. Add yourself to the +contributors section of [package.json](/package.json) too if you want to. + +## License + +Released under the MIT license. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/markdown/bin/md2html.js b/node_modules/markdown/bin/md2html.js new file mode 100755 index 000000000..f8ce1dd57 --- /dev/null +++ b/node_modules/markdown/bin/md2html.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node +(function () { + "use strict"; + + var fs = require("fs") + , markdown = require("markdown").markdown + , nopt = require("nopt") + , stream + , opts + , buffer = "" + ; + + opts = nopt( + { "dialect": [ "Gruber", "Maruku"] + , "help": Boolean + } + ); + + if (opts.help) { + var name = process.argv[1].split("/").pop() + console.warn( require("util").format( + "usage: %s [--dialect=DIALECT] FILE\n\nValid dialects are Gruber (the default) or Maruku", + name + ) ); + process.exit(0); + } + + var fullpath = opts.argv.remain[0]; + + if (fullpath && fullpath !== "-") { + stream = fs.createReadStream(fullpath); + } else { + stream = process.stdin; + } + stream.resume(); + stream.setEncoding("utf8"); + + stream.on("error", function(error) { + console.error(error.toString()); + process.exit(1); + }); + + stream.on("data", function(data) { + buffer += data; + }); + + stream.on("end", function() { + var html = markdown.toHTML(buffer, opts.dialect); + console.log(html); + }); + +}()) diff --git a/node_modules/markdown/lib/index.js b/node_modules/markdown/lib/index.js new file mode 100644 index 000000000..8bb08734b --- /dev/null +++ b/node_modules/markdown/lib/index.js @@ -0,0 +1,3 @@ +// super simple module for the most common nodejs use case. +exports.markdown = require("./markdown"); +exports.parse = exports.markdown.toHTML; diff --git a/node_modules/markdown/lib/markdown.js b/node_modules/markdown/lib/markdown.js new file mode 100644 index 000000000..d365cfa07 --- /dev/null +++ b/node_modules/markdown/lib/markdown.js @@ -0,0 +1,1725 @@ +// Released under MIT license +// Copyright (c) 2009-2010 Dominic Baggott +// Copyright (c) 2009-2010 Ash Berlin +// Copyright (c) 2011 Christoph Dorn (http://www.christophdorn.com) + +/*jshint browser:true, devel:true */ + +(function( expose ) { + +/** + * class Markdown + * + * Markdown processing in Javascript done right. We have very particular views + * on what constitutes 'right' which include: + * + * - produces well-formed HTML (this means that em and strong nesting is + * important) + * + * - has an intermediate representation to allow processing of parsed data (We + * in fact have two, both as [JsonML]: a markdown tree and an HTML tree). + * + * - is easily extensible to add new dialects without having to rewrite the + * entire parsing mechanics + * + * - has a good test suite + * + * This implementation fulfills all of these (except that the test suite could + * do with expanding to automatically run all the fixtures from other Markdown + * implementations.) + * + * ##### Intermediate Representation + * + * *TODO* Talk about this :) Its JsonML, but document the node names we use. + * + * [JsonML]: http://jsonml.org/ "JSON Markup Language" + **/ +var Markdown = expose.Markdown = function(dialect) { + switch (typeof dialect) { + case "undefined": + this.dialect = Markdown.dialects.Gruber; + break; + case "object": + this.dialect = dialect; + break; + default: + if ( dialect in Markdown.dialects ) { + this.dialect = Markdown.dialects[dialect]; + } + else { + throw new Error("Unknown Markdown dialect '" + String(dialect) + "'"); + } + break; + } + this.em_state = []; + this.strong_state = []; + this.debug_indent = ""; +}; + +/** + * parse( markdown, [dialect] ) -> JsonML + * - markdown (String): markdown string to parse + * - dialect (String | Dialect): the dialect to use, defaults to gruber + * + * Parse `markdown` and return a markdown document as a Markdown.JsonML tree. + **/ +expose.parse = function( source, dialect ) { + // dialect will default if undefined + var md = new Markdown( dialect ); + return md.toTree( source ); +}; + +/** + * toHTML( markdown, [dialect] ) -> String + * toHTML( md_tree ) -> String + * - markdown (String): markdown string to parse + * - md_tree (Markdown.JsonML): parsed markdown tree + * + * Take markdown (either as a string or as a JsonML tree) and run it through + * [[toHTMLTree]] then turn it into a well-formated HTML fragment. + **/ +expose.toHTML = function toHTML( source , dialect , options ) { + var input = expose.toHTMLTree( source , dialect , options ); + + return expose.renderJsonML( input ); +}; + +/** + * toHTMLTree( markdown, [dialect] ) -> JsonML + * toHTMLTree( md_tree ) -> JsonML + * - markdown (String): markdown string to parse + * - dialect (String | Dialect): the dialect to use, defaults to gruber + * - md_tree (Markdown.JsonML): parsed markdown tree + * + * Turn markdown into HTML, represented as a JsonML tree. If a string is given + * to this function, it is first parsed into a markdown tree by calling + * [[parse]]. + **/ +expose.toHTMLTree = function toHTMLTree( input, dialect , options ) { + // convert string input to an MD tree + if ( typeof input ==="string" ) input = this.parse( input, dialect ); + + // Now convert the MD tree to an HTML tree + + // remove references from the tree + var attrs = extract_attr( input ), + refs = {}; + + if ( attrs && attrs.references ) { + refs = attrs.references; + } + + var html = convert_tree_to_html( input, refs , options ); + merge_text_nodes( html ); + return html; +}; + +// For Spidermonkey based engines +function mk_block_toSource() { + return "Markdown.mk_block( " + + uneval(this.toString()) + + ", " + + uneval(this.trailing) + + ", " + + uneval(this.lineNumber) + + " )"; +} + +// node +function mk_block_inspect() { + var util = require("util"); + return "Markdown.mk_block( " + + util.inspect(this.toString()) + + ", " + + util.inspect(this.trailing) + + ", " + + util.inspect(this.lineNumber) + + " )"; + +} + +var mk_block = Markdown.mk_block = function(block, trail, line) { + // Be helpful for default case in tests. + if ( arguments.length == 1 ) trail = "\n\n"; + + var s = new String(block); + s.trailing = trail; + // To make it clear its not just a string + s.inspect = mk_block_inspect; + s.toSource = mk_block_toSource; + + if ( line != undefined ) + s.lineNumber = line; + + return s; +}; + +function count_lines( str ) { + var n = 0, i = -1; + while ( ( i = str.indexOf("\n", i + 1) ) !== -1 ) n++; + return n; +} + +// Internal - split source into rough blocks +Markdown.prototype.split_blocks = function splitBlocks( input, startLine ) { + input = input.replace(/(\r\n|\n|\r)/g, "\n"); + // [\s\S] matches _anything_ (newline or space) + // [^] is equivalent but doesn't work in IEs. + var re = /([\s\S]+?)($|\n#|\n(?:\s*\n|$)+)/g, + blocks = [], + m; + + var line_no = 1; + + if ( ( m = /^(\s*\n)/.exec(input) ) != null ) { + // skip (but count) leading blank lines + line_no += count_lines( m[0] ); + re.lastIndex = m[0].length; + } + + while ( ( m = re.exec(input) ) !== null ) { + if (m[2] == "\n#") { + m[2] = "\n"; + re.lastIndex--; + } + blocks.push( mk_block( m[1], m[2], line_no ) ); + line_no += count_lines( m[0] ); + } + + return blocks; +}; + +/** + * Markdown#processBlock( block, next ) -> undefined | [ JsonML, ... ] + * - block (String): the block to process + * - next (Array): the following blocks + * + * Process `block` and return an array of JsonML nodes representing `block`. + * + * It does this by asking each block level function in the dialect to process + * the block until one can. Succesful handling is indicated by returning an + * array (with zero or more JsonML nodes), failure by a false value. + * + * Blocks handlers are responsible for calling [[Markdown#processInline]] + * themselves as appropriate. + * + * If the blocks were split incorrectly or adjacent blocks need collapsing you + * can adjust `next` in place using shift/splice etc. + * + * If any of this default behaviour is not right for the dialect, you can + * define a `__call__` method on the dialect that will get invoked to handle + * the block processing. + */ +Markdown.prototype.processBlock = function processBlock( block, next ) { + var cbs = this.dialect.block, + ord = cbs.__order__; + + if ( "__call__" in cbs ) { + return cbs.__call__.call(this, block, next); + } + + for ( var i = 0; i < ord.length; i++ ) { + //D:this.debug( "Testing", ord[i] ); + var res = cbs[ ord[i] ].call( this, block, next ); + if ( res ) { + //D:this.debug(" matched"); + if ( !isArray(res) || ( res.length > 0 && !( isArray(res[0]) ) ) ) + this.debug(ord[i], "didn't return a proper array"); + //D:this.debug( "" ); + return res; + } + } + + // Uhoh! no match! Should we throw an error? + return []; +}; + +Markdown.prototype.processInline = function processInline( block ) { + return this.dialect.inline.__call__.call( this, String( block ) ); +}; + +/** + * Markdown#toTree( source ) -> JsonML + * - source (String): markdown source to parse + * + * Parse `source` into a JsonML tree representing the markdown document. + **/ +// custom_tree means set this.tree to `custom_tree` and restore old value on return +Markdown.prototype.toTree = function toTree( source, custom_root ) { + var blocks = source instanceof Array ? source : this.split_blocks( source ); + + // Make tree a member variable so its easier to mess with in extensions + var old_tree = this.tree; + try { + this.tree = custom_root || this.tree || [ "markdown" ]; + + blocks: + while ( blocks.length ) { + var b = this.processBlock( blocks.shift(), blocks ); + + // Reference blocks and the like won't return any content + if ( !b.length ) continue blocks; + + this.tree.push.apply( this.tree, b ); + } + return this.tree; + } + finally { + if ( custom_root ) { + this.tree = old_tree; + } + } +}; + +// Noop by default +Markdown.prototype.debug = function () { + var args = Array.prototype.slice.call( arguments); + args.unshift(this.debug_indent); + if ( typeof print !== "undefined" ) + print.apply( print, args ); + if ( typeof console !== "undefined" && typeof console.log !== "undefined" ) + console.log.apply( null, args ); +} + +Markdown.prototype.loop_re_over_block = function( re, block, cb ) { + // Dont use /g regexps with this + var m, + b = block.valueOf(); + + while ( b.length && (m = re.exec(b) ) != null ) { + b = b.substr( m[0].length ); + cb.call(this, m); + } + return b; +}; + +/** + * Markdown.dialects + * + * Namespace of built-in dialects. + **/ +Markdown.dialects = {}; + +/** + * Markdown.dialects.Gruber + * + * The default dialect that follows the rules set out by John Gruber's + * markdown.pl as closely as possible. Well actually we follow the behaviour of + * that script which in some places is not exactly what the syntax web page + * says. + **/ +Markdown.dialects.Gruber = { + block: { + atxHeader: function atxHeader( block, next ) { + var m = block.match( /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/ ); + + if ( !m ) return undefined; + + var header = [ "header", { level: m[ 1 ].length } ]; + Array.prototype.push.apply(header, this.processInline(m[ 2 ])); + + if ( m[0].length < block.length ) + next.unshift( mk_block( block.substr( m[0].length ), block.trailing, block.lineNumber + 2 ) ); + + return [ header ]; + }, + + setextHeader: function setextHeader( block, next ) { + var m = block.match( /^(.*)\n([-=])\2\2+(?:\n|$)/ ); + + if ( !m ) return undefined; + + var level = ( m[ 2 ] === "=" ) ? 1 : 2; + var header = [ "header", { level : level }, m[ 1 ] ]; + + if ( m[0].length < block.length ) + next.unshift( mk_block( block.substr( m[0].length ), block.trailing, block.lineNumber + 2 ) ); + + return [ header ]; + }, + + code: function code( block, next ) { + // | Foo + // |bar + // should be a code block followed by a paragraph. Fun + // + // There might also be adjacent code block to merge. + + var ret = [], + re = /^(?: {0,3}\t| {4})(.*)\n?/, + lines; + + // 4 spaces + content + if ( !block.match( re ) ) return undefined; + + block_search: + do { + // Now pull out the rest of the lines + var b = this.loop_re_over_block( + re, block.valueOf(), function( m ) { ret.push( m[1] ); } ); + + if ( b.length ) { + // Case alluded to in first comment. push it back on as a new block + next.unshift( mk_block(b, block.trailing) ); + break block_search; + } + else if ( next.length ) { + // Check the next block - it might be code too + if ( !next[0].match( re ) ) break block_search; + + // Pull how how many blanks lines follow - minus two to account for .join + ret.push ( block.trailing.replace(/[^\n]/g, "").substring(2) ); + + block = next.shift(); + } + else { + break block_search; + } + } while ( true ); + + return [ [ "code_block", ret.join("\n") ] ]; + }, + + horizRule: function horizRule( block, next ) { + // this needs to find any hr in the block to handle abutting blocks + var m = block.match( /^(?:([\s\S]*?)\n)?[ \t]*([-_*])(?:[ \t]*\2){2,}[ \t]*(?:\n([\s\S]*))?$/ ); + + if ( !m ) { + return undefined; + } + + var jsonml = [ [ "hr" ] ]; + + // if there's a leading abutting block, process it + if ( m[ 1 ] ) { + jsonml.unshift.apply( jsonml, this.processBlock( m[ 1 ], [] ) ); + } + + // if there's a trailing abutting block, stick it into next + if ( m[ 3 ] ) { + next.unshift( mk_block( m[ 3 ] ) ); + } + + return jsonml; + }, + + // There are two types of lists. Tight and loose. Tight lists have no whitespace + // between the items (and result in text just in the
  • ) and loose lists, + // which have an empty line between list items, resulting in (one or more) + // paragraphs inside the
  • . + // + // There are all sorts weird edge cases about the original markdown.pl's + // handling of lists: + // + // * Nested lists are supposed to be indented by four chars per level. But + // if they aren't, you can get a nested list by indenting by less than + // four so long as the indent doesn't match an indent of an existing list + // item in the 'nest stack'. + // + // * The type of the list (bullet or number) is controlled just by the + // first item at the indent. Subsequent changes are ignored unless they + // are for nested lists + // + lists: (function( ) { + // Use a closure to hide a few variables. + var any_list = "[*+-]|\\d+\\.", + bullet_list = /[*+-]/, + number_list = /\d+\./, + // Capture leading indent as it matters for determining nested lists. + is_list_re = new RegExp( "^( {0,3})(" + any_list + ")[ \t]+" ), + indent_re = "(?: {0,3}\\t| {4})"; + + // TODO: Cache this regexp for certain depths. + // Create a regexp suitable for matching an li for a given stack depth + function regex_for_depth( depth ) { + + return new RegExp( + // m[1] = indent, m[2] = list_type + "(?:^(" + indent_re + "{0," + depth + "} {0,3})(" + any_list + ")\\s+)|" + + // m[3] = cont + "(^" + indent_re + "{0," + (depth-1) + "}[ ]{0,4})" + ); + } + function expand_tab( input ) { + return input.replace( / {0,3}\t/g, " " ); + } + + // Add inline content `inline` to `li`. inline comes from processInline + // so is an array of content + function add(li, loose, inline, nl) { + if ( loose ) { + li.push( [ "para" ].concat(inline) ); + return; + } + // Hmmm, should this be any block level element or just paras? + var add_to = li[li.length -1] instanceof Array && li[li.length - 1][0] == "para" + ? li[li.length -1] + : li; + + // If there is already some content in this list, add the new line in + if ( nl && li.length > 1 ) inline.unshift(nl); + + for ( var i = 0; i < inline.length; i++ ) { + var what = inline[i], + is_str = typeof what == "string"; + if ( is_str && add_to.length > 1 && typeof add_to[add_to.length-1] == "string" ) { + add_to[ add_to.length-1 ] += what; + } + else { + add_to.push( what ); + } + } + } + + // contained means have an indent greater than the current one. On + // *every* line in the block + function get_contained_blocks( depth, blocks ) { + + var re = new RegExp( "^(" + indent_re + "{" + depth + "}.*?\\n?)*$" ), + replace = new RegExp("^" + indent_re + "{" + depth + "}", "gm"), + ret = []; + + while ( blocks.length > 0 ) { + if ( re.exec( blocks[0] ) ) { + var b = blocks.shift(), + // Now remove that indent + x = b.replace( replace, ""); + + ret.push( mk_block( x, b.trailing, b.lineNumber ) ); + } + else { + break; + } + } + return ret; + } + + // passed to stack.forEach to turn list items up the stack into paras + function paragraphify(s, i, stack) { + var list = s.list; + var last_li = list[list.length-1]; + + if ( last_li[1] instanceof Array && last_li[1][0] == "para" ) { + return; + } + if ( i + 1 == stack.length ) { + // Last stack frame + // Keep the same array, but replace the contents + last_li.push( ["para"].concat( last_li.splice(1, last_li.length - 1) ) ); + } + else { + var sublist = last_li.pop(); + last_li.push( ["para"].concat( last_li.splice(1, last_li.length - 1) ), sublist ); + } + } + + // The matcher function + return function( block, next ) { + var m = block.match( is_list_re ); + if ( !m ) return undefined; + + function make_list( m ) { + var list = bullet_list.exec( m[2] ) + ? ["bulletlist"] + : ["numberlist"]; + + stack.push( { list: list, indent: m[1] } ); + return list; + } + + + var stack = [], // Stack of lists for nesting. + list = make_list( m ), + last_li, + loose = false, + ret = [ stack[0].list ], + i; + + // Loop to search over block looking for inner block elements and loose lists + loose_search: + while ( true ) { + // Split into lines preserving new lines at end of line + var lines = block.split( /(?=\n)/ ); + + // We have to grab all lines for a li and call processInline on them + // once as there are some inline things that can span lines. + var li_accumulate = ""; + + // Loop over the lines in this block looking for tight lists. + tight_search: + for ( var line_no = 0; line_no < lines.length; line_no++ ) { + var nl = "", + l = lines[line_no].replace(/^\n/, function(n) { nl = n; return ""; }); + + // TODO: really should cache this + var line_re = regex_for_depth( stack.length ); + + m = l.match( line_re ); + //print( "line:", uneval(l), "\nline match:", uneval(m) ); + + // We have a list item + if ( m[1] !== undefined ) { + // Process the previous list item, if any + if ( li_accumulate.length ) { + add( last_li, loose, this.processInline( li_accumulate ), nl ); + // Loose mode will have been dealt with. Reset it + loose = false; + li_accumulate = ""; + } + + m[1] = expand_tab( m[1] ); + var wanted_depth = Math.floor(m[1].length/4)+1; + //print( "want:", wanted_depth, "stack:", stack.length); + if ( wanted_depth > stack.length ) { + // Deep enough for a nested list outright + //print ( "new nested list" ); + list = make_list( m ); + last_li.push( list ); + last_li = list[1] = [ "listitem" ]; + } + else { + // We aren't deep enough to be strictly a new level. This is + // where Md.pl goes nuts. If the indent matches a level in the + // stack, put it there, else put it one deeper then the + // wanted_depth deserves. + var found = false; + for ( i = 0; i < stack.length; i++ ) { + if ( stack[ i ].indent != m[1] ) continue; + list = stack[ i ].list; + stack.splice( i+1, stack.length - (i+1) ); + found = true; + break; + } + + if (!found) { + //print("not found. l:", uneval(l)); + wanted_depth++; + if ( wanted_depth <= stack.length ) { + stack.splice(wanted_depth, stack.length - wanted_depth); + //print("Desired depth now", wanted_depth, "stack:", stack.length); + list = stack[wanted_depth-1].list; + //print("list:", uneval(list) ); + } + else { + //print ("made new stack for messy indent"); + list = make_list(m); + last_li.push(list); + } + } + + //print( uneval(list), "last", list === stack[stack.length-1].list ); + last_li = [ "listitem" ]; + list.push(last_li); + } // end depth of shenegains + nl = ""; + } + + // Add content + if ( l.length > m[0].length ) { + li_accumulate += nl + l.substr( m[0].length ); + } + } // tight_search + + if ( li_accumulate.length ) { + add( last_li, loose, this.processInline( li_accumulate ), nl ); + // Loose mode will have been dealt with. Reset it + loose = false; + li_accumulate = ""; + } + + // Look at the next block - we might have a loose list. Or an extra + // paragraph for the current li + var contained = get_contained_blocks( stack.length, next ); + + // Deal with code blocks or properly nested lists + if ( contained.length > 0 ) { + // Make sure all listitems up the stack are paragraphs + forEach( stack, paragraphify, this); + + last_li.push.apply( last_li, this.toTree( contained, [] ) ); + } + + var next_block = next[0] && next[0].valueOf() || ""; + + if ( next_block.match(is_list_re) || next_block.match( /^ / ) ) { + block = next.shift(); + + // Check for an HR following a list: features/lists/hr_abutting + var hr = this.dialect.block.horizRule( block, next ); + + if ( hr ) { + ret.push.apply(ret, hr); + break; + } + + // Make sure all listitems up the stack are paragraphs + forEach( stack, paragraphify, this); + + loose = true; + continue loose_search; + } + break; + } // loose_search + + return ret; + }; + })(), + + blockquote: function blockquote( block, next ) { + if ( !block.match( /^>/m ) ) + return undefined; + + var jsonml = []; + + // separate out the leading abutting block, if any. I.e. in this case: + // + // a + // > b + // + if ( block[ 0 ] != ">" ) { + var lines = block.split( /\n/ ), + prev = [], + line_no = block.lineNumber; + + // keep shifting lines until you find a crotchet + while ( lines.length && lines[ 0 ][ 0 ] != ">" ) { + prev.push( lines.shift() ); + line_no++; + } + + var abutting = mk_block( prev.join( "\n" ), "\n", block.lineNumber ); + jsonml.push.apply( jsonml, this.processBlock( abutting, [] ) ); + // reassemble new block of just block quotes! + block = mk_block( lines.join( "\n" ), block.trailing, line_no ); + } + + + // if the next block is also a blockquote merge it in + while ( next.length && next[ 0 ][ 0 ] == ">" ) { + var b = next.shift(); + block = mk_block( block + block.trailing + b, b.trailing, block.lineNumber ); + } + + // Strip off the leading "> " and re-process as a block. + var input = block.replace( /^> ?/gm, "" ), + old_tree = this.tree, + processedBlock = this.toTree( input, [ "blockquote" ] ), + attr = extract_attr( processedBlock ); + + // If any link references were found get rid of them + if ( attr && attr.references ) { + delete attr.references; + // And then remove the attribute object if it's empty + if ( isEmpty( attr ) ) { + processedBlock.splice( 1, 1 ); + } + } + + jsonml.push( processedBlock ); + return jsonml; + }, + + referenceDefn: function referenceDefn( block, next) { + var re = /^\s*\[(.*?)\]:\s*(\S+)(?:\s+(?:(['"])(.*?)\3|\((.*?)\)))?\n?/; + // interesting matches are [ , ref_id, url, , title, title ] + + if ( !block.match(re) ) + return undefined; + + // make an attribute node if it doesn't exist + if ( !extract_attr( this.tree ) ) { + this.tree.splice( 1, 0, {} ); + } + + var attrs = extract_attr( this.tree ); + + // make a references hash if it doesn't exist + if ( attrs.references === undefined ) { + attrs.references = {}; + } + + var b = this.loop_re_over_block(re, block, function( m ) { + + if ( m[2] && m[2][0] == "<" && m[2][m[2].length-1] == ">" ) + m[2] = m[2].substring( 1, m[2].length - 1 ); + + var ref = attrs.references[ m[1].toLowerCase() ] = { + href: m[2] + }; + + if ( m[4] !== undefined ) + ref.title = m[4]; + else if ( m[5] !== undefined ) + ref.title = m[5]; + + } ); + + if ( b.length ) + next.unshift( mk_block( b, block.trailing ) ); + + return []; + }, + + para: function para( block, next ) { + // everything's a para! + return [ ["para"].concat( this.processInline( block ) ) ]; + } + } +}; + +Markdown.dialects.Gruber.inline = { + + __oneElement__: function oneElement( text, patterns_or_re, previous_nodes ) { + var m, + res, + lastIndex = 0; + + patterns_or_re = patterns_or_re || this.dialect.inline.__patterns__; + var re = new RegExp( "([\\s\\S]*?)(" + (patterns_or_re.source || patterns_or_re) + ")" ); + + m = re.exec( text ); + if (!m) { + // Just boring text + return [ text.length, text ]; + } + else if ( m[1] ) { + // Some un-interesting text matched. Return that first + return [ m[1].length, m[1] ]; + } + + var res; + if ( m[2] in this.dialect.inline ) { + res = this.dialect.inline[ m[2] ].call( + this, + text.substr( m.index ), m, previous_nodes || [] ); + } + // Default for now to make dev easier. just slurp special and output it. + res = res || [ m[2].length, m[2] ]; + return res; + }, + + __call__: function inline( text, patterns ) { + + var out = [], + res; + + function add(x) { + //D:self.debug(" adding output", uneval(x)); + if ( typeof x == "string" && typeof out[out.length-1] == "string" ) + out[ out.length-1 ] += x; + else + out.push(x); + } + + while ( text.length > 0 ) { + res = this.dialect.inline.__oneElement__.call(this, text, patterns, out ); + text = text.substr( res.shift() ); + forEach(res, add ) + } + + return out; + }, + + // These characters are intersting elsewhere, so have rules for them so that + // chunks of plain text blocks don't include them + "]": function () {}, + "}": function () {}, + + __escape__ : /^\\[\\`\*_{}\[\]()#\+.!\-]/, + + "\\": function escaped( text ) { + // [ length of input processed, node/children to add... ] + // Only esacape: \ ` * _ { } [ ] ( ) # * + - . ! + if ( this.dialect.inline.__escape__.exec( text ) ) + return [ 2, text.charAt( 1 ) ]; + else + // Not an esacpe + return [ 1, "\\" ]; + }, + + "![": function image( text ) { + + // Unlike images, alt text is plain text only. no other elements are + // allowed in there + + // ![Alt text](/path/to/img.jpg "Optional title") + // 1 2 3 4 <--- captures + var m = text.match( /^!\[(.*?)\][ \t]*\([ \t]*([^")]*?)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/ ); + + if ( m ) { + if ( m[2] && m[2][0] == "<" && m[2][m[2].length-1] == ">" ) + m[2] = m[2].substring( 1, m[2].length - 1 ); + + m[2] = this.dialect.inline.__call__.call( this, m[2], /\\/ )[0]; + + var attrs = { alt: m[1], href: m[2] || "" }; + if ( m[4] !== undefined) + attrs.title = m[4]; + + return [ m[0].length, [ "img", attrs ] ]; + } + + // ![Alt text][id] + m = text.match( /^!\[(.*?)\][ \t]*\[(.*?)\]/ ); + + if ( m ) { + // We can't check if the reference is known here as it likely wont be + // found till after. Check it in md tree->hmtl tree conversion + return [ m[0].length, [ "img_ref", { alt: m[1], ref: m[2].toLowerCase(), original: m[0] } ] ]; + } + + // Just consume the '![' + return [ 2, "![" ]; + }, + + "[": function link( text ) { + + var orig = String(text); + // Inline content is possible inside `link text` + var res = Markdown.DialectHelpers.inline_until_char.call( this, text.substr(1), "]" ); + + // No closing ']' found. Just consume the [ + if ( !res ) return [ 1, "[" ]; + + var consumed = 1 + res[ 0 ], + children = res[ 1 ], + link, + attrs; + + // At this point the first [...] has been parsed. See what follows to find + // out which kind of link we are (reference or direct url) + text = text.substr( consumed ); + + // [link text](/path/to/img.jpg "Optional title") + // 1 2 3 <--- captures + // This will capture up to the last paren in the block. We then pull + // back based on if there a matching ones in the url + // ([here](/url/(test)) + // The parens have to be balanced + var m = text.match( /^\s*\([ \t]*([^"']*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/ ); + if ( m ) { + var url = m[1]; + consumed += m[0].length; + + if ( url && url[0] == "<" && url[url.length-1] == ">" ) + url = url.substring( 1, url.length - 1 ); + + // If there is a title we don't have to worry about parens in the url + if ( !m[3] ) { + var open_parens = 1; // One open that isn't in the capture + for ( var len = 0; len < url.length; len++ ) { + switch ( url[len] ) { + case "(": + open_parens++; + break; + case ")": + if ( --open_parens == 0) { + consumed -= url.length - len; + url = url.substring(0, len); + } + break; + } + } + } + + // Process escapes only + url = this.dialect.inline.__call__.call( this, url, /\\/ )[0]; + + attrs = { href: url || "" }; + if ( m[3] !== undefined) + attrs.title = m[3]; + + link = [ "link", attrs ].concat( children ); + return [ consumed, link ]; + } + + // [Alt text][id] + // [Alt text] [id] + m = text.match( /^\s*\[(.*?)\]/ ); + + if ( m ) { + + consumed += m[ 0 ].length; + + // [links][] uses links as its reference + attrs = { ref: ( m[ 1 ] || String(children) ).toLowerCase(), original: orig.substr( 0, consumed ) }; + + link = [ "link_ref", attrs ].concat( children ); + + // We can't check if the reference is known here as it likely wont be + // found till after. Check it in md tree->hmtl tree conversion. + // Store the original so that conversion can revert if the ref isn't found. + return [ consumed, link ]; + } + + // [id] + // Only if id is plain (no formatting.) + if ( children.length == 1 && typeof children[0] == "string" ) { + + attrs = { ref: children[0].toLowerCase(), original: orig.substr( 0, consumed ) }; + link = [ "link_ref", attrs, children[0] ]; + return [ consumed, link ]; + } + + // Just consume the "[" + return [ 1, "[" ]; + }, + + + "<": function autoLink( text ) { + var m; + + if ( ( m = text.match( /^<(?:((https?|ftp|mailto):[^>]+)|(.*?@.*?\.[a-zA-Z]+))>/ ) ) != null ) { + if ( m[3] ) { + return [ m[0].length, [ "link", { href: "mailto:" + m[3] }, m[3] ] ]; + + } + else if ( m[2] == "mailto" ) { + return [ m[0].length, [ "link", { href: m[1] }, m[1].substr("mailto:".length ) ] ]; + } + else + return [ m[0].length, [ "link", { href: m[1] }, m[1] ] ]; + } + + return [ 1, "<" ]; + }, + + "`": function inlineCode( text ) { + // Inline code block. as many backticks as you like to start it + // Always skip over the opening ticks. + var m = text.match( /(`+)(([\s\S]*?)\1)/ ); + + if ( m && m[2] ) + return [ m[1].length + m[2].length, [ "inlinecode", m[3] ] ]; + else { + // TODO: No matching end code found - warn! + return [ 1, "`" ]; + } + }, + + " \n": function lineBreak( text ) { + return [ 3, [ "linebreak" ] ]; + } + +}; + +// Meta Helper/generator method for em and strong handling +function strong_em( tag, md ) { + + var state_slot = tag + "_state", + other_slot = tag == "strong" ? "em_state" : "strong_state"; + + function CloseTag(len) { + this.len_after = len; + this.name = "close_" + md; + } + + return function ( text, orig_match ) { + + if ( this[state_slot][0] == md ) { + // Most recent em is of this type + //D:this.debug("closing", md); + this[state_slot].shift(); + + // "Consume" everything to go back to the recrusion in the else-block below + return[ text.length, new CloseTag(text.length-md.length) ]; + } + else { + // Store a clone of the em/strong states + var other = this[other_slot].slice(), + state = this[state_slot].slice(); + + this[state_slot].unshift(md); + + //D:this.debug_indent += " "; + + // Recurse + var res = this.processInline( text.substr( md.length ) ); + //D:this.debug_indent = this.debug_indent.substr(2); + + var last = res[res.length - 1]; + + //D:this.debug("processInline from", tag + ": ", uneval( res ) ); + + var check = this[state_slot].shift(); + if ( last instanceof CloseTag ) { + res.pop(); + // We matched! Huzzah. + var consumed = text.length - last.len_after; + return [ consumed, [ tag ].concat(res) ]; + } + else { + // Restore the state of the other kind. We might have mistakenly closed it. + this[other_slot] = other; + this[state_slot] = state; + + // We can't reuse the processed result as it could have wrong parsing contexts in it. + return [ md.length, md ]; + } + } + }; // End returned function +} + +Markdown.dialects.Gruber.inline["**"] = strong_em("strong", "**"); +Markdown.dialects.Gruber.inline["__"] = strong_em("strong", "__"); +Markdown.dialects.Gruber.inline["*"] = strong_em("em", "*"); +Markdown.dialects.Gruber.inline["_"] = strong_em("em", "_"); + + +// Build default order from insertion order. +Markdown.buildBlockOrder = function(d) { + var ord = []; + for ( var i in d ) { + if ( i == "__order__" || i == "__call__" ) continue; + ord.push( i ); + } + d.__order__ = ord; +}; + +// Build patterns for inline matcher +Markdown.buildInlinePatterns = function(d) { + var patterns = []; + + for ( var i in d ) { + // __foo__ is reserved and not a pattern + if ( i.match( /^__.*__$/) ) continue; + var l = i.replace( /([\\.*+?|()\[\]{}])/g, "\\$1" ) + .replace( /\n/, "\\n" ); + patterns.push( i.length == 1 ? l : "(?:" + l + ")" ); + } + + patterns = patterns.join("|"); + d.__patterns__ = patterns; + //print("patterns:", uneval( patterns ) ); + + var fn = d.__call__; + d.__call__ = function(text, pattern) { + if ( pattern != undefined ) { + return fn.call(this, text, pattern); + } + else + { + return fn.call(this, text, patterns); + } + }; +}; + +Markdown.DialectHelpers = {}; +Markdown.DialectHelpers.inline_until_char = function( text, want ) { + var consumed = 0, + nodes = []; + + while ( true ) { + if ( text.charAt( consumed ) == want ) { + // Found the character we were looking for + consumed++; + return [ consumed, nodes ]; + } + + if ( consumed >= text.length ) { + // No closing char found. Abort. + return null; + } + + var res = this.dialect.inline.__oneElement__.call(this, text.substr( consumed ) ); + consumed += res[ 0 ]; + // Add any returned nodes. + nodes.push.apply( nodes, res.slice( 1 ) ); + } +} + +// Helper function to make sub-classing a dialect easier +Markdown.subclassDialect = function( d ) { + function Block() {} + Block.prototype = d.block; + function Inline() {} + Inline.prototype = d.inline; + + return { block: new Block(), inline: new Inline() }; +}; + +Markdown.buildBlockOrder ( Markdown.dialects.Gruber.block ); +Markdown.buildInlinePatterns( Markdown.dialects.Gruber.inline ); + +Markdown.dialects.Maruku = Markdown.subclassDialect( Markdown.dialects.Gruber ); + +Markdown.dialects.Maruku.processMetaHash = function processMetaHash( meta_string ) { + var meta = split_meta_hash( meta_string ), + attr = {}; + + for ( var i = 0; i < meta.length; ++i ) { + // id: #foo + if ( /^#/.test( meta[ i ] ) ) { + attr.id = meta[ i ].substring( 1 ); + } + // class: .foo + else if ( /^\./.test( meta[ i ] ) ) { + // if class already exists, append the new one + if ( attr["class"] ) { + attr["class"] = attr["class"] + meta[ i ].replace( /./, " " ); + } + else { + attr["class"] = meta[ i ].substring( 1 ); + } + } + // attribute: foo=bar + else if ( /\=/.test( meta[ i ] ) ) { + var s = meta[ i ].split( /\=/ ); + attr[ s[ 0 ] ] = s[ 1 ]; + } + } + + return attr; +} + +function split_meta_hash( meta_string ) { + var meta = meta_string.split( "" ), + parts = [ "" ], + in_quotes = false; + + while ( meta.length ) { + var letter = meta.shift(); + switch ( letter ) { + case " " : + // if we're in a quoted section, keep it + if ( in_quotes ) { + parts[ parts.length - 1 ] += letter; + } + // otherwise make a new part + else { + parts.push( "" ); + } + break; + case "'" : + case '"' : + // reverse the quotes and move straight on + in_quotes = !in_quotes; + break; + case "\\" : + // shift off the next letter to be used straight away. + // it was escaped so we'll keep it whatever it is + letter = meta.shift(); + default : + parts[ parts.length - 1 ] += letter; + break; + } + } + + return parts; +} + +Markdown.dialects.Maruku.block.document_meta = function document_meta( block, next ) { + // we're only interested in the first block + if ( block.lineNumber > 1 ) return undefined; + + // document_meta blocks consist of one or more lines of `Key: Value\n` + if ( ! block.match( /^(?:\w+:.*\n)*\w+:.*$/ ) ) return undefined; + + // make an attribute node if it doesn't exist + if ( !extract_attr( this.tree ) ) { + this.tree.splice( 1, 0, {} ); + } + + var pairs = block.split( /\n/ ); + for ( p in pairs ) { + var m = pairs[ p ].match( /(\w+):\s*(.*)$/ ), + key = m[ 1 ].toLowerCase(), + value = m[ 2 ]; + + this.tree[ 1 ][ key ] = value; + } + + // document_meta produces no content! + return []; +}; + +Markdown.dialects.Maruku.block.block_meta = function block_meta( block, next ) { + // check if the last line of the block is an meta hash + var m = block.match( /(^|\n) {0,3}\{:\s*((?:\\\}|[^\}])*)\s*\}$/ ); + if ( !m ) return undefined; + + // process the meta hash + var attr = this.dialect.processMetaHash( m[ 2 ] ); + + var hash; + + // if we matched ^ then we need to apply meta to the previous block + if ( m[ 1 ] === "" ) { + var node = this.tree[ this.tree.length - 1 ]; + hash = extract_attr( node ); + + // if the node is a string (rather than JsonML), bail + if ( typeof node === "string" ) return undefined; + + // create the attribute hash if it doesn't exist + if ( !hash ) { + hash = {}; + node.splice( 1, 0, hash ); + } + + // add the attributes in + for ( a in attr ) { + hash[ a ] = attr[ a ]; + } + + // return nothing so the meta hash is removed + return []; + } + + // pull the meta hash off the block and process what's left + var b = block.replace( /\n.*$/, "" ), + result = this.processBlock( b, [] ); + + // get or make the attributes hash + hash = extract_attr( result[ 0 ] ); + if ( !hash ) { + hash = {}; + result[ 0 ].splice( 1, 0, hash ); + } + + // attach the attributes to the block + for ( a in attr ) { + hash[ a ] = attr[ a ]; + } + + return result; +}; + +Markdown.dialects.Maruku.block.definition_list = function definition_list( block, next ) { + // one or more terms followed by one or more definitions, in a single block + var tight = /^((?:[^\s:].*\n)+):\s+([\s\S]+)$/, + list = [ "dl" ], + i, m; + + // see if we're dealing with a tight or loose block + if ( ( m = block.match( tight ) ) ) { + // pull subsequent tight DL blocks out of `next` + var blocks = [ block ]; + while ( next.length && tight.exec( next[ 0 ] ) ) { + blocks.push( next.shift() ); + } + + for ( var b = 0; b < blocks.length; ++b ) { + var m = blocks[ b ].match( tight ), + terms = m[ 1 ].replace( /\n$/, "" ).split( /\n/ ), + defns = m[ 2 ].split( /\n:\s+/ ); + + // print( uneval( m ) ); + + for ( i = 0; i < terms.length; ++i ) { + list.push( [ "dt", terms[ i ] ] ); + } + + for ( i = 0; i < defns.length; ++i ) { + // run inline processing over the definition + list.push( [ "dd" ].concat( this.processInline( defns[ i ].replace( /(\n)\s+/, "$1" ) ) ) ); + } + } + } + else { + return undefined; + } + + return [ list ]; +}; + +// splits on unescaped instances of @ch. If @ch is not a character the result +// can be unpredictable + +Markdown.dialects.Maruku.block.table = function table (block, next) { + + var _split_on_unescaped = function(s, ch) { + ch = ch || '\\s'; + if (ch.match(/^[\\|\[\]{}?*.+^$]$/)) { ch = '\\' + ch; } + var res = [ ], + r = new RegExp('^((?:\\\\.|[^\\\\' + ch + '])*)' + ch + '(.*)'), + m; + while(m = s.match(r)) { + res.push(m[1]); + s = m[2]; + } + res.push(s); + return res; + } + + var leading_pipe = /^ {0,3}\|(.+)\n {0,3}\|\s*([\-:]+[\-| :]*)\n((?:\s*\|.*(?:\n|$))*)(?=\n|$)/, + // find at least an unescaped pipe in each line + no_leading_pipe = /^ {0,3}(\S(?:\\.|[^\\|])*\|.*)\n {0,3}([\-:]+\s*\|[\-| :]*)\n((?:(?:\\.|[^\\|])*\|.*(?:\n|$))*)(?=\n|$)/, + i, m; + if (m = block.match(leading_pipe)) { + // remove leading pipes in contents + // (header and horizontal rule already have the leading pipe left out) + m[3] = m[3].replace(/^\s*\|/gm, ''); + } else if (! ( m = block.match(no_leading_pipe))) { + return undefined; + } + + var table = [ "table", [ "thead", [ "tr" ] ], [ "tbody" ] ]; + + // remove trailing pipes, then split on pipes + // (no escaped pipes are allowed in horizontal rule) + m[2] = m[2].replace(/\|\s*$/, '').split('|'); + + // process alignment + var html_attrs = [ ]; + forEach (m[2], function (s) { + if (s.match(/^\s*-+:\s*$/)) html_attrs.push({align: "right"}); + else if (s.match(/^\s*:-+\s*$/)) html_attrs.push({align: "left"}); + else if (s.match(/^\s*:-+:\s*$/)) html_attrs.push({align: "center"}); + else html_attrs.push({}); + }); + + // now for the header, avoid escaped pipes + m[1] = _split_on_unescaped(m[1].replace(/\|\s*$/, ''), '|'); + for (i = 0; i < m[1].length; i++) { + table[1][1].push(['th', html_attrs[i] || {}].concat( + this.processInline(m[1][i].trim()))); + } + + // now for body contents + forEach (m[3].replace(/\|\s*$/mg, '').split('\n'), function (row) { + var html_row = ['tr']; + row = _split_on_unescaped(row, '|'); + for (i = 0; i < row.length; i++) { + html_row.push(['td', html_attrs[i] || {}].concat(this.processInline(row[i].trim()))); + } + table[2].push(html_row); + }, this); + + return [table]; +} + +Markdown.dialects.Maruku.inline[ "{:" ] = function inline_meta( text, matches, out ) { + if ( !out.length ) { + return [ 2, "{:" ]; + } + + // get the preceeding element + var before = out[ out.length - 1 ]; + + if ( typeof before === "string" ) { + return [ 2, "{:" ]; + } + + // match a meta hash + var m = text.match( /^\{:\s*((?:\\\}|[^\}])*)\s*\}/ ); + + // no match, false alarm + if ( !m ) { + return [ 2, "{:" ]; + } + + // attach the attributes to the preceeding element + var meta = this.dialect.processMetaHash( m[ 1 ] ), + attr = extract_attr( before ); + + if ( !attr ) { + attr = {}; + before.splice( 1, 0, attr ); + } + + for ( var k in meta ) { + attr[ k ] = meta[ k ]; + } + + // cut out the string and replace it with nothing + return [ m[ 0 ].length, "" ]; +}; + +Markdown.dialects.Maruku.inline.__escape__ = /^\\[\\`\*_{}\[\]()#\+.!\-|:]/; + +Markdown.buildBlockOrder ( Markdown.dialects.Maruku.block ); +Markdown.buildInlinePatterns( Markdown.dialects.Maruku.inline ); + +var isArray = Array.isArray || function(obj) { + return Object.prototype.toString.call(obj) == "[object Array]"; +}; + +var forEach; +// Don't mess with Array.prototype. Its not friendly +if ( Array.prototype.forEach ) { + forEach = function( arr, cb, thisp ) { + return arr.forEach( cb, thisp ); + }; +} +else { + forEach = function(arr, cb, thisp) { + for (var i = 0; i < arr.length; i++) { + cb.call(thisp || arr, arr[i], i, arr); + } + } +} + +var isEmpty = function( obj ) { + for ( var key in obj ) { + if ( hasOwnProperty.call( obj, key ) ) { + return false; + } + } + + return true; +} + +function extract_attr( jsonml ) { + return isArray(jsonml) + && jsonml.length > 1 + && typeof jsonml[ 1 ] === "object" + && !( isArray(jsonml[ 1 ]) ) + ? jsonml[ 1 ] + : undefined; +} + + + +/** + * renderJsonML( jsonml[, options] ) -> String + * - jsonml (Array): JsonML array to render to XML + * - options (Object): options + * + * Converts the given JsonML into well-formed XML. + * + * The options currently understood are: + * + * - root (Boolean): wether or not the root node should be included in the + * output, or just its children. The default `false` is to not include the + * root itself. + */ +expose.renderJsonML = function( jsonml, options ) { + options = options || {}; + // include the root element in the rendered output? + options.root = options.root || false; + + var content = []; + + if ( options.root ) { + content.push( render_tree( jsonml ) ); + } + else { + jsonml.shift(); // get rid of the tag + if ( jsonml.length && typeof jsonml[ 0 ] === "object" && !( jsonml[ 0 ] instanceof Array ) ) { + jsonml.shift(); // get rid of the attributes + } + + while ( jsonml.length ) { + content.push( render_tree( jsonml.shift() ) ); + } + } + + return content.join( "\n\n" ); +}; + +function escapeHTML( text ) { + return text.replace( /&/g, "&" ) + .replace( //g, ">" ) + .replace( /"/g, """ ) + .replace( /'/g, "'" ); +} + +function render_tree( jsonml ) { + // basic case + if ( typeof jsonml === "string" ) { + return escapeHTML( jsonml ); + } + + var tag = jsonml.shift(), + attributes = {}, + content = []; + + if ( jsonml.length && typeof jsonml[ 0 ] === "object" && !( jsonml[ 0 ] instanceof Array ) ) { + attributes = jsonml.shift(); + } + + while ( jsonml.length ) { + content.push( render_tree( jsonml.shift() ) ); + } + + var tag_attrs = ""; + for ( var a in attributes ) { + tag_attrs += " " + a + '="' + escapeHTML( attributes[ a ] ) + '"'; + } + + // be careful about adding whitespace here for inline elements + if ( tag == "img" || tag == "br" || tag == "hr" ) { + return "<"+ tag + tag_attrs + "/>"; + } + else { + return "<"+ tag + tag_attrs + ">" + content.join( "" ) + ""; + } +} + +function convert_tree_to_html( tree, references, options ) { + var i; + options = options || {}; + + // shallow clone + var jsonml = tree.slice( 0 ); + + if ( typeof options.preprocessTreeNode === "function" ) { + jsonml = options.preprocessTreeNode(jsonml, references); + } + + // Clone attributes if they exist + var attrs = extract_attr( jsonml ); + if ( attrs ) { + jsonml[ 1 ] = {}; + for ( i in attrs ) { + jsonml[ 1 ][ i ] = attrs[ i ]; + } + attrs = jsonml[ 1 ]; + } + + // basic case + if ( typeof jsonml === "string" ) { + return jsonml; + } + + // convert this node + switch ( jsonml[ 0 ] ) { + case "header": + jsonml[ 0 ] = "h" + jsonml[ 1 ].level; + delete jsonml[ 1 ].level; + break; + case "bulletlist": + jsonml[ 0 ] = "ul"; + break; + case "numberlist": + jsonml[ 0 ] = "ol"; + break; + case "listitem": + jsonml[ 0 ] = "li"; + break; + case "para": + jsonml[ 0 ] = "p"; + break; + case "markdown": + jsonml[ 0 ] = "html"; + if ( attrs ) delete attrs.references; + break; + case "code_block": + jsonml[ 0 ] = "pre"; + i = attrs ? 2 : 1; + var code = [ "code" ]; + code.push.apply( code, jsonml.splice( i, jsonml.length - i ) ); + jsonml[ i ] = code; + break; + case "inlinecode": + jsonml[ 0 ] = "code"; + break; + case "img": + jsonml[ 1 ].src = jsonml[ 1 ].href; + delete jsonml[ 1 ].href; + break; + case "linebreak": + jsonml[ 0 ] = "br"; + break; + case "link": + jsonml[ 0 ] = "a"; + break; + case "link_ref": + jsonml[ 0 ] = "a"; + + // grab this ref and clean up the attribute node + var ref = references[ attrs.ref ]; + + // if the reference exists, make the link + if ( ref ) { + delete attrs.ref; + + // add in the href and title, if present + attrs.href = ref.href; + if ( ref.title ) { + attrs.title = ref.title; + } + + // get rid of the unneeded original text + delete attrs.original; + } + // the reference doesn't exist, so revert to plain text + else { + return attrs.original; + } + break; + case "img_ref": + jsonml[ 0 ] = "img"; + + // grab this ref and clean up the attribute node + var ref = references[ attrs.ref ]; + + // if the reference exists, make the link + if ( ref ) { + delete attrs.ref; + + // add in the href and title, if present + attrs.src = ref.href; + if ( ref.title ) { + attrs.title = ref.title; + } + + // get rid of the unneeded original text + delete attrs.original; + } + // the reference doesn't exist, so revert to plain text + else { + return attrs.original; + } + break; + } + + // convert all the children + i = 1; + + // deal with the attribute node, if it exists + if ( attrs ) { + // if there are keys, skip over it + for ( var key in jsonml[ 1 ] ) { + i = 2; + break; + } + // if there aren't, remove it + if ( i === 1 ) { + jsonml.splice( i, 1 ); + } + } + + for ( ; i < jsonml.length; ++i ) { + jsonml[ i ] = convert_tree_to_html( jsonml[ i ], references, options ); + } + + return jsonml; +} + + +// merges adjacent text nodes into a single node +function merge_text_nodes( jsonml ) { + // skip the tag name and attribute hash + var i = extract_attr( jsonml ) ? 2 : 1; + + while ( i < jsonml.length ) { + // if it's a string check the next item too + if ( typeof jsonml[ i ] === "string" ) { + if ( i + 1 < jsonml.length && typeof jsonml[ i + 1 ] === "string" ) { + // merge the second string into the first and remove it + jsonml[ i ] += jsonml.splice( i + 1, 1 )[ 0 ]; + } + else { + ++i; + } + } + // if it's not a string recurse + else { + merge_text_nodes( jsonml[ i ] ); + ++i; + } + } +} + +} )( (function() { + if ( typeof exports === "undefined" ) { + window.markdown = {}; + return window.markdown; + } + else { + return exports; + } +} )() ); diff --git a/node_modules/markdown/markdown-js.sublime-project b/node_modules/markdown/markdown-js.sublime-project new file mode 100644 index 000000000..8eaf2255d --- /dev/null +++ b/node_modules/markdown/markdown-js.sublime-project @@ -0,0 +1,10 @@ +{ + "folders": + [ + { + "path": "/Users/ash/code/js/markdown-js", + "folder_exclude_patterns": ["node_modules"], + "file_exclude_patterns": ["*.sublime-*"] + } + ] +} diff --git a/node_modules/markdown/markdown-js.sublime-workspace b/node_modules/markdown/markdown-js.sublime-workspace new file mode 100644 index 000000000..6b124716d --- /dev/null +++ b/node_modules/markdown/markdown-js.sublime-workspace @@ -0,0 +1,1993 @@ +{ + "auto_complete": + { + "selected_items": + [ + [ + "di", + "dialects" + ], + [ + "len", + "length-1" + ], + [ + "parsed", + "parsed_nodes" + ], + [ + "pars", + "parsed_ndoes" + ], + [ + "prev", + "previous" + ], + [ + "con", + "console" + ], + [ + "d", + "dialects" + ], + [ + "pat", + "patterns" + ], + [ + "br", + "break" + ], + [ + "inl", + "Inline" + ], + [ + "inlin", + "inline_until_char" + ], + [ + "Di", + "DialectHelpers" + ], + [ + "sub", + "substr" + ], + [ + "last", + "lastIndex" + ], + [ + "open", + "open_brackets" + ], + [ + "bra", + "bracket" + ], + [ + "ope", + "open_brackets" + ], + [ + "prot", + "prototype" + ], + [ + "pa", + "paragraphify" + ], + [ + "debug", + "debugger" + ], + [ + "test", + "testBasePath" + ], + [ + "read", + "readFileSync" + ], + [ + "mk", + "mk_block_toSource" + ], + [ + "u", + "util" + ], + [ + "return", + "return_to" + ], + [ + "retur", + "return_to" + ], + [ + "base64_c", + "base64_decode" + ], + [ + "var", + "variant" + ], + [ + "Produ", + "ProductX" + ], + [ + "publ", + "publishing_tasks" + ], + [ + "use", + "use_hosted_download" + ], + [ + "publi", + "publishing_tasks" + ], + [ + "Var", + "variant_price" + ], + [ + "pr", + "product2" + ], + [ + "pro", + "product1" + ], + [ + "proc", + "product1" + ], + [ + "paypal", + "paypal_account" + ], + [ + "pay", + "paypal_account" + ], + [ + "bala", + "balance_permissions_granted" + ], + [ + "curr", + "current_user" + ], + [ + "masspay", + "masspay_check" + ], + [ + "redirec", + "redirect_to" + ], + [ + "mass", + "masspay_check_users_path" + ], + [ + "cur", + "current_user" + ], + [ + "per", + "perform_masspay_check" + ], + [ + "eq", + "equity_partner_share" + ], + [ + "equi", + "equity_partner_share" + ], + [ + "brok", + "broker" + ], + [ + "broker", + "broker_share" + ], + [ + "affi", + "affiliate_share" + ], + [ + "net", + "network_share" + ], + [ + "cal", + "caclulate_shares" + ], + [ + "aff", + "affiliate" + ], + [ + "to", + "to_split" + ], + [ + "va", + "variant" + ], + [ + "with", + "with_aff_prog" + ], + [ + "purge", + "purge_cache" + ], + [ + "Ipan", + "IpanUpdater" + ], + [ + "send", + "send_user" + ], + [ + "after_c", + "after_commit" + ], + [ + "show", + "shown_in_marketplace" + ], + [ + "C", + "CATEGORIES" + ], + [ + "after", + "after_commit" + ], + [ + "res", + "resque_pid" + ], + [ + "cus", + "custom_params" + ], + [ + "refund", + "refunded" + ], + [ + "assert", + "assert_equal" + ], + [ + "p", + "payment_plans" + ], + [ + "up", + "upsell_without_price" + ], + [ + "list", + "listing" + ], + [ + "su", + "subscriptions" + ], + [ + "padding", + "padding padding-top: length" + ], + [ + "opt", + "optin_condition" + ], + [ + "sale", + "sale_time_condition" + ], + [ + "op", + "optin_condition" + ], + [ + "click", + "click_count_condition" + ], + [ + "sal", + "sale_time_condition" + ], + [ + "by", + "by_listing" + ], + [ + "optin", + "optin_tracking" + ], + [ + "product", + "product_b" + ], + [ + "prod", + "product_a" + ], + [ + "par", + "params" + ], + [ + "sho", + "show_in_marketplace_state" + ], + [ + "lis", + "listing_state" + ], + [ + "dow", + "download" + ], + [ + "valid", + "validate_state_on_published" + ], + [ + "debu", + "debug Break Point" + ], + [ + "upse", + "upsell_id" + ], + [ + "upsell", + "upsell_parent" + ], + [ + "create", + "created_at" + ], + [ + "creat", + "created_at" + ], + [ + "data", + "database" + ], + [ + "render", + "render_template" + ], + [ + "fak", + "fake_p_id_1" + ], + [ + "fake", + "fake_p_id_1" + ], + [ + "update_", + "update_attribute" + ], + [ + "default", + "default_variant" + ], + [ + "frontend", + "frontend_product" + ], + [ + "front", + "frontend_product" + ], + [ + "updat", + "update_ipan" + ], + [ + "deb", + "debugger" + ], + [ + "ass", + "association" + ], + [ + "listing", + "listing_id" + ], + [ + "re", + "release_date" + ], + [ + "ca", + "category" + ], + [ + "uni", + "units_sold" + ], + [ + "am", + "amount" + ], + [ + "co", + "commission" + ], + [ + "Per", + "Percentage" + ], + [ + "variant", + "variants" + ], + [ + "varia", + "variant" + ], + [ + "tra", + "transaction" + ], + [ + "au", + "autoresponder_type" + ], + [ + "aut", + "autoresponder" + ], + [ + "auto", + "autoresponder_type" + ], + [ + "v", + "variants" + ], + [ + "autop", + "autoresponder_id" + ], + [ + "rel", + "release_date" + ], + [ + "upd", + "update_stats" + ], + [ + "ve", + "vendor_earnings" + ], + [ + "ret", + "return_hash" + ], + [ + "vendor", + "vendor_data" + ], + [ + "affili", + "affiliate_data" + ], + [ + "affil", + "affiliate_data" + ], + [ + "trac", + "tracking_codes" + ], + [ + "full", + "full_product_name" + ], + [ + "af", + "after_create" + ], + [ + "shoul", + "should" + ] + ] + }, + "buffers": + [ + { + "file": "lib/markdown.js", + "settings": + { + "buffer_size": 50548, + "line_ending": "Unix" + } + }, + { + "file": "test/features/github/line_breaks.json", + "settings": + { + "buffer_size": 118, + "line_ending": "Unix" + } + }, + { + "file": "test/features/github/no_em_in_word.text", + "settings": + { + "buffer_size": 91, + "line_ending": "Unix" + } + }, + { + "file": "test/features/github/no_em_in_word.json", + "settings": + { + "buffer_size": 183, + "line_ending": "Unix" + } + }, + { + "file": "test/features/github/auto_linking.text", + "settings": + { + "buffer_size": 54, + "line_ending": "Unix" + } + }, + { + "file": "test/features.t.js", + "settings": + { + "buffer_size": 2359, + "line_ending": "Unix" + } + }, + { + "file": "bin/md2html.js", + "settings": + { + "buffer_size": 1064, + "line_ending": "Unix" + } + }, + { + "file": "test/features/emphasis/simple.text", + "settings": + { + "buffer_size": 74, + "line_ending": "Unix" + } + }, + { + "file": "Changes.markdown", + "settings": + { + "buffer_size": 646, + "line_ending": "Unix" + } + }, + { + "file": "package.json", + "settings": + { + "buffer_size": 1338, + "line_ending": "Unix" + } + } + ], + "build_system": "Packages/Ruby/Ruby.sublime-build", + "command_palette": + { + "height": 47.0, + "selected_items": + [ + [ + "newvie", + "File: New View into File" + ], + [ + "pack", + "Package Control: Remove Package" + ], + [ + "view", + "File: New View into File" + ], + [ + "giste", + "GitHub: Open Gist in Editor" + ], + [ + "gist", + "GitHub: Private Gist from Selection" + ], + [ + "ruby", + "Set Syntax: Ruby" + ], + [ + "html", + "Set Syntax: HTML (Rails)" + ], + [ + "syntax", + "Set Syntax: C#" + ], + [ + "php", + "Set Syntax: PHP" + ], + [ + ":w", + ":w - Save" + ], + [ + "trim", + "Snippet: Lorem ipsum" + ], + [ + "py", + "Set Syntax: Python" + ], + [ + "bash", + "Set Syntax: Shell Script (Bash)" + ], + [ + "text", + "Set Syntax: Textile" + ], + [ + "mark", + "Set Syntax: Markdown" + ], + [ + "c#", + "Set Syntax: C#" + ], + [ + "yaml", + "Set Syntax: YAML" + ], + [ + "perl", + "Set Syntax: Perl" + ], + [ + "pl", + "Set Syntax: Plain Text" + ], + [ + "", + "About" + ] + ], + "width": 467.0 + }, + "console": + { + "height": 129.0 + }, + "distraction_free": + { + "menu_visible": true, + "show_minimap": false, + "show_open_files": true, + "show_tabs": false, + "side_bar_visible": false, + "status_bar_visible": false + }, + "file_history": + [ + "/Users/ash/code/js/markdown-js/bin/namp.js", + "/Users/ash/code/js/markdown-js/test/features.t.js", + "/Users/ash/code/js/markdown-js/test/features/github/auto_linking.json", + "/Users/ash/code/js/markdown-js/test/features/meta/leading_whitespace.json", + "/Users/ash/code/js/markdown-js/package.json", + "/Users/ash/code/js/markdown-js/test/features/github/fenced_code_with_lang.text", + "/Users/ash/code/js/markdown-js/test/features/github/fenced_code_with_lang.json", + "/Users/ash/code/js/markdown-js/test/features/github/fenced_code.json", + "/Users/ash/code/js/markdown-js/test/features/code_fences/fenced.text", + "/Users/ash/code/js/markdown-js/test/features/code_fences/fenced.json", + "/Users/ash/code/digiresults/ops/chef/cookbooks/digiresults/templates/default/proxies/manager.erb", + "/Users/ash/code/js/markdown-js/smpl", + "/Users/ash/code/js/markdown-js/test/features/meta/multiple_classes.text", + "/Users/ash/code/js/markdown-js/test/features/meta/multiple_classes.json", + "/Users/ash/code/js/markdown-js/test/regressions.t.js", + "/Users/ash/code/js/markdown-js/Changes.markdown", + "/Users/ash/code/js/markdown-js/test/features/links/implicit.text", + "/Users/ash/code/js/markdown-js/test/features/links/ref_with_image_ref.text", + "/Users/ash/code/js/markdown-js/lib/markdown.js", + "/Users/ash/code/js/markdown-js/test/features/links/ref_with_image_ref.json", + "/Users/ash/code/js/markdown-js/test/interface.t.js", + "/Users/ash/etc/sublime/Packages/User/Distraction Free.sublime-settings", + "/Users/ash/Library/Application Support/Sublime Text 2/Packages/User/Preferences.sublime-settings", + "/Users/ash/code/digiresults/ops/chef/cookbooks/rvm/attributes/default.rb", + "/Users/ash/code/digiresults/ops/chef/cookbooks/rvm/recipes/default.rb", + "/Users/ash/code/js/markdown-js/test/features/links/parens_inline.text", + "/Users/ash/code/js/markdown-js/test/features/links/in_brackets.json", + "/Users/ash/code/js/markdown-js/test/features/links/in_brackets.text", + "/Users/ash/code/js/markdown-js/test/features/images/ref.text", + "/Users/ash/code/js/markdown-js/test/features/images/ref.json", + "/Users/ash/code/js/markdown-js/test/features/meta/list.text", + "/Users/ash/code/js/markdown-js/test/features/meta/list.json", + "/Users/ash/code/js/markdown-js/test/features/meta/class.text", + "/Users/ash/code/js/markdown-js/bin/md2html.js", + "/Users/ash/code/js/markdown-js/README.markdown", + "/Users/ash/code/js/markdown-js/markdown-js.sublime-project", + "/Users/ash/code/js/markdown-js/test/reg_old.js", + "/Users/ash/code/js/markdown-js/t.js", + "/Users/ash/code/js/markdown-js/node_modules/tap/node_modules/deep-equal/index.js", + "/Users/ash/code/js/markdown-js/node_modules/tap/lib/tap-assert.js", + "/Users/ash/code/js/untitled", + "/Users/ash/etc/bash/rc/01.rvm", + "/Users/ash/etc/bash/rc/01.node", + "/Users/ash/etc/rbenv/rbenv.d/rehash/rbx-2.0.0-dev-fix.bash", + "/Users/ash/code/digiresults/manager/Gemfile", + "/Users/ash/etc/rbenv/shims/rake", + "/Users/ash/code/digiresults/manager/test/functional/reports_controller_test.rb", + "/Users/ash/Dropbox/dta_support_snippets.txt", + "/Users/ash/code/digiresults/manager/app/views/manage/_checklist.html.erb", + "/Users/ash/code/digiresults/manager/app/views/manage/listings/publishing/_not_ready.html.erb", + "/Users/ash/code/digiresults/manager/test/unit/user_test.rb", + "/Users/ash/code/digiresults/manager/test/unit/sale_test.rb", + "/Users/ash/code/digiresults/manager/app/models/sale.rb", + "/Users/ash/code/digiresults/manager/app/controllers/manage/variants_controller.rb", + "/Users/ash/code/digiresults/manager/app/views/manage/products/publishing/_not_ready.html.erb", + "/Users/ash/code/digiresults/manager/lib/ipan_updater.rb", + "/Users/ash/code/digiresults/manager/app/models/listing.rb", + "/Users/ash/code/digiresults/manager/app/models/product.rb", + "/Users/ash/code/digiresults/manager/test/unit/product_test.rb", + "/Users/ash/code/digiresults/manager/app/controllers/manage/products_controller.rb", + "/Users/ash/code/digiresults/manager/app/views/manage/products/edit.html.erb", + "/Users/ash/code/digiresults/manager/app/views/manage/listings/edit.html.erb", + "/Users/ash/code/digiresults/manager/app/views/manage/variants/edit.html.erb", + "/Users/ash/code/digiresults/manager/public/javascripts/application.js", + "/Users/ash/code/digiresults/manager/db/migrate/20120402083309_add_share_columns_to_payment_plans.rb", + "/Users/ash/code/digiresults/manager/app/models/variant.rb", + "/Users/ash/code/digiresults/ops/chef/data_bags/apps/ipan.json", + "/Users/ash/code/digiresults/ops/chef/data_bags/apps/manager.json", + "/Users/ash/Sites/cb_test.php", + "/Users/ash/Sites/decode.php", + "/Users/ash/Downloads/Functions.php", + "/Users/ash/code/digiresults/manager/app/views/manage/products/publishing/_ready.html.erb", + "/Users/ash/code/digiresults/manager/config/locales/en.yml", + "/Users/ash/code/digiresults/manager/app/controllers/manage/listings_controller.rb", + "/Users/ash/code/digiresults/manager/app/helpers/application_helper.rb", + "/Users/ash/code/digiresults/manager/test/unit/ipan_updater_test.rb", + "/Users/ash/code/digiresults/manager/db/migrate/20120329211108_add_fee_discount_to_users.rb", + "/Users/ash/code/digiresults/manager/app/models/user.rb", + "/Users/ash/code/digiresults/manager/db/migrate/20120320103301_move_products_into_upsell_chains.rb", + "/Users/ash/code/digiresults/manager/app/models/discount_code.rb", + "/Users/ash/code/digiresults/manager/lib/price_attributes.rb", + "/Users/ash/code/digiresults/manager/test/unit/variant_test.rb", + "/Users/ash/code/digiresults/manager/test/unit/discount_code_test.rb", + "/Users/ash/code/digiresults/manager/test/functional/manage/discount_codes_controller_test.rb", + "/Users/ash/code/digiresults/manager/app/views/manage/listings/show.html.erb", + "/Users/ash/code/digiresults/manager/app/views/listings/_product.html.erb", + "/Users/ash/code/digiresults/manager/app/views/user_mailer/suspended_refund_failed.text.erb", + "/Users/ash/code/digiresults/manager/app/controllers/users_controller.rb", + "/Users/ash/code/digiresults/manager/test/functional/users_controller_test.rb", + "/Users/ash/Library/Application Support/Sublime Text 2/Packages/Default/Preferences.sublime-settings", + "/Users/ash/code/digiresults/manager/lib/pay_pal.rb", + "/Users/ash/code/digiresults/manager/app/views/users/masspay_check.html.erb", + "/Users/ash/code/digiresults/manager/config/routes.rb", + "/Users/ash/code/digiresults/manager/test/unit/paypal_test.rb", + "/Users/ash/code/digiresults/manager/public/stylesheets/bootstrap.min.css", + "/Users/ash/code/digiresults/manager/app/controllers/sessions_controller.rb", + "/Users/ash/code/digiresults/manager/app/views/users/subscription_permissions.html.erb", + "/Users/ash/code/digiresults/manager/test/factories/payment_plan.rb", + "/Users/ash/code/digiresults/manager/test/functional/api/ipan_v1_payment_plans_controller_test.rb", + "/Users/ash/code/digiresults/manager/app/models/payment_plan.rb", + "/Users/ash/code/digiresults/ipan/lib/prices.rb", + "/Users/ash/.gitconfig", + "/Users/ash/code/digiresults/manager/app/controllers/users/affiliate_programs_controller.rb", + "/Users/ash/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.4/lib/active_record/transactions.rb", + "/Users/ash/code/digiresults/manager/app/controllers/manage/discount_codes_controller.rb", + "/Users/ash/code/digiresults/manager/db/migrate/20120329211108_add_fee_discount_to_variants.rb", + "/Users/ash/code/digiresults/manager/app/views/manage/variants/_price.html.erb", + "/Users/ash/code/digiresults/manager/Rakefile", + "/Users/ash/code/digiresults/manager/test/factories/discount_code.rb", + "/Users/ash/code/digiresults/manager/tmp/cache/ipan:products/0/29.cache", + "/Users/ash/code/digiresults/manager/config/environments/test.rb", + "/Users/ash/code/digiresults/manager/app/controllers/api/ipan/v2/products_controller.rb", + "/Users/ash/code/digiresults/manager/app/controllers/api/ipan/v2/users_controller.rb", + "/Users/ash/code/digiresults/manager/app/controllers/api/ipan/v1/users_controller.rb", + "/Users/ash/code/digiresults/manager/app/controllers/api/ipan/v1/products_controller.rb", + "/Users/ash/code/digiresults/manager/test/functional/api/ipan_v2_users_controller_test.rb", + "/Users/ash/code/digiresults/manager/test/functional/api/ipan_v2_products_controller_test.rb", + "/Users/ash/code/digiresults/manager/config/database.yml", + "/Users/ash/code/digiresults/ops/chef/cookbooks/application/recipes/resque-worker.rb", + "/Users/ash/code/digiresults/manager/app/controllers/application_controller.rb", + "/Users/ash/code/digiresults/manager/test/functional/api/ipan_v1_users_controller_test.rb", + "/Users/ash/code/digiresults/manager/test/functional/api/ipan_v1_products_controller_test.rb", + "/Users/ash/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/cache.rb", + "/Users/ash/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/cache/file_store.rb", + "/Users/ash/code/digiresults/manager/config/environment.rb", + "/Users/ash/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.4/lib/active_support/cache/strategy/local_cache.rb", + "/Users/ash/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.4/lib/rails.rb", + "/Users/ash/code/digiresults/manager/test/test_helper.rb" + ], + "find": + { + "height": 33.0 + }, + "find_in_files": + { + "height": 0.0, + "where_history": + [ + "" + ] + }, + "find_state": + { + "case_sensitive": false, + "find_history": + [ + "debugger", + "parsed_ndoes", + "Markdown.dialects.Gruber", + "strong_em", + "count_l", + "merge_text_nodes", + "buildin", + "i", + "some", + "process_meta_hash", + "split_meta_hash", + "process_met", + "debugger", + "/manage", + "Maruku", + "debugger", + "original", + "attr", + "conact", + "console.log", + "debugger", + "concat", + "link", + "children", + "out", + "patterns_or_re", + "inline", + "m", + "patterns_or_re", + ",", + "escape", + "))))", + "open_brackets", + "m[2]", + "attrs = { href", + "text", + "img_ref", + "link_ref", + "img_ref", + "img", + "img_ref", + "img_reg", + "ref", + "reg", + "\"\\\\\"", + "__call__", + "link", + "forEach", + ".length", + "paragraphify", + "isArray", + "for ( var i", + "stack", + "isArray", + "<<<", + "lists", + "parentDi", + "debugger", + "parentDialect", + "parent", + "Maruku", + "\"list:\"", + "extract_attr", + "custom_tree", + "toTree", + "block = ", + "console.", + "console.log", + "debug_in", + "console.log", + "Gruber", + ".block", + "Gruber.block", + "block_meta", + "depen", + "Gruber", + "dialect", + "scripts", + "// End retu", + "<<<", + "testBaseName", + "Name", + "testBaeName", + "testName", + "t", + "testBasePath", + "test_path", + "path", + "test_path + tests[ t ]", + "test_name", + "isfile", + "( t, md )", + "(md)", + "asserts.same", + "dialect", + "asserts.same", + "toSource", + "diff", + "stringify", + "caller", + "asserts.deepEqual", + "same", + "meta", + "rbenv_dir", + "pending_execution?", + "pending", + "salt", + "Reorder", + "comlete", + ":sales_page", + "variant", + "task", + "listing", + "fee_multiplier", + " ] = ", + "fee_m", + "fee", + "fee_mul", + "fee_multi", + "auto_", + ":paypal_chang", + "paypal_change", + "change_paypal", + "change_to", + "when changing the paypal account", + "chang", + "payer_id", + "current_user" + ], + "highlight": true, + "in_selection": false, + "preserve_case": false, + "regex": false, + "replace_history": + [ + "\n", + "@listing.", + "product", + ".email", + ":payment_type => 'subscription'", + "***", + "#", + "broker_commission", + "tier_2_commission", + "affiliate", + "network", + "", + "refunds_count", + "affiliate_earnings", + "clicks_count", + "affiliate_earnings", + "clicks_count", + "refunds_count" + ], + "reverse": false, + "show_context": true, + "use_buffer2": true, + "whole_word": false, + "wrap": true + }, + "groups": + [ + { + "selected": 12, + "sheets": + [ + { + "buffer": 0, + "file": "lib/markdown.js", + "settings": + { + "buffer_size": 50548, + "regions": + { + }, + "selection": + [ + [ + 42874, + 42874 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JavaScript.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 21357.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 1, + "file": "test/features/github/line_breaks.json", + "settings": + { + "buffer_size": 118, + "regions": + { + }, + "selection": + [ + [ + 106, + 106 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JSON.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 2, + "file": "test/features/github/no_em_in_word.text", + "settings": + { + "buffer_size": 91, + "regions": + { + }, + "selection": + [ + [ + 68, + 36 + ] + ], + "settings": + { + "syntax": "Packages/Text/Plain text.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 3, + "file": "test/features/github/no_em_in_word.json", + "settings": + { + "buffer_size": 183, + "regions": + { + }, + "selection": + [ + [ + 183, + 183 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JSON.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 4, + "file": "test/features/github/auto_linking.text", + "settings": + { + "buffer_size": 54, + "regions": + { + }, + "selection": + [ + [ + 54, + 54 + ] + ], + "settings": + { + "syntax": "Packages/Text/Plain text.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 5, + "file": "test/features.t.js", + "settings": + { + "buffer_size": 2359, + "regions": + { + }, + "selection": + [ + [ + 1987, + 1987 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JavaScript.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 618.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 6, + "file": "bin/md2html.js", + "settings": + { + "buffer_size": 1064, + "regions": + { + }, + "selection": + [ + [ + 724, + 724 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JavaScript.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 7, + "file": "test/features/emphasis/simple.text", + "settings": + { + "buffer_size": 74, + "regions": + { + }, + "selection": + [ + [ + 0, + 0 + ] + ], + "settings": + { + "syntax": "Packages/Text/Plain text.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 0, + "file": "lib/markdown.js", + "settings": + { + "buffer_size": 50548, + "regions": + { + }, + "selection": + [ + [ + 32816, + 32816 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JavaScript.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 16317.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 6, + "file": "bin/md2html.js", + "settings": + { + "buffer_size": 1064, + "regions": + { + }, + "selection": + [ + [ + 492, + 492 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JavaScript.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 2, + "file": "test/features/github/no_em_in_word.text", + "settings": + { + "buffer_size": 91, + "regions": + { + }, + "selection": + [ + [ + 72, + 72 + ] + ], + "settings": + { + "syntax": "Packages/Text/Plain text.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 3, + "file": "test/features/github/no_em_in_word.json", + "settings": + { + "buffer_size": 183, + "regions": + { + }, + "selection": + [ + [ + 0, + 0 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JSON.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 8, + "file": "Changes.markdown", + "settings": + { + "buffer_size": 646, + "regions": + { + }, + "selection": + [ + [ + 0, + 0 + ] + ], + "settings": + { + "spell_check": true, + "syntax": "Packages/Markdown/Markdown.tmLanguage" + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + }, + { + "buffer": 9, + "file": "package.json", + "settings": + { + "buffer_size": 1338, + "regions": + { + }, + "selection": + [ + [ + 45, + 45 + ] + ], + "settings": + { + "syntax": "Packages/JavaScript/JSON.tmLanguage", + "tab_size": 2, + "translate_tabs_to_spaces": true + }, + "translation.x": 0.0, + "translation.y": 0.0, + "zoom_level": 1.0 + }, + "type": "text" + } + ] + } + ], + "incremental_find": + { + "height": 32.0 + }, + "input": + { + "height": 29.0 + }, + "layout": + { + "cells": + [ + [ + 0, + 0, + 1, + 1 + ] + ], + "cols": + [ + 0.0, + 1.0 + ], + "rows": + [ + 0.0, + 1.0 + ] + }, + "menu_visible": true, + "replace": + { + "height": 62.0 + }, + "save_all_on_build": true, + "select_file": + { + "height": 0.0, + "selected_items": + [ + [ + "pack", + "package.json" + ], + [ + "changes", + "Changes.markdown" + ], + [ + "noemjson", + "test/features/github/no_em_in_word.json" + ], + [ + "eminwojso", + "test/features/github/no_em_in_word.json" + ], + [ + "emin", + "test/features/github/no_em_in_word.text" + ], + [ + "mark", + "lib/markdown.js" + ], + [ + "", + "test/features/github/no_em_in_word.json" + ], + [ + "emsimpletext", + "test/features/emphasis/simple.text" + ], + [ + "feature", + "test/features.t.js" + ], + [ + "md2", + "bin/md2html.js" + ], + [ + "featu", + "test/features.t.js" + ], + [ + "namp", + "bin/namp.js" + ], + [ + "metalead", + "test/features/meta/leading_whitespace.json" + ], + [ + "pac", + "package.json" + ], + [ + "fenced", + "test/features/github/fenced_code.json" + ], + [ + "smp", + "smpl" + ], + [ + "metamult", + "test/features/meta/multiple_classes.text" + ], + [ + "metamu", + "test/features/meta/multiple_classes.json" + ], + [ + "regre", + "test/regressions.t.js" + ], + [ + "cha", + "Changes.markdown" + ], + [ + "refwithim", + "test/features/links/ref_with_image_ref.json" + ], + [ + "linkimpl", + "test/features/links/implicit.text" + ], + [ + "int", + "test/interface.t.js" + ], + [ + "refwithimage", + "test/features/links/ref_with_image_ref.text" + ], + [ + "linkpareinlin", + "test/features/links/parens_inline.text" + ], + [ + "regres", + "test/regressions.t.js" + ], + [ + "imageref", + "test/features/images/ref.text" + ], + [ + "metalistjs", + "test/features/meta/list.json" + ], + [ + "metalist", + "test/features/meta/list.text" + ], + [ + "fea", + "test/features.t.js" + ], + [ + "read", + "README.markdown" + ], + [ + "feat", + "test/features.t.js" + ], + [ + "packa", + "package.json" + ], + [ + "testunsalte", + "test/unit/sale_test.rb" + ], + [ + "usertest", + "test/unit/user_test.rb" + ], + [ + "reportconttest", + "test/functional/reports_controller_test.rb" + ], + [ + "appmodesal", + "app/models/sale.rb" + ], + [ + "saletest", + "test/unit/sale_test.rb" + ], + [ + "testunuser", + "test/unit/user_test.rb" + ], + [ + "gem", + "Gemfile" + ], + [ + "user.r", + "app/models/user.rb" + ], + [ + "_check", + "app/views/manage/_checklist.html.erb" + ], + [ + "manaprod", + "app/controllers/manage/products_controller.rb" + ], + [ + "manvarcont", + "app/controllers/manage/variants_controller.rb" + ], + [ + "checkli", + "app/views/manage/_checklist.html.erb" + ], + [ + "ipanupd", + "lib/ipan_updater.rb" + ], + [ + "appjs", + "public/javascripts/application.js" + ], + [ + "listpublinotr", + "app/views/manage/listings/publishing/_not_ready.html.erb" + ], + [ + "testunprod", + "test/unit/product_test.rb" + ], + [ + "120402083309_add_share_columns_to_paym", + "db/migrate/20120402083309_add_share_columns_to_payment_plans.rb" + ], + [ + "var", + "app/models/variant.rb" + ], + [ + "modlist", + "app/models/listing.rb" + ], + [ + "modprod", + "app/models/product.rb" + ], + [ + "produtest", + "test/unit/product_test.rb" + ], + [ + "apphelpe", + "app/helpers/application_helper.rb" + ], + [ + "isting", + "app/models/listing.rb" + ], + [ + "manproductcont", + "app/controllers/manage/products_controller.rb" + ], + [ + "en.", + "config/locales/en.yml" + ], + [ + "modlisting", + "app/models/listing.rb" + ], + [ + "notread", + "app/views/manage/products/publishing/_not_ready.html.erb" + ], + [ + "listingnotread", + "app/views/manage/listings/publishing/_not_ready.html.erb" + ], + [ + "manlistincont", + "app/controllers/manage/listings_controller.rb" + ], + [ + "ipanupdatete", + "test/unit/ipan_updater_test.rb" + ], + [ + "pricea", + "lib/price_attributes.rb" + ], + [ + "disco", + "app/models/discount_code.rb" + ], + [ + "teundisccodete", + "test/unit/discount_code_test.rb" + ], + [ + "disccontest", + "test/functional/manage/discount_codes_controller_test.rb" + ], + [ + "vartest", + "test/unit/variant_test.rb" + ], + [ + "listinshow", + "app/views/manage/listings/show.html.erb" + ], + [ + "ipanup", + "lib/ipan_updater.rb" + ], + [ + "testunvartest", + "test/unit/variant_test.rb" + ], + [ + "user.rb", + "app/models/user.rb" + ], + [ + "20120329211108_add_fee_discount_to_variants.rb", + "db/migrate/20120329211108_add_fee_discount_to_variants.rb" + ], + [ + "refund", + "app/views/user_mailer/suspended_refund_failed.text.erb" + ], + [ + "en.yml", + "config/locales/en.yml" + ], + [ + "appmoduser", + "app/models/user.rb" + ], + [ + "apphelp", + "app/helpers/application_helper.rb" + ], + [ + "sesscon", + "app/controllers/sessions_controller.rb" + ], + [ + "testunpayp", + "test/unit/paypal_test.rb" + ], + [ + "bootstr", + "public/stylesheets/bootstrap.min.css" + ], + [ + "routes", + "config/routes.rb" + ], + [ + "usersconttest", + "test/functional/users_controller_test.rb" + ], + [ + "appviewsubper", + "app/views/users/subscription_permissions.html.erb" + ], + [ + "usercontr", + "app/controllers/users_controller.rb" + ], + [ + "list", + "app/models/listing.rb" + ], + [ + "appmodsale", + "app/models/sale.rb" + ], + [ + "payp", + "lib/pay_pal.rb" + ], + [ + "testfacpay", + "test/factories/payment_plan.rb" + ], + [ + "testpayplan", + "test/functional/api/ipan_v1_payment_plans_controller_test.rb" + ], + [ + "modesale", + "app/models/sale.rb" + ], + [ + "modelplan", + "app/models/payment_plan.rb" + ], + [ + "useraffpro", + "app/controllers/users/affiliate_programs_controller.rb" + ], + [ + "tesunidisc", + "test/unit/discount_code_test.rb" + ], + [ + "managdiscount", + "app/controllers/manage/discount_codes_controller.rb" + ], + [ + "appviewvarpri", + "app/views/manage/variants/_price.html.erb" + ], + [ + "rake", + "Rakefile" + ], + [ + "testfacdis", + "test/factories/discount_code.rb" + ], + [ + "discontest", + "test/unit/discount_code_test.rb" + ], + [ + "disc", + "app/models/discount_code.rb" + ], + [ + "29", + "tmp/cache/ipan:products/0/29.cache" + ], + [ + "moddiscount", + "app/models/discount_code.rb" + ], + [ + "modvar", + "app/models/variant.rb" + ], + [ + "appcont", + "app/controllers/application_controller.rb" + ], + [ + "data", + "config/database.yml" + ], + [ + "confroutes", + "config/routes.rb" + ], + [ + "envtest", + "config/environments/test.rb" + ], + [ + "appmodprod", + "app/models/product.rb" + ], + [ + "testipan", + "test/unit/ipan_updater_test.rb" + ], + [ + "ipanproducts", + "app/controllers/api/ipan/v1/products_controller.rb" + ], + [ + "test/functional/api/ipan_v1_users_controller_test.rb", + "test/functional/api/ipan_v1_users_controller_test.rb" + ], + [ + "testunprodte", + "test/unit/product_test.rb" + ], + [ + "ipaupdatest", + "test/unit/ipan_updater_test.rb" + ], + [ + "conenv", + "config/environment.rb" + ], + [ + "modediscou", + "app/models/discount_code.rb" + ], + [ + "apiuserscont", + "app/controllers/api/ipan/v1/users_controller.rb" + ], + [ + "testhelp", + "test/test_helper.rb" + ], + [ + "testfuncmanagaffcontest", + "test/functional/manage/affiliates_controller_test.rb" + ], + [ + "test/unit/listing_test.rb", + "test/unit/listing_test.rb" + ], + [ + "teshe", + "test/test_helper.rb" + ], + [ + "apviewusermailapp", + "app/views/user_mailer/affiliate_approved.text.erb" + ], + [ + "affproguser", + "app/models/affiliate_program_user.rb" + ], + [ + "modelaffprog", + "app/models/affiliate_program.rb" + ], + [ + "appmodlist", + "app/models/listing.rb" + ], + [ + "appmodaffprouser", + "app/models/affiliate_program_user.rb" + ], + [ + "appmailusermail", + "app/mailers/user_mailer.rb" + ], + [ + "testmarkcont", + "test/functional/marketplace_controller_test.rb" + ], + [ + "markp", + "app/controllers/marketplace_controller.rb" + ], + [ + "markcont", + "app/controllers/marketplace_controller.rb" + ] + ], + "width": 0.0 + }, + "select_project": + { + "height": 500.0, + "selected_items": + [ + [ + "", + "/Users/ash/Documents/sublime-projects/manager.sublime-project" + ], + [ + "ipan", + "/Users/ash/Documents/sublime-projects/ipan.sublime-project" + ], + [ + "dab", + "/Users/ash/Documents/sublime-projects/digiarticleblaster.sublime-project" + ], + [ + "ip", + "/Users/ash/Documents/sublime-projects/ipan.sublime-project" + ], + [ + "ipa", + "/Users/ash/Documents/sublime-projects/ipan.sublime-project" + ], + [ + "mn", + "/Users/ash/Documents/manager.sublime-project" + ] + ], + "width": 380.0 + }, + "show_minimap": true, + "show_open_files": false, + "show_tabs": true, + "side_bar_visible": true, + "side_bar_width": 218.0, + "status_bar_visible": true +} diff --git a/node_modules/markdown/node_modules/.bin/nopt b/node_modules/markdown/node_modules/.bin/nopt new file mode 120000 index 000000000..6b6566ea7 --- /dev/null +++ b/node_modules/markdown/node_modules/.bin/nopt @@ -0,0 +1 @@ +../nopt/bin/nopt.js \ No newline at end of file diff --git a/node_modules/markdown/node_modules/nopt/.npmignore b/node_modules/markdown/node_modules/nopt/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/markdown/node_modules/nopt/LICENSE b/node_modules/markdown/node_modules/nopt/LICENSE new file mode 100644 index 000000000..05a401094 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/LICENSE @@ -0,0 +1,23 @@ +Copyright 2009, 2010, 2011 Isaac Z. Schlueter. +All rights reserved. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/markdown/node_modules/nopt/README.md b/node_modules/markdown/node_modules/nopt/README.md new file mode 100644 index 000000000..f290da8f4 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/README.md @@ -0,0 +1,210 @@ +If you want to write an option parser, and have it be good, there are +two ways to do it. The Right Way, and the Wrong Way. + +The Wrong Way is to sit down and write an option parser. We've all done +that. + +The Right Way is to write some complex configurable program with so many +options that you go half-insane just trying to manage them all, and put +it off with duct-tape solutions until you see exactly to the core of the +problem, and finally snap and write an awesome option parser. + +If you want to write an option parser, don't write an option parser. +Write a package manager, or a source control system, or a service +restarter, or an operating system. You probably won't end up with a +good one of those, but if you don't give up, and you are relentless and +diligent enough in your procrastination, you may just end up with a very +nice option parser. + +## USAGE + + // my-program.js + var nopt = require("nopt") + , Stream = require("stream").Stream + , path = require("path") + , knownOpts = { "foo" : [String, null] + , "bar" : [Stream, Number] + , "baz" : path + , "bloo" : [ "big", "medium", "small" ] + , "flag" : Boolean + , "pick" : Boolean + , "many" : [String, Array] + } + , shortHands = { "foofoo" : ["--foo", "Mr. Foo"] + , "b7" : ["--bar", "7"] + , "m" : ["--bloo", "medium"] + , "p" : ["--pick"] + , "f" : ["--flag"] + } + // everything is optional. + // knownOpts and shorthands default to {} + // arg list defaults to process.argv + // slice defaults to 2 + , parsed = nopt(knownOpts, shortHands, process.argv, 2) + console.log(parsed) + +This would give you support for any of the following: + +```bash +$ node my-program.js --foo "blerp" --no-flag +{ "foo" : "blerp", "flag" : false } + +$ node my-program.js ---bar 7 --foo "Mr. Hand" --flag +{ bar: 7, foo: "Mr. Hand", flag: true } + +$ node my-program.js --foo "blerp" -f -----p +{ foo: "blerp", flag: true, pick: true } + +$ node my-program.js -fp --foofoo +{ foo: "Mr. Foo", flag: true, pick: true } + +$ node my-program.js --foofoo -- -fp # -- stops the flag parsing. +{ foo: "Mr. Foo", argv: { remain: ["-fp"] } } + +$ node my-program.js --blatzk 1000 -fp # unknown opts are ok. +{ blatzk: 1000, flag: true, pick: true } + +$ node my-program.js --blatzk true -fp # but they need a value +{ blatzk: true, flag: true, pick: true } + +$ node my-program.js --no-blatzk -fp # unless they start with "no-" +{ blatzk: false, flag: true, pick: true } + +$ node my-program.js --baz b/a/z # known paths are resolved. +{ baz: "/Users/isaacs/b/a/z" } + +# if Array is one of the types, then it can take many +# values, and will always be an array. The other types provided +# specify what types are allowed in the list. + +$ node my-program.js --many 1 --many null --many foo +{ many: ["1", "null", "foo"] } + +$ node my-program.js --many foo +{ many: ["foo"] } +``` + +Read the tests at the bottom of `lib/nopt.js` for more examples of +what this puppy can do. + +## Types + +The following types are supported, and defined on `nopt.typeDefs` + +* String: A normal string. No parsing is done. +* path: A file system path. Gets resolved against cwd if not absolute. +* url: A url. If it doesn't parse, it isn't accepted. +* Number: Must be numeric. +* Date: Must parse as a date. If it does, and `Date` is one of the options, + then it will return a Date object, not a string. +* Boolean: Must be either `true` or `false`. If an option is a boolean, + then it does not need a value, and its presence will imply `true` as + the value. To negate boolean flags, do `--no-whatever` or `--whatever + false` +* NaN: Means that the option is strictly not allowed. Any value will + fail. +* Stream: An object matching the "Stream" class in node. Valuable + for use when validating programmatically. (npm uses this to let you + supply any WriteStream on the `outfd` and `logfd` config options.) +* Array: If `Array` is specified as one of the types, then the value + will be parsed as a list of options. This means that multiple values + can be specified, and that the value will always be an array. + +If a type is an array of values not on this list, then those are +considered valid values. For instance, in the example above, the +`--bloo` option can only be one of `"big"`, `"medium"`, or `"small"`, +and any other value will be rejected. + +When parsing unknown fields, `"true"`, `"false"`, and `"null"` will be +interpreted as their JavaScript equivalents, and numeric values will be +interpreted as a number. + +You can also mix types and values, or multiple types, in a list. For +instance `{ blah: [Number, null] }` would allow a value to be set to +either a Number or null. When types are ordered, this implies a +preference, and the first type that can be used to properly interpret +the value will be used. + +To define a new type, add it to `nopt.typeDefs`. Each item in that +hash is an object with a `type` member and a `validate` method. The +`type` member is an object that matches what goes in the type list. The +`validate` method is a function that gets called with `validate(data, +key, val)`. Validate methods should assign `data[key]` to the valid +value of `val` if it can be handled properly, or return boolean +`false` if it cannot. + +You can also call `nopt.clean(data, types, typeDefs)` to clean up a +config object and remove its invalid properties. + +## Error Handling + +By default, nopt outputs a warning to standard error when invalid +options are found. You can change this behavior by assigning a method +to `nopt.invalidHandler`. This method will be called with +the offending `nopt.invalidHandler(key, val, types)`. + +If no `nopt.invalidHandler` is assigned, then it will console.error +its whining. If it is assigned to boolean `false` then the warning is +suppressed. + +## Abbreviations + +Yes, they are supported. If you define options like this: + +```javascript +{ "foolhardyelephants" : Boolean +, "pileofmonkeys" : Boolean } +``` + +Then this will work: + +```bash +node program.js --foolhar --pil +node program.js --no-f --pileofmon +# etc. +``` + +## Shorthands + +Shorthands are a hash of shorter option names to a snippet of args that +they expand to. + +If multiple one-character shorthands are all combined, and the +combination does not unambiguously match any other option or shorthand, +then they will be broken up into their constituent parts. For example: + +```json +{ "s" : ["--loglevel", "silent"] +, "g" : "--global" +, "f" : "--force" +, "p" : "--parseable" +, "l" : "--long" +} +``` + +```bash +npm ls -sgflp +# just like doing this: +npm ls --loglevel silent --global --force --long --parseable +``` + +## The Rest of the args + +The config object returned by nopt is given a special member called +`argv`, which is an object with the following fields: + +* `remain`: The remaining args after all the parsing has occurred. +* `original`: The args as they originally appeared. +* `cooked`: The args after flags and shorthands are expanded. + +## Slicing + +Node programs are called with more or less the exact argv as it appears +in C land, after the v8 and node-specific options have been plucked off. +As such, `argv[0]` is always `node` and `argv[1]` is always the +JavaScript program being run. + +That's usually not very useful to you. So they're sliced off by +default. If you want them, then you can pass in `0` as the last +argument, or any other number that you'd like to slice off the start of +the list. diff --git a/node_modules/markdown/node_modules/nopt/bin/nopt.js b/node_modules/markdown/node_modules/nopt/bin/nopt.js new file mode 100755 index 000000000..30e9fdbab --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/bin/nopt.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node +var nopt = require("../lib/nopt") + , types = { num: Number + , bool: Boolean + , help: Boolean + , list: Array + , "num-list": [Number, Array] + , "str-list": [String, Array] + , "bool-list": [Boolean, Array] + , str: String + , clear: Boolean + , config: Boolean + , length: Number + } + , shorthands = { s: [ "--str", "astring" ] + , b: [ "--bool" ] + , nb: [ "--no-bool" ] + , tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ] + , "?": ["--help"] + , h: ["--help"] + , H: ["--help"] + , n: [ "--num", "125" ] + , c: ["--config"] + , l: ["--length"] + } + , parsed = nopt( types + , shorthands + , process.argv + , 2 ) + +console.log("parsed", parsed) + +if (parsed.help) { + console.log("") + console.log("nopt cli tester") + console.log("") + console.log("types") + console.log(Object.keys(types).map(function M (t) { + var type = types[t] + if (Array.isArray(type)) { + return [t, type.map(function (type) { return type.name })] + } + return [t, type && type.name] + }).reduce(function (s, i) { + s[i[0]] = i[1] + return s + }, {})) + console.log("") + console.log("shorthands") + console.log(shorthands) +} diff --git a/node_modules/markdown/node_modules/nopt/examples/my-program.js b/node_modules/markdown/node_modules/nopt/examples/my-program.js new file mode 100755 index 000000000..142447e18 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/examples/my-program.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node + +//process.env.DEBUG_NOPT = 1 + +// my-program.js +var nopt = require("../lib/nopt") + , Stream = require("stream").Stream + , path = require("path") + , knownOpts = { "foo" : [String, null] + , "bar" : [Stream, Number] + , "baz" : path + , "bloo" : [ "big", "medium", "small" ] + , "flag" : Boolean + , "pick" : Boolean + } + , shortHands = { "foofoo" : ["--foo", "Mr. Foo"] + , "b7" : ["--bar", "7"] + , "m" : ["--bloo", "medium"] + , "p" : ["--pick"] + , "f" : ["--flag", "true"] + , "g" : ["--flag"] + , "s" : "--flag" + } + // everything is optional. + // knownOpts and shorthands default to {} + // arg list defaults to process.argv + // slice defaults to 2 + , parsed = nopt(knownOpts, shortHands, process.argv, 2) + +console.log("parsed =\n"+ require("util").inspect(parsed)) diff --git a/node_modules/markdown/node_modules/nopt/lib/nopt.js b/node_modules/markdown/node_modules/nopt/lib/nopt.js new file mode 100644 index 000000000..20f3b5b1d --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/lib/nopt.js @@ -0,0 +1,612 @@ +// info about each config option. + +var debug = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG + ? function () { console.error.apply(console, arguments) } + : function () {} + +var url = require("url") + , path = require("path") + , Stream = require("stream").Stream + , abbrev = require("abbrev") + +module.exports = exports = nopt +exports.clean = clean + +exports.typeDefs = + { String : { type: String, validate: validateString } + , Boolean : { type: Boolean, validate: validateBoolean } + , url : { type: url, validate: validateUrl } + , Number : { type: Number, validate: validateNumber } + , path : { type: path, validate: validatePath } + , Stream : { type: Stream, validate: validateStream } + , Date : { type: Date, validate: validateDate } + } + +function nopt (types, shorthands, args, slice) { + args = args || process.argv + types = types || {} + shorthands = shorthands || {} + if (typeof slice !== "number") slice = 2 + + debug(types, shorthands, args, slice) + + args = args.slice(slice) + var data = {} + , key + , remain = [] + , cooked = args + , original = args.slice(0) + + parse(args, data, remain, types, shorthands) + // now data is full + clean(data, types, exports.typeDefs) + data.argv = {remain:remain,cooked:cooked,original:original} + Object.defineProperty(data.argv, 'toString', { value: function () { + return this.original.map(JSON.stringify).join(" ") + }, enumerable: false }) + return data +} + +function clean (data, types, typeDefs) { + typeDefs = typeDefs || exports.typeDefs + var remove = {} + , typeDefault = [false, true, null, String, Number, Array] + + Object.keys(data).forEach(function (k) { + if (k === "argv") return + var val = data[k] + , isArray = Array.isArray(val) + , type = types[k] + if (!isArray) val = [val] + if (!type) type = typeDefault + if (type === Array) type = typeDefault.concat(Array) + if (!Array.isArray(type)) type = [type] + + debug("val=%j", val) + debug("types=", type) + val = val.map(function (val) { + // if it's an unknown value, then parse false/true/null/numbers/dates + if (typeof val === "string") { + debug("string %j", val) + val = val.trim() + if ((val === "null" && ~type.indexOf(null)) + || (val === "true" && + (~type.indexOf(true) || ~type.indexOf(Boolean))) + || (val === "false" && + (~type.indexOf(false) || ~type.indexOf(Boolean)))) { + val = JSON.parse(val) + debug("jsonable %j", val) + } else if (~type.indexOf(Number) && !isNaN(val)) { + debug("convert to number", val) + val = +val + } else if (~type.indexOf(Date) && !isNaN(Date.parse(val))) { + debug("convert to date", val) + val = new Date(val) + } + } + + if (!types.hasOwnProperty(k)) { + return val + } + + // allow `--no-blah` to set 'blah' to null if null is allowed + if (val === false && ~type.indexOf(null) && + !(~type.indexOf(false) || ~type.indexOf(Boolean))) { + val = null + } + + var d = {} + d[k] = val + debug("prevalidated val", d, val, types[k]) + if (!validate(d, k, val, types[k], typeDefs)) { + if (exports.invalidHandler) { + exports.invalidHandler(k, val, types[k], data) + } else if (exports.invalidHandler !== false) { + debug("invalid: "+k+"="+val, types[k]) + } + return remove + } + debug("validated val", d, val, types[k]) + return d[k] + }).filter(function (val) { return val !== remove }) + + if (!val.length) delete data[k] + else if (isArray) { + debug(isArray, data[k], val) + data[k] = val + } else data[k] = val[0] + + debug("k=%s val=%j", k, val, data[k]) + }) +} + +function validateString (data, k, val) { + data[k] = String(val) +} + +function validatePath (data, k, val) { + data[k] = path.resolve(String(val)) + return true +} + +function validateNumber (data, k, val) { + debug("validate Number %j %j %j", k, val, isNaN(val)) + if (isNaN(val)) return false + data[k] = +val +} + +function validateDate (data, k, val) { + debug("validate Date %j %j %j", k, val, Date.parse(val)) + var s = Date.parse(val) + if (isNaN(s)) return false + data[k] = new Date(val) +} + +function validateBoolean (data, k, val) { + if (val instanceof Boolean) val = val.valueOf() + else if (typeof val === "string") { + if (!isNaN(val)) val = !!(+val) + else if (val === "null" || val === "false") val = false + else val = true + } else val = !!val + data[k] = val +} + +function validateUrl (data, k, val) { + val = url.parse(String(val)) + if (!val.host) return false + data[k] = val.href +} + +function validateStream (data, k, val) { + if (!(val instanceof Stream)) return false + data[k] = val +} + +function validate (data, k, val, type, typeDefs) { + // arrays are lists of types. + if (Array.isArray(type)) { + for (var i = 0, l = type.length; i < l; i ++) { + if (type[i] === Array) continue + if (validate(data, k, val, type[i], typeDefs)) return true + } + delete data[k] + return false + } + + // an array of anything? + if (type === Array) return true + + // NaN is poisonous. Means that something is not allowed. + if (type !== type) { + debug("Poison NaN", k, val, type) + delete data[k] + return false + } + + // explicit list of values + if (val === type) { + debug("Explicitly allowed %j", val) + // if (isArray) (data[k] = data[k] || []).push(val) + // else data[k] = val + data[k] = val + return true + } + + // now go through the list of typeDefs, validate against each one. + var ok = false + , types = Object.keys(typeDefs) + for (var i = 0, l = types.length; i < l; i ++) { + debug("test type %j %j %j", k, val, types[i]) + var t = typeDefs[types[i]] + if (t && type === t.type) { + var d = {} + ok = false !== t.validate(d, k, val) + val = d[k] + if (ok) { + // if (isArray) (data[k] = data[k] || []).push(val) + // else data[k] = val + data[k] = val + break + } + } + } + debug("OK? %j (%j %j %j)", ok, k, val, types[i]) + + if (!ok) delete data[k] + return ok +} + +function parse (args, data, remain, types, shorthands) { + debug("parse", args, data, remain) + + var key = null + , abbrevs = abbrev(Object.keys(types)) + , shortAbbr = abbrev(Object.keys(shorthands)) + + for (var i = 0; i < args.length; i ++) { + var arg = args[i] + debug("arg", arg) + + if (arg.match(/^-{2,}$/)) { + // done with keys. + // the rest are args. + remain.push.apply(remain, args.slice(i + 1)) + args[i] = "--" + break + } + var hadEq = false + if (arg.charAt(0) === "-" && arg.length > 1) { + if (arg.indexOf("=") !== -1) { + hadEq = true + var v = arg.split("=") + arg = v.shift() + v = v.join("=") + args.splice.apply(args, [i, 1].concat([arg, v])) + } + + // see if it's a shorthand + // if so, splice and back up to re-parse it. + var shRes = resolveShort(arg, shorthands, shortAbbr, abbrevs) + debug("arg=%j shRes=%j", arg, shRes) + if (shRes) { + debug(arg, shRes) + args.splice.apply(args, [i, 1].concat(shRes)) + if (arg !== shRes[0]) { + i -- + continue + } + } + arg = arg.replace(/^-+/, "") + var no = null + while (arg.toLowerCase().indexOf("no-") === 0) { + no = !no + arg = arg.substr(3) + } + + if (abbrevs[arg]) arg = abbrevs[arg] + + var isArray = types[arg] === Array || + Array.isArray(types[arg]) && types[arg].indexOf(Array) !== -1 + + // allow unknown things to be arrays if specified multiple times. + if (!types.hasOwnProperty(arg) && data.hasOwnProperty(arg)) { + if (!Array.isArray(data[arg])) + data[arg] = [data[arg]] + isArray = true + } + + var val + , la = args[i + 1] + + var isBool = typeof no === 'boolean' || + types[arg] === Boolean || + Array.isArray(types[arg]) && types[arg].indexOf(Boolean) !== -1 || + (typeof types[arg] === 'undefined' && !hadEq) || + (la === "false" && + (types[arg] === null || + Array.isArray(types[arg]) && ~types[arg].indexOf(null))) + + if (isBool) { + // just set and move along + val = !no + // however, also support --bool true or --bool false + if (la === "true" || la === "false") { + val = JSON.parse(la) + la = null + if (no) val = !val + i ++ + } + + // also support "foo":[Boolean, "bar"] and "--foo bar" + if (Array.isArray(types[arg]) && la) { + if (~types[arg].indexOf(la)) { + // an explicit type + val = la + i ++ + } else if ( la === "null" && ~types[arg].indexOf(null) ) { + // null allowed + val = null + i ++ + } else if ( !la.match(/^-{2,}[^-]/) && + !isNaN(la) && + ~types[arg].indexOf(Number) ) { + // number + val = +la + i ++ + } else if ( !la.match(/^-[^-]/) && ~types[arg].indexOf(String) ) { + // string + val = la + i ++ + } + } + + if (isArray) (data[arg] = data[arg] || []).push(val) + else data[arg] = val + + continue + } + + if (la && la.match(/^-{2,}$/)) { + la = undefined + i -- + } + + val = la === undefined ? true : la + if (isArray) (data[arg] = data[arg] || []).push(val) + else data[arg] = val + + i ++ + continue + } + remain.push(arg) + } +} + +function resolveShort (arg, shorthands, shortAbbr, abbrevs) { + // handle single-char shorthands glommed together, like + // npm ls -glp, but only if there is one dash, and only if + // all of the chars are single-char shorthands, and it's + // not a match to some other abbrev. + arg = arg.replace(/^-+/, '') + + // if it's an exact known option, then don't go any further + if (abbrevs[arg] === arg) + return null + + // if it's an exact known shortopt, same deal + if (shorthands[arg]) { + // make it an array, if it's a list of words + if (shorthands[arg] && !Array.isArray(shorthands[arg])) + shorthands[arg] = shorthands[arg].split(/\s+/) + + return shorthands[arg] + } + + // first check to see if this arg is a set of single-char shorthands + var singles = shorthands.___singles + if (!singles) { + singles = Object.keys(shorthands).filter(function (s) { + return s.length === 1 + }).reduce(function (l,r) { + l[r] = true + return l + }, {}) + shorthands.___singles = singles + debug('shorthand singles', singles) + } + + var chrs = arg.split("").filter(function (c) { + return singles[c] + }) + + if (chrs.join("") === arg) return chrs.map(function (c) { + return shorthands[c] + }).reduce(function (l, r) { + return l.concat(r) + }, []) + + + // if it's an arg abbrev, and not a literal shorthand, then prefer the arg + if (abbrevs[arg] && !shorthands[arg]) + return null + + // if it's an abbr for a shorthand, then use that + if (shortAbbr[arg]) + arg = shortAbbr[arg] + + // make it an array, if it's a list of words + if (shorthands[arg] && !Array.isArray(shorthands[arg])) + shorthands[arg] = shorthands[arg].split(/\s+/) + + return shorthands[arg] +} + +if (module === require.main) { +var assert = require("assert") + , util = require("util") + + , shorthands = + { s : ["--loglevel", "silent"] + , d : ["--loglevel", "info"] + , dd : ["--loglevel", "verbose"] + , ddd : ["--loglevel", "silly"] + , noreg : ["--no-registry"] + , reg : ["--registry"] + , "no-reg" : ["--no-registry"] + , silent : ["--loglevel", "silent"] + , verbose : ["--loglevel", "verbose"] + , h : ["--usage"] + , H : ["--usage"] + , "?" : ["--usage"] + , help : ["--usage"] + , v : ["--version"] + , f : ["--force"] + , desc : ["--description"] + , "no-desc" : ["--no-description"] + , "local" : ["--no-global"] + , l : ["--long"] + , p : ["--parseable"] + , porcelain : ["--parseable"] + , g : ["--global"] + } + + , types = + { aoa: Array + , nullstream: [null, Stream] + , date: Date + , str: String + , browser : String + , cache : path + , color : ["always", Boolean] + , depth : Number + , description : Boolean + , dev : Boolean + , editor : path + , force : Boolean + , global : Boolean + , globalconfig : path + , group : [String, Number] + , gzipbin : String + , logfd : [Number, Stream] + , loglevel : ["silent","win","error","warn","info","verbose","silly"] + , long : Boolean + , "node-version" : [false, String] + , npaturl : url + , npat : Boolean + , "onload-script" : [false, String] + , outfd : [Number, Stream] + , parseable : Boolean + , pre: Boolean + , prefix: path + , proxy : url + , "rebuild-bundle" : Boolean + , registry : url + , searchopts : String + , searchexclude: [null, String] + , shell : path + , t: [Array, String] + , tag : String + , tar : String + , tmp : path + , "unsafe-perm" : Boolean + , usage : Boolean + , user : String + , username : String + , userconfig : path + , version : Boolean + , viewer: path + , _exit : Boolean + } + +; [["-v", {version:true}, []] + ,["---v", {version:true}, []] + ,["ls -s --no-reg connect -d", + {loglevel:"info",registry:null},["ls","connect"]] + ,["ls ---s foo",{loglevel:"silent"},["ls","foo"]] + ,["ls --registry blargle", {}, ["ls"]] + ,["--no-registry", {registry:null}, []] + ,["--no-color true", {color:false}, []] + ,["--no-color false", {color:true}, []] + ,["--no-color", {color:false}, []] + ,["--color false", {color:false}, []] + ,["--color --logfd 7", {logfd:7,color:true}, []] + ,["--color=true", {color:true}, []] + ,["--logfd=10", {logfd:10}, []] + ,["--tmp=/tmp -tar=gtar",{tmp:"/tmp",tar:"gtar"},[]] + ,["--tmp=tmp -tar=gtar", + {tmp:path.resolve(process.cwd(), "tmp"),tar:"gtar"},[]] + ,["--logfd x", {}, []] + ,["a -true -- -no-false", {true:true},["a","-no-false"]] + ,["a -no-false", {false:false},["a"]] + ,["a -no-no-true", {true:true}, ["a"]] + ,["a -no-no-no-false", {false:false}, ["a"]] + ,["---NO-no-No-no-no-no-nO-no-no"+ + "-No-no-no-no-no-no-no-no-no"+ + "-no-no-no-no-NO-NO-no-no-no-no-no-no"+ + "-no-body-can-do-the-boogaloo-like-I-do" + ,{"body-can-do-the-boogaloo-like-I-do":false}, []] + ,["we are -no-strangers-to-love "+ + "--you-know=the-rules --and=so-do-i "+ + "---im-thinking-of=a-full-commitment "+ + "--no-you-would-get-this-from-any-other-guy "+ + "--no-gonna-give-you-up "+ + "-no-gonna-let-you-down=true "+ + "--no-no-gonna-run-around false "+ + "--desert-you=false "+ + "--make-you-cry false "+ + "--no-tell-a-lie "+ + "--no-no-and-hurt-you false" + ,{"strangers-to-love":false + ,"you-know":"the-rules" + ,"and":"so-do-i" + ,"you-would-get-this-from-any-other-guy":false + ,"gonna-give-you-up":false + ,"gonna-let-you-down":false + ,"gonna-run-around":false + ,"desert-you":false + ,"make-you-cry":false + ,"tell-a-lie":false + ,"and-hurt-you":false + },["we", "are"]] + ,["-t one -t two -t three" + ,{t: ["one", "two", "three"]} + ,[]] + ,["-t one -t null -t three four five null" + ,{t: ["one", "null", "three"]} + ,["four", "five", "null"]] + ,["-t foo" + ,{t:["foo"]} + ,[]] + ,["--no-t" + ,{t:["false"]} + ,[]] + ,["-no-no-t" + ,{t:["true"]} + ,[]] + ,["-aoa one -aoa null -aoa 100" + ,{aoa:["one", null, 100]} + ,[]] + ,["-str 100" + ,{str:"100"} + ,[]] + ,["--color always" + ,{color:"always"} + ,[]] + ,["--no-nullstream" + ,{nullstream:null} + ,[]] + ,["--nullstream false" + ,{nullstream:null} + ,[]] + ,["--notadate=2011-01-25" + ,{notadate: "2011-01-25"} + ,[]] + ,["--date 2011-01-25" + ,{date: new Date("2011-01-25")} + ,[]] + ,["-cl 1" + ,{config: true, length: 1} + ,[] + ,{config: Boolean, length: Number, clear: Boolean} + ,{c: "--config", l: "--length"}] + ,["--acount bla" + ,{"acount":true} + ,["bla"] + ,{account: Boolean, credentials: Boolean, options: String} + ,{a:"--account", c:"--credentials",o:"--options"}] + ,["--clear" + ,{clear:true} + ,[] + ,{clear:Boolean,con:Boolean,len:Boolean,exp:Boolean,add:Boolean,rep:Boolean} + ,{c:"--con",l:"--len",e:"--exp",a:"--add",r:"--rep"}] + ,["--file -" + ,{"file":"-"} + ,[] + ,{file:String} + ,{}] + ,["--file -" + ,{"file":true} + ,["-"] + ,{file:Boolean} + ,{}] + ].forEach(function (test) { + var argv = test[0].split(/\s+/) + , opts = test[1] + , rem = test[2] + , actual = nopt(test[3] || types, test[4] || shorthands, argv, 0) + , parsed = actual.argv + delete actual.argv + console.log(util.inspect(actual, false, 2, true), parsed.remain) + for (var i in opts) { + var e = JSON.stringify(opts[i]) + , a = JSON.stringify(actual[i] === undefined ? null : actual[i]) + if (e && typeof e === "object") { + assert.deepEqual(e, a) + } else { + assert.equal(e, a) + } + } + assert.deepEqual(rem, parsed.remain) + }) +} diff --git a/node_modules/markdown/node_modules/nopt/node_modules/abbrev/LICENSE b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/LICENSE new file mode 100644 index 000000000..05a401094 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/LICENSE @@ -0,0 +1,23 @@ +Copyright 2009, 2010, 2011 Isaac Z. Schlueter. +All rights reserved. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/markdown/node_modules/nopt/node_modules/abbrev/README.md b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/README.md new file mode 100644 index 000000000..99746fe67 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/README.md @@ -0,0 +1,23 @@ +# abbrev-js + +Just like [ruby's Abbrev](http://apidock.com/ruby/Abbrev). + +Usage: + + var abbrev = require("abbrev"); + abbrev("foo", "fool", "folding", "flop"); + + // returns: + { fl: 'flop' + , flo: 'flop' + , flop: 'flop' + , fol: 'folding' + , fold: 'folding' + , foldi: 'folding' + , foldin: 'folding' + , folding: 'folding' + , foo: 'foo' + , fool: 'fool' + } + +This is handy for command-line scripts, or other cases where you want to be able to accept shorthands. diff --git a/node_modules/markdown/node_modules/nopt/node_modules/abbrev/lib/abbrev.js b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/lib/abbrev.js new file mode 100644 index 000000000..bee4132c9 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/lib/abbrev.js @@ -0,0 +1,111 @@ + +module.exports = exports = abbrev.abbrev = abbrev + +abbrev.monkeyPatch = monkeyPatch + +function monkeyPatch () { + Object.defineProperty(Array.prototype, 'abbrev', { + value: function () { return abbrev(this) }, + enumerable: false, configurable: true, writable: true + }) + + Object.defineProperty(Object.prototype, 'abbrev', { + value: function () { return abbrev(Object.keys(this)) }, + enumerable: false, configurable: true, writable: true + }) +} + +function abbrev (list) { + if (arguments.length !== 1 || !Array.isArray(list)) { + list = Array.prototype.slice.call(arguments, 0) + } + for (var i = 0, l = list.length, args = [] ; i < l ; i ++) { + args[i] = typeof list[i] === "string" ? list[i] : String(list[i]) + } + + // sort them lexicographically, so that they're next to their nearest kin + args = args.sort(lexSort) + + // walk through each, seeing how much it has in common with the next and previous + var abbrevs = {} + , prev = "" + for (var i = 0, l = args.length ; i < l ; i ++) { + var current = args[i] + , next = args[i + 1] || "" + , nextMatches = true + , prevMatches = true + if (current === next) continue + for (var j = 0, cl = current.length ; j < cl ; j ++) { + var curChar = current.charAt(j) + nextMatches = nextMatches && curChar === next.charAt(j) + prevMatches = prevMatches && curChar === prev.charAt(j) + if (!nextMatches && !prevMatches) { + j ++ + break + } + } + prev = current + if (j === cl) { + abbrevs[current] = current + continue + } + for (var a = current.substr(0, j) ; j <= cl ; j ++) { + abbrevs[a] = current + a += current.charAt(j) + } + } + return abbrevs +} + +function lexSort (a, b) { + return a === b ? 0 : a > b ? 1 : -1 +} + + +// tests +if (module === require.main) { + +var assert = require("assert") +var util = require("util") + +console.log("running tests") +function test (list, expect) { + var actual = abbrev(list) + assert.deepEqual(actual, expect, + "abbrev("+util.inspect(list)+") === " + util.inspect(expect) + "\n"+ + "actual: "+util.inspect(actual)) + actual = abbrev.apply(exports, list) + assert.deepEqual(abbrev.apply(exports, list), expect, + "abbrev("+list.map(JSON.stringify).join(",")+") === " + util.inspect(expect) + "\n"+ + "actual: "+util.inspect(actual)) +} + +test([ "ruby", "ruby", "rules", "rules", "rules" ], +{ rub: 'ruby' +, ruby: 'ruby' +, rul: 'rules' +, rule: 'rules' +, rules: 'rules' +}) +test(["fool", "foom", "pool", "pope"], +{ fool: 'fool' +, foom: 'foom' +, poo: 'pool' +, pool: 'pool' +, pop: 'pope' +, pope: 'pope' +}) +test(["a", "ab", "abc", "abcd", "abcde", "acde"], +{ a: 'a' +, ab: 'ab' +, abc: 'abc' +, abcd: 'abcd' +, abcde: 'abcde' +, ac: 'acde' +, acd: 'acde' +, acde: 'acde' +}) + +console.log("pass") + +} diff --git a/node_modules/markdown/node_modules/nopt/node_modules/abbrev/package.json b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/package.json new file mode 100644 index 000000000..55ed011bf --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/node_modules/abbrev/package.json @@ -0,0 +1,28 @@ +{ + "name": "abbrev", + "version": "1.0.4", + "description": "Like ruby's abbrev module, but in js", + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me" + }, + "main": "./lib/abbrev.js", + "scripts": { + "test": "node lib/abbrev.js" + }, + "repository": { + "type": "git", + "url": "http://github.com/isaacs/abbrev-js" + }, + "license": { + "type": "MIT", + "url": "https://github.com/isaacs/abbrev-js/raw/master/LICENSE" + }, + "readme": "# abbrev-js\n\nJust like [ruby's Abbrev](http://apidock.com/ruby/Abbrev).\n\nUsage:\n\n var abbrev = require(\"abbrev\");\n abbrev(\"foo\", \"fool\", \"folding\", \"flop\");\n \n // returns:\n { fl: 'flop'\n , flo: 'flop'\n , flop: 'flop'\n , fol: 'folding'\n , fold: 'folding'\n , foldi: 'folding'\n , foldin: 'folding'\n , folding: 'folding'\n , foo: 'foo'\n , fool: 'fool'\n }\n\nThis is handy for command-line scripts, or other cases where you want to be able to accept shorthands.\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/isaacs/abbrev-js/issues" + }, + "_id": "abbrev@1.0.4", + "_from": "abbrev@1" +} diff --git a/node_modules/markdown/node_modules/nopt/package.json b/node_modules/markdown/node_modules/nopt/package.json new file mode 100644 index 000000000..95a43fe51 --- /dev/null +++ b/node_modules/markdown/node_modules/nopt/package.json @@ -0,0 +1,35 @@ +{ + "name": "nopt", + "version": "2.1.2", + "description": "Option parsing for Node, supporting types, shorthands, etc. Used by npm.", + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "http://blog.izs.me/" + }, + "main": "lib/nopt.js", + "scripts": { + "test": "node lib/nopt.js" + }, + "repository": { + "type": "git", + "url": "http://github.com/isaacs/nopt" + }, + "bin": { + "nopt": "./bin/nopt.js" + }, + "license": { + "type": "MIT", + "url": "https://github.com/isaacs/nopt/raw/master/LICENSE" + }, + "dependencies": { + "abbrev": "1" + }, + "readme": "If you want to write an option parser, and have it be good, there are\ntwo ways to do it. The Right Way, and the Wrong Way.\n\nThe Wrong Way is to sit down and write an option parser. We've all done\nthat.\n\nThe Right Way is to write some complex configurable program with so many\noptions that you go half-insane just trying to manage them all, and put\nit off with duct-tape solutions until you see exactly to the core of the\nproblem, and finally snap and write an awesome option parser.\n\nIf you want to write an option parser, don't write an option parser.\nWrite a package manager, or a source control system, or a service\nrestarter, or an operating system. You probably won't end up with a\ngood one of those, but if you don't give up, and you are relentless and\ndiligent enough in your procrastination, you may just end up with a very\nnice option parser.\n\n## USAGE\n\n // my-program.js\n var nopt = require(\"nopt\")\n , Stream = require(\"stream\").Stream\n , path = require(\"path\")\n , knownOpts = { \"foo\" : [String, null]\n , \"bar\" : [Stream, Number]\n , \"baz\" : path\n , \"bloo\" : [ \"big\", \"medium\", \"small\" ]\n , \"flag\" : Boolean\n , \"pick\" : Boolean\n , \"many\" : [String, Array]\n }\n , shortHands = { \"foofoo\" : [\"--foo\", \"Mr. Foo\"]\n , \"b7\" : [\"--bar\", \"7\"]\n , \"m\" : [\"--bloo\", \"medium\"]\n , \"p\" : [\"--pick\"]\n , \"f\" : [\"--flag\"]\n }\n // everything is optional.\n // knownOpts and shorthands default to {}\n // arg list defaults to process.argv\n // slice defaults to 2\n , parsed = nopt(knownOpts, shortHands, process.argv, 2)\n console.log(parsed)\n\nThis would give you support for any of the following:\n\n```bash\n$ node my-program.js --foo \"blerp\" --no-flag\n{ \"foo\" : \"blerp\", \"flag\" : false }\n\n$ node my-program.js ---bar 7 --foo \"Mr. Hand\" --flag\n{ bar: 7, foo: \"Mr. Hand\", flag: true }\n\n$ node my-program.js --foo \"blerp\" -f -----p\n{ foo: \"blerp\", flag: true, pick: true }\n\n$ node my-program.js -fp --foofoo\n{ foo: \"Mr. Foo\", flag: true, pick: true }\n\n$ node my-program.js --foofoo -- -fp # -- stops the flag parsing.\n{ foo: \"Mr. Foo\", argv: { remain: [\"-fp\"] } }\n\n$ node my-program.js --blatzk 1000 -fp # unknown opts are ok.\n{ blatzk: 1000, flag: true, pick: true }\n\n$ node my-program.js --blatzk true -fp # but they need a value\n{ blatzk: true, flag: true, pick: true }\n\n$ node my-program.js --no-blatzk -fp # unless they start with \"no-\"\n{ blatzk: false, flag: true, pick: true }\n\n$ node my-program.js --baz b/a/z # known paths are resolved.\n{ baz: \"/Users/isaacs/b/a/z\" }\n\n# if Array is one of the types, then it can take many\n# values, and will always be an array. The other types provided\n# specify what types are allowed in the list.\n\n$ node my-program.js --many 1 --many null --many foo\n{ many: [\"1\", \"null\", \"foo\"] }\n\n$ node my-program.js --many foo\n{ many: [\"foo\"] }\n```\n\nRead the tests at the bottom of `lib/nopt.js` for more examples of\nwhat this puppy can do.\n\n## Types\n\nThe following types are supported, and defined on `nopt.typeDefs`\n\n* String: A normal string. No parsing is done.\n* path: A file system path. Gets resolved against cwd if not absolute.\n* url: A url. If it doesn't parse, it isn't accepted.\n* Number: Must be numeric.\n* Date: Must parse as a date. If it does, and `Date` is one of the options,\n then it will return a Date object, not a string.\n* Boolean: Must be either `true` or `false`. If an option is a boolean,\n then it does not need a value, and its presence will imply `true` as\n the value. To negate boolean flags, do `--no-whatever` or `--whatever\n false`\n* NaN: Means that the option is strictly not allowed. Any value will\n fail.\n* Stream: An object matching the \"Stream\" class in node. Valuable\n for use when validating programmatically. (npm uses this to let you\n supply any WriteStream on the `outfd` and `logfd` config options.)\n* Array: If `Array` is specified as one of the types, then the value\n will be parsed as a list of options. This means that multiple values\n can be specified, and that the value will always be an array.\n\nIf a type is an array of values not on this list, then those are\nconsidered valid values. For instance, in the example above, the\n`--bloo` option can only be one of `\"big\"`, `\"medium\"`, or `\"small\"`,\nand any other value will be rejected.\n\nWhen parsing unknown fields, `\"true\"`, `\"false\"`, and `\"null\"` will be\ninterpreted as their JavaScript equivalents, and numeric values will be\ninterpreted as a number.\n\nYou can also mix types and values, or multiple types, in a list. For\ninstance `{ blah: [Number, null] }` would allow a value to be set to\neither a Number or null. When types are ordered, this implies a\npreference, and the first type that can be used to properly interpret\nthe value will be used.\n\nTo define a new type, add it to `nopt.typeDefs`. Each item in that\nhash is an object with a `type` member and a `validate` method. The\n`type` member is an object that matches what goes in the type list. The\n`validate` method is a function that gets called with `validate(data,\nkey, val)`. Validate methods should assign `data[key]` to the valid\nvalue of `val` if it can be handled properly, or return boolean\n`false` if it cannot.\n\nYou can also call `nopt.clean(data, types, typeDefs)` to clean up a\nconfig object and remove its invalid properties.\n\n## Error Handling\n\nBy default, nopt outputs a warning to standard error when invalid\noptions are found. You can change this behavior by assigning a method\nto `nopt.invalidHandler`. This method will be called with\nthe offending `nopt.invalidHandler(key, val, types)`.\n\nIf no `nopt.invalidHandler` is assigned, then it will console.error\nits whining. If it is assigned to boolean `false` then the warning is\nsuppressed.\n\n## Abbreviations\n\nYes, they are supported. If you define options like this:\n\n```javascript\n{ \"foolhardyelephants\" : Boolean\n, \"pileofmonkeys\" : Boolean }\n```\n\nThen this will work:\n\n```bash\nnode program.js --foolhar --pil\nnode program.js --no-f --pileofmon\n# etc.\n```\n\n## Shorthands\n\nShorthands are a hash of shorter option names to a snippet of args that\nthey expand to.\n\nIf multiple one-character shorthands are all combined, and the\ncombination does not unambiguously match any other option or shorthand,\nthen they will be broken up into their constituent parts. For example:\n\n```json\n{ \"s\" : [\"--loglevel\", \"silent\"]\n, \"g\" : \"--global\"\n, \"f\" : \"--force\"\n, \"p\" : \"--parseable\"\n, \"l\" : \"--long\"\n}\n```\n\n```bash\nnpm ls -sgflp\n# just like doing this:\nnpm ls --loglevel silent --global --force --long --parseable\n```\n\n## The Rest of the args\n\nThe config object returned by nopt is given a special member called\n`argv`, which is an object with the following fields:\n\n* `remain`: The remaining args after all the parsing has occurred.\n* `original`: The args as they originally appeared.\n* `cooked`: The args after flags and shorthands are expanded.\n\n## Slicing\n\nNode programs are called with more or less the exact argv as it appears\nin C land, after the v8 and node-specific options have been plucked off.\nAs such, `argv[0]` is always `node` and `argv[1]` is always the\nJavaScript program being run.\n\nThat's usually not very useful to you. So they're sliced off by\ndefault. If you want them, then you can pass in `0` as the last\nargument, or any other number that you'd like to slice off the start of\nthe list.\n", + "readmeFilename": "README.md", + "bugs": { + "url": "https://github.com/isaacs/nopt/issues" + }, + "_id": "nopt@2.1.2", + "_from": "nopt@~2.1.1" +} diff --git a/node_modules/markdown/package.json b/node_modules/markdown/package.json new file mode 100644 index 000000000..e391cb396 --- /dev/null +++ b/node_modules/markdown/package.json @@ -0,0 +1,64 @@ +{ + "name": "markdown", + "version": "0.5.0", + "description": "A sensible Markdown parser for javascript", + "keywords": [ + "markdown", + "text processing", + "ast" + ], + "maintainers": [ + { + "name": "Dominic Baggott", + "email": "dominic.baggott@gmail.com", + "url": "http://evilstreak.co.uk" + }, + { + "name": "Ash Berlin", + "email": "ash_markdownjs@firemirror.com", + "url": "http://ashberlin.com" + } + ], + "contributors": [ + { + "name": "Dominic Baggott", + "email": "dominic.baggott@gmail.com", + "url": "http://evilstreak.co.uk" + }, + { + "name": "Ash Berlin", + "email": "ash_markdownjs@firemirror.com", + "url": "http://ashberlin.com" + } + ], + "bugs": { + "url": "http://github.com/evilstreak/markdown-js/issues" + }, + "licenses": [ + { + "type": "MIT", + "url": "http://www.opensource.org/licenses/mit-license.php" + } + ], + "repository": { + "type": "git", + "url": "git://github.com/evilstreak/markdown-js.git" + }, + "main": "./lib/index.js", + "bin": { + "md2html": "./bin/md2html.js" + }, + "dependencies": { + "nopt": "~2.1.1" + }, + "devDependencies": { + "tap": "~0.3.3" + }, + "scripts": { + "test": "tap ./test/*.t.js" + }, + "readme": "# markdown-js\n\nYet another markdown parser, this time for JavaScript. There's a few\noptions that precede this project but they all treat markdown to HTML\nconversion as a single step process. You pass markdown in and get HTML\nout, end of story. We had some pretty particular views on how the\nprocess should actually look, which include:\n\n * producing well-formed HTML. This means that `em` and `strong` nesting\n is important, as is the ability to output as both HTML and XHTML\n\n * having an intermediate representation to allow processing of parsed\n data (we in fact have two, both [JsonML]: a markdown tree and an HTML tree)\n\n * being easily extensible to add new dialects without having to\n rewrite the entire parsing mechanics\n\n * having a good test suite. The only test suites we could find tested\n massive blocks of input, and passing depended on outputting the HTML\n with exactly the same whitespace as the original implementation\n\n[JsonML]: http://jsonml.org/ \"JSON Markup Language\"\n\n## Installation\n\nJust the `markdown` library:\n\n npm install markdown\n\nOptionally, install `md2html` into your path\n\n npm install -g markdown\n\n## Usage\n\n### Node\n\nThe simple way to use it with node is:\n\n```js\nvar markdown = require( \"markdown\" ).markdown;\nconsole.log( markdown.toHTML( \"Hello *World*!\" ) );\n```\n\n### Browser\n\nIt also works in a browser; here is a complete example:\n\n```html\n\n\n \n \n
    \n \n \n \n\n```\n\n### Command line\n\nAssuming you've installed the `md2html` script (see Installation,\nabove), you can convert markdown to html:\n\n```bash\n# read from a file\nmd2html /path/to/doc.md > /path/to/doc.html\n\n# or from stdin\necho 'Hello *World*!' | md2html\n```\n\n### More options\n\nIf you want more control check out the documentation in\n[lib/markdown.js] which details all the methods and parameters\navailable (including examples!). One day we'll get the docs generated\nand hosted somewhere for nicer browsing.\n\n[lib/markdown.js]: http://github.com/evilstreak/markdown-js/blob/master/lib/markdown.js\n\nMeanwhile, here's an example of using the multi-step processing to\nmake wiki-style linking work by filling in missing link references:\n\n```js\nvar md = require( \"markdown\" ).markdown,\n text = \"[Markdown] is a simple text-based [markup language]\\n\" +\n \"created by [John Gruber]\\n\\n\" +\n \"[John Gruber]: http://daringfireball.net\";\n\n// parse the markdown into a tree and grab the link references\nvar tree = md.parse( text ),\n refs = tree[ 1 ].references;\n\n// iterate through the tree finding link references\n( function find_link_refs( jsonml ) {\n if ( jsonml[ 0 ] === \"link_ref\" ) {\n var ref = jsonml[ 1 ].ref;\n\n // if there's no reference, define a wiki link\n if ( !refs[ ref ] ) {\n refs[ ref ] = {\n href: \"http://en.wikipedia.org/wiki/\" + ref.replace(/\\s+/, \"_\" )\n };\n }\n }\n else if ( Array.isArray( jsonml[ 1 ] ) ) {\n jsonml[ 1 ].forEach( find_link_refs );\n }\n else if ( Array.isArray( jsonml[ 2 ] ) ) {\n jsonml[ 2 ].forEach( find_link_refs );\n }\n} )( tree );\n\n// convert the tree into html\nvar html = md.renderJsonML( md.toHTMLTree( tree ) );\nconsole.log( html );\n```\n\n## Intermediate Representation\n\nInternally the process to convert a chunk of markdown into a chunk of\nHTML has three steps:\n\n 1. Parse the markdown into a JsonML tree. Any references found in the\n parsing are stored in the attribute hash of the root node under the\n key `references`.\n\n 2. Convert the markdown tree into an HTML tree. Rename any nodes that\n need it (`bulletlist` to `ul` for example) and lookup any references\n used by links or images. Remove the references attribute once done.\n\n 3. Stringify the HTML tree being careful not to wreck whitespace where\n whitespace is important (surrounding inline elements for example).\n\nEach step of this process can be called individually if you need to do\nsome processing or modification of the data at an intermediate stage.\nFor example, you may want to grab a list of all URLs linked to in the\ndocument before rendering it to HTML which you could do by recursing\nthrough the HTML tree looking for `a` nodes.\n\n## Running tests\n\nTo run the tests under node you will need tap installed (it's listed as a\n`devDependencies` so `npm install` from the checkout should be enough), then do\n\n $ npm test\n\n## Contributing\n\nDo the usual github fork and pull request dance. Add yourself to the\ncontributors section of [package.json](/package.json) too if you want to.\n\n## License\n\nReleased under the MIT license.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n", + "readmeFilename": "README.markdown", + "_id": "markdown@0.5.0", + "_from": "markdown@" +} diff --git a/node_modules/markdown/seed.yml b/node_modules/markdown/seed.yml new file mode 100644 index 000000000..a15b22903 --- /dev/null +++ b/node_modules/markdown/seed.yml @@ -0,0 +1,5 @@ +--- + name: markdown-js + description: JavaScript implementation of Markdown + tags: markdown parser + version: 0.1.2 diff --git a/plugins/tiddlywiki/markdown/files/tiddlywiki.files b/plugins/tiddlywiki/markdown/files/tiddlywiki.files new file mode 100644 index 000000000..ee2795b9f --- /dev/null +++ b/plugins/tiddlywiki/markdown/files/tiddlywiki.files @@ -0,0 +1,12 @@ +{ + "tiddlers": [ + { + "file": "../../../../node_modules/markdown/lib/markdown.js", + "fields": { + "type": "application/javascript", + "title": "$:/plugins/tiddlywiki/markdown/markdown.js", + "module-type": "library" + } + } + ] +} diff --git a/plugins/tiddlywiki/markdown/plugin.info b/plugins/tiddlywiki/markdown/plugin.info new file mode 100644 index 000000000..2980ff71f --- /dev/null +++ b/plugins/tiddlywiki/markdown/plugin.info @@ -0,0 +1,6 @@ +{ + "title": "$:/plugins/tiddlywiki/markdown", + "description": "Markdown plugin wrapping markdown-js", + "author": "JeremyRuston", + "coreVersion": ">=5.0.0" +} diff --git a/plugins/tiddlywiki/markdown/wrapper.js b/plugins/tiddlywiki/markdown/wrapper.js new file mode 100644 index 000000000..0cbe0dd54 --- /dev/null +++ b/plugins/tiddlywiki/markdown/wrapper.js @@ -0,0 +1,60 @@ +/*\ +title: $:/plugins/tiddlywiki/markdown/wrapper.js +type: application/javascript +module-type: parser + +Wraps up the markdown-js parser for use in TiddlyWiki5 + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var markdown = require("$:/plugins/tiddlywiki/markdown/markdown.js"); + +function transformNodes(nodes) { + var results = []; + for(var index=0; index> -} - -code { - padding: 1px 2px; - color: #d14; - background-color: #f7f7f9; - border: 1px solid #e1e1e8; - white-space: pre-wrap; -} - pre { display: block; padding: 14px; @@ -103,6 +90,27 @@ pre { white-space: pre-wrap; background-color: #f5f5f5; border: 1px solid #ccc; + padding: 0 3px 2px; + <> +} + +code { + color: #d14; + background-color: #f7f7f9; + border: 1px solid #e1e1e8; + white-space: pre-wrap; + padding: 0 3px 2px; + <> +} + +/* +Markdown likes putting code elements inside pre elements +*/ +pre > code { + padding: 0; + border: none; + background-color: inherit; + color: inherit; } table {