marked 0.2.4 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2012, Christopher Jeffrey (https://github.com/chjj/)
1
+ Copyright (c) 2011-2013, Christopher Jeffrey (https://github.com/chjj/)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -62,15 +62,20 @@ Along with implementing every markdown feature, marked also implements
62
62
 
63
63
  ## Options
64
64
 
65
- marked has 4 different switches which change behavior.
65
+ marked has a few different switches which change behavior.
66
66
 
67
67
  - __pedantic__: Conform to obscure parts of `markdown.pl` as much as possible.
68
68
  Don't fix any of the original markdown bugs or poor behavior.
69
69
  - __gfm__: Enable github flavored markdown (enabled by default).
70
70
  - __sanitize__: Sanitize the output. Ignore any HTML that has been input.
71
71
  - __highlight__: A callback to highlight code blocks.
72
-
73
- None of the above are mutually exclusive/inclusive.
72
+ - __tables__: Enable GFM tables. This is enabled by default. (Requires the
73
+ `gfm` option in order to be enabled).
74
+ - __breaks__: Enable GFM line breaks. Disabled by default.
75
+ - __smartLists__: Use smarter list behavior than the original markdown.
76
+ Disabled by default. May eventually be default with the old behavior
77
+ moved into `pedantic`.
78
+ - __langPrefix__: Set the prefix for code block classes. Defaults to `lang-`.
74
79
 
75
80
  ## Usage
76
81
 
@@ -78,12 +83,15 @@ None of the above are mutually exclusive/inclusive.
78
83
  // Set default options
79
84
  marked.setOptions({
80
85
  gfm: true,
86
+ tables: true,
87
+ breaks: false,
81
88
  pedantic: false,
82
89
  sanitize: true,
83
- // callback for code highlighter
90
+ smartLists: true,
91
+ langPrefix: 'language-',
84
92
  highlight: function(code, lang) {
85
93
  if (lang === 'js') {
86
- return javascriptHighlighter(code);
94
+ return highlighter.javascript(code);
87
95
  }
88
96
  return code;
89
97
  }
@@ -94,10 +102,17 @@ console.log(marked('i am using __markdown__.'));
94
102
  You also have direct access to the lexer and parser if you so desire.
95
103
 
96
104
  ``` js
97
- var tokens = marked.lexer(text);
105
+ var tokens = marked.lexer(text, options);
98
106
  console.log(marked.parser(tokens));
99
107
  ```
100
108
 
109
+ ``` js
110
+ var lexer = new marked.Lexer(options);
111
+ var tokens = lexer.lex(text);
112
+ console.log(tokens);
113
+ console.log(lexer.rules);
114
+ ```
115
+
101
116
  ``` bash
102
117
  $ node
103
118
  > require('marked').lexer('> i am using marked.')
@@ -120,6 +135,6 @@ $ cat hello.html
120
135
 
121
136
  ## License
122
137
 
123
- Copyright (c) 2011-2012, Christopher Jeffrey. (MIT License)
138
+ Copyright (c) 2011-2013, Christopher Jeffrey. (MIT License)
124
139
 
125
140
  See LICENSE for more info.
package/bin/marked CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * Marked CLI
5
- * Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)
5
+ * Copyright (c) 2011-2013, Christopher Jeffrey (MIT License)
6
6
  */
7
7
 
8
8
  var fs = require('fs')
@@ -13,7 +13,7 @@ var fs = require('fs')
13
13
  * Man Page
14
14
  */
15
15
 
16
- var help = function() {
16
+ function help() {
17
17
  var spawn = require('child_process').spawn;
18
18
 
19
19
  var options = {
@@ -26,29 +26,48 @@ var help = function() {
26
26
  spawn('man',
27
27
  [__dirname + '/../man/marked.1'],
28
28
  options);
29
- };
29
+ }
30
30
 
31
31
  /**
32
32
  * Main
33
33
  */
34
34
 
35
- var main = function(argv) {
35
+ function main(argv, callback) {
36
36
  var files = []
37
37
  , options = {}
38
- , data = ''
39
38
  , input
40
39
  , output
41
40
  , arg
42
- , tokens;
41
+ , tokens
42
+ , opt;
43
43
 
44
- var getarg = function() {
44
+ function getarg() {
45
45
  var arg = argv.shift();
46
- arg = arg.split('=');
47
- if (arg.length > 1) {
48
- argv.unshift(arg.slice(1).join('='));
46
+
47
+ if (arg.indexOf('--') === 0) {
48
+ // e.g. --opt
49
+ arg = arg.split('=');
50
+ if (arg.length > 1) {
51
+ // e.g. --opt=val
52
+ argv.unshift(arg.slice(1).join('='));
53
+ }
54
+ arg = arg[0];
55
+ } else if (arg[0] === '-') {
56
+ if (arg.length > 2) {
57
+ // e.g. -abc
58
+ argv = arg.substring(1).split('').map(function(ch) {
59
+ return '-' + ch;
60
+ }).concat(argv);
61
+ arg = argv.shift();
62
+ } else {
63
+ // e.g. -a
64
+ }
65
+ } else {
66
+ // e.g. foo
49
67
  }
50
- return arg[0];
51
- };
68
+
69
+ return arg;
70
+ }
52
71
 
53
72
  while (argv.length) {
54
73
  arg = getarg();
@@ -65,63 +84,102 @@ var main = function(argv) {
65
84
  case '--tokens':
66
85
  tokens = true;
67
86
  break;
68
- case '--gfm':
69
- options.gfm = true;
70
- break;
71
- case '--sanitize':
72
- options.sanitize = true;
73
- break;
74
- case '--pedantic':
75
- options.pedantic = true;
76
- break;
77
87
  case '-h':
78
88
  case '--help':
79
89
  return help();
80
90
  default:
81
- files.push(arg);
91
+ if (arg.indexOf('--') === 0) {
92
+ opt = camelize(arg.replace(/^--(no-)?/, ''));
93
+ if (!marked.defaults.hasOwnProperty(opt)) {
94
+ continue;
95
+ }
96
+ if (arg.indexOf('--no-') === 0) {
97
+ options[opt] = typeof marked.defaults[opt] !== 'boolean'
98
+ ? null
99
+ : false;
100
+ } else {
101
+ options[opt] = typeof marked.defaults[opt] !== 'boolean'
102
+ ? argv.shift()
103
+ : true;
104
+ }
105
+ } else {
106
+ files.push(arg);
107
+ }
82
108
  break;
83
109
  }
84
110
  }
85
111
 
86
- if (!input) {
87
- if (files.length <= 2) {
88
- var stdin = process.stdin;
89
-
90
- stdin.setEncoding('utf8');
91
- stdin.resume();
92
-
93
- stdin.on('data', function(text) {
94
- data += text;
95
- });
96
-
97
- stdin.on('end', write);
98
-
99
- return;
112
+ function getData(callback) {
113
+ if (!input) {
114
+ if (files.length <= 2) {
115
+ return getStdin(callback);
116
+ }
117
+ input = files.pop();
100
118
  }
101
- input = files.pop();
119
+ return fs.readFile(input, 'utf8', callback);
102
120
  }
103
121
 
104
- data = fs.readFileSync(input, 'utf8');
105
- write();
106
-
107
- function write() {
108
- marked.setOptions(options);
122
+ return getData(function(err, data) {
123
+ if (err) return callback(err);
109
124
 
110
125
  data = tokens
111
- ? JSON.stringify(marked.lexer(data), null, 2)
112
- : marked(data);
126
+ ? JSON.stringify(marked.lexer(data, options), null, 2)
127
+ : marked(data, options);
113
128
 
114
129
  if (!output) {
115
130
  process.stdout.write(data + '\n');
116
- } else {
117
- fs.writeFileSync(output, data);
131
+ return callback();
118
132
  }
133
+
134
+ return fs.writeFile(output, data, callback);
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Helpers
140
+ */
141
+
142
+ function getStdin(callback) {
143
+ var stdin = process.stdin
144
+ , buff = '';
145
+
146
+ stdin.setEncoding('utf8');
147
+
148
+ stdin.on('data', function(data) {
149
+ buff += data;
150
+ });
151
+
152
+ stdin.on('error', function(err) {
153
+ return callback(err);
154
+ });
155
+
156
+ stdin.on('end', function() {
157
+ return callback(null, buff);
158
+ });
159
+
160
+ try {
161
+ stdin.resume();
162
+ } catch (e) {
163
+ callback(e);
119
164
  }
120
- };
165
+ }
166
+
167
+ function camelize(text) {
168
+ return text.replace(/(\w)-(\w)/g, function(_, a, b) {
169
+ return a + b.toUpperCase();
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Expose / Entry Point
175
+ */
121
176
 
122
177
  if (!module.parent) {
123
178
  process.title = 'marked';
124
- main(process.argv.slice());
179
+ main(process.argv.slice(), function(err, code) {
180
+ if (err) throw err;
181
+ return process.exit(code || 0);
182
+ });
125
183
  } else {
126
184
  module.exports = main;
127
185
  }