Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bug fix, cleanup to remove marked references, add demo code blocks

  • Loading branch information...
commit 289158a700878ee9779a8912cc38119ca801ff27 1 parent aa800f7
@gjtorikian authored
View
127 bin/namp
@@ -1,127 +0,0 @@
-#!/usr/bin/env node
-
-/**
- * Marked CLI
- * Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)
- */
-
-var fs = require('fs')
- , util = require('util')
- , marked = require('../');
-
-/**
- * Man Page
- */
-
-var help = function() {
- var spawn = require('child_process').spawn;
-
- var options = {
- cwd: process.cwd(),
- env: process.env,
- setsid: false,
- customFds: [0, 1, 2]
- };
-
- spawn('man',
- [__dirname + '/../man/marked.1'],
- options);
-};
-
-/**
- * Main
- */
-
-var main = function(argv) {
- var files = []
- , options = {}
- , data = ''
- , input
- , output
- , arg
- , tokens;
-
- var getarg = function() {
- var arg = argv.shift();
- arg = arg.split('=');
- if (arg.length > 1) {
- argv.unshift(arg.slice(1).join('='));
- }
- return arg[0];
- };
-
- while (argv.length) {
- arg = getarg();
- switch (arg) {
- case '-o':
- case '--output':
- output = argv.shift();
- break;
- case '-i':
- case '--input':
- input = argv.shift();
- break;
- case '-t':
- case '--tokens':
- tokens = true;
- break;
- case '--gfm':
- options.gfm = true;
- break;
- case '--sanitize':
- options.sanitize = true;
- break;
- case '--pedantic':
- options.pedantic = true;
- break;
- case '-h':
- case '--help':
- return help();
- default:
- files.push(arg);
- break;
- }
- }
-
- if (!input) {
- if (files.length <= 2) {
- var stdin = process.stdin;
-
- stdin.setEncoding('utf8');
- stdin.resume();
-
- stdin.on('data', function(text) {
- data += text;
- });
-
- stdin.on('end', write);
-
- return;
- }
- input = files.pop();
- }
-
- data = fs.readFileSync(input, 'utf8');
- write();
-
- function write() {
- marked.setOptions(options);
-
- data = tokens
- ? JSON.stringify(marked.lexer(data), null, 2)
- : marked(data);
-
- if (!output) {
- process.stdout.write(data + '\n');
- } else {
- fs.writeFileSync(output, data);
- }
- }
-};
-
-if (!module.parent) {
- process.title = 'marked';
- main(process.argv.slice());
-} else {
- module.exports = main;
-}
View
25 doc/SYNTAX.html
@@ -96,14 +96,19 @@
<hr>
<p>Indent every line of a code block by at least 4 spaces or 1 tab.</p>
<p>This is a normal paragraph.</p>
-<pre><code>This <span class="keyword">is</span> a preformatted
+<pre id="code-1"><code>This <span class="keyword">is</span> a preformatted
code <span class="keyword">block</span>.</code></pre>
<p>Code blocks can also be &quot;fenced&quot; by <code> ``` </code> (GitHub-Flavored-Markdown)</p>
-<pre><code>console<span class="preprocessor">.log</span>(<span class="string">"flock yeah!"</span>)<span class="comment">;</span></code></pre>
+<pre id="code-2"><code>console<span class="preprocessor">.log</span>(<span class="string">"flock yeah!"</span>)<span class="comment">;</span></code></pre>
<p>For extra awesome, add the name of a programming language to the first fence, in order to syntax highlight it.</p>
-<pre><code class="language-perl">var <span class="keyword">x</span> = function () {
+<pre id="code-3"><code class="language-perl">var <span class="keyword">x</span> = function () {
console.<span class="keyword">log</span>(<span class="string">"This actually has 'perl' as a tag!"</span>)
};</code></pre>
+<pre class="demo" id="code-4"><code class="language-ruby"><span class="class"><span class="keyword">module</span> <span class="title">Test</span></span>
+
+ <span class="function"><span class="keyword">def</span> <span class="title">demo</span></span>
+ puts <span class="string">"This is testing the demo construction"</span>
+ <span class="keyword">end</span></code></pre>
<p>(Highlighting is enabled by default; you&#39;ll have to define your own CSS that matches the highlight-js notation, though, which this document does not do!)</p>
<h2>STRIKETHROUGH</h2>
<p>Hey, this is <del>terrible</del> great!</p>
@@ -157,8 +162,8 @@
</ul>
<p>Orange
: The fruit of an evergreen tree of the genus Citrus.</p>
-<pre><code class="language-python"><span class="keyword">print</span> <span class="string">"Testing yet again"</span></code></pre>
-<pre><code>It<span class="attribute">'s</span> extremly hard <span class="keyword">to</span> come up <span class="keyword">with</span> make believe text.</code></pre>
+<pre id="code-5"><code class="language-python"><span class="keyword">print</span> <span class="string">"Testing yet again"</span></code></pre>
+<pre id="code-6"><code>It<span class="attribute">'s</span> extremly hard <span class="keyword">to</span> come up <span class="keyword">with</span> make believe text.</code></pre>
<p>Pomegranate
: A deciduous shrub or small tree (Punica granatum), native to Asia and <em>widely cultivated</em> for its edible fruit.
Anyway, Blah blah blah.adsadsasd.</p>
@@ -167,7 +172,7 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus.
: Second definition for term 1, also wrapped in a paragraph</p>
-<pre><code><span class="title">because</span> <span class="keyword">of</span> the blank line preceding it. {: .test} </code></pre>
+<pre id="code-7"><code><span class="title">because</span> <span class="keyword">of</span> the blank line preceding it. {: .test} </code></pre>
<p>{: #TestingIDHere}</p>
<h2>ATTRIBUTES (Maruku)</h2>
<p>{: #myid .myclass}</p>
@@ -180,7 +185,7 @@
<h2>AUTO-LINK</h2>
<hr>
<p><a href="http://foo.com/">http://foo.com/</a> </p>
-<a href="&#x6d;&#97;&#x69;&#x6c;&#x74;&#x6f;&#58;&#x66;&#111;&#111;&#64;&#x62;&#97;&#114;&#x2e;&#99;&#111;&#109;">&#x66;&#111;&#111;&#64;&#x62;&#97;&#114;&#x2e;&#99;&#111;&#109;</a>
+<a href="&#x6d;&#97;&#x69;&#x6c;&#116;&#111;&#58;&#102;&#111;&#x6f;&#x40;&#98;&#x61;&#x72;&#x2e;&#x63;&#x6f;&#x6d;">&#102;&#111;&#x6f;&#x40;&#98;&#x61;&#x72;&#x2e;&#x63;&#x6f;&#x6d;</a>
<h2>ENCODING</h2>
<hr>
@@ -192,7 +197,9 @@
<div class="alert alert-info"><h4 class="alert-heading">Tip: </h4>This should be wrapped in a div that looks like this: <code>&lt;div class=&#39;alert alert-info&#39;&gt;</code>
</div>
-<p>Warning: And <em>this</em> should be wrapped in a div like this: <code>&lt;div class=&#39;alert alert-block&#39;&gt;</code></p>
+<div class="alert alert-block"><h4 class="alert-heading">Warning: </h4>And <em>this</em> should be wrapped in a div like this: <code>&lt;div class=&#39;alert alert-block&#39;&gt;</code>
+
+</div>
<p>These classes have to do with Twitter Bootstrap stylings for <code>Note: </code>, <code>Tip: </code>, and <code>Warning: </code>.</p>
<h2>INLINE HTML</h2>
<hr>
@@ -216,4 +223,4 @@
<p><em>Your Name</em>, Setup, Develop, Stuff</p>
<h2>Menus</h2>
<hr>
-<p>Click <span class="menucascade"><span class="menuitem"><em><strong>Your Name</strong></em></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Setup</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Develop</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Stuff</strong></span>. For Visualforce components, click <span class="menucascade"><span class="menuitem"><strong>Blah</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Setup</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Develop</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Components</strong></span>.</p>
+<p>Click <span class="menucascade"><span class="menuitem"><em><strong>Your Name</strong></em></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Setup</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Develop</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Stuff</strong></span></span>. For Visualforce components, click <span class="menucascade"><span class="menuitem"><strong>Blah</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Setup</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Develop</strong></span><span class='menudivider'> <strong>&gt;</strong> </span><span class='menuitem'><strong>Components</strong></span></span>.</p>
View
8 doc/SYNTAX.md
@@ -137,6 +137,14 @@ var x = function () {
};
```
+```ruby, demo
+module Test
+
+ def demo
+ puts "This is testing the demo construction"
+ end
+```
+
(Highlighting is enabled by default; you'll have to define your own CSS that matches the highlight-js notation, though, which this document does not do!)
## STRIKETHROUGH
View
2  index.js
@@ -1 +1 @@
-module.exports = require('./lib/marked');
+module.exports = require('./lib/namp');
View
53 lib/namp.js
@@ -1,5 +1,5 @@
/**
- * marked - Not another markdown parser (https://github.com/gjtorikian/namp)
+ * namp - Not another markdown parser (https://github.com/gjtorikian/namp)
* Copyright (c) 2011-2012, Garen Torikian. (MIT Licensed)
*/
@@ -76,7 +76,7 @@ block.normal = {
};
block.gfm = {
- fences: /^ *``` *([\w\-]+)? *\n([^\0]+?)\s*``` *(?:\n+|$)/,
+ fences: /^ *``` *([\w\-]+)?(,\s*demo)? *\n([^\0]+?)\s*``` *(?:\n+|$)/,
paragraph: /^/
};
@@ -91,11 +91,9 @@ block.gfm.paragraph = replace(block.paragraph)
('(?!', '(?!' + block.gfm.fences.source.replace(/(^|[^\[])\^/g, '$1') + '|')
();
-var namp = {
- documentMeta: /^(\w+): (.+)\n/
-}
+documentMeta = /^(\w+): (.+)\n/;
-var metadata = { };
+codeCounter = 0;
/**
* Block Lexer
@@ -127,7 +125,7 @@ block.token = function(src, tokens, top) {
while (src) {
// add doc metadata
- if (!firstBlock && (cap = namp.documentMeta.exec(src))) {
+ if (!firstBlock && (cap = documentMeta.exec(src))) {
src = src.substring(cap[0].length);
if (cap[0].length > 1) {
tokens.push({
@@ -169,7 +167,8 @@ block.token = function(src, tokens, top) {
tokens.push({
type: 'code',
lang: cap[1],
- text: cap[2]
+ demo: cap[2],
+ text: cap[3]
});
continue;
}
@@ -712,7 +711,7 @@ function next() {
return token = tokens.pop();
}
-function tok() {
+function tok(metadata) {
switch (token.type) {
case 'space': {
return '';
@@ -747,7 +746,12 @@ function tok() {
token.text = hljs.highlightAuto(token.text).value;
// intentionally skip 'no-highlight'
- return '<pre><code'
+ var pretag = "<pre "
+ if (token.demo !== undefined)
+ pretag += 'class="demo" ';
+ pretag += 'id="code-' + ++codeCounter + '">';
+
+ return pretag + '<code'
+ (token.lang
? ' class="language-'
+ token.lang
@@ -867,14 +871,16 @@ function parse(src) {
tokens = src.reverse();
var out = '';
+ var metadata = {};
+
while (next()) {
- out += tok();
+ out += tok(metadata);
}
tokens = null;
token = null;
- return out;
+ return [out, metadata];
}
/**
@@ -933,9 +939,10 @@ noop.exec = noop;
* Marked
*/
-function marked(src, opt) {
+function namp(src, opt) {
setOptions(opt);
- return { html: parse(block.lexer(src)), metadata: metadata };
+ var parsedReturn = parse(block.lexer(src));
+ return { html: parsedReturn[0], metadata: parsedReturn[1] };
}
/**
@@ -964,14 +971,14 @@ function setOptions(opt) {
}
}
-marked.options =
-marked.setOptions = function(opt) {
+namp.options =
+namp.setOptions = function(opt) {
defaults = opt;
setOptions(opt);
- return marked;
+ return namp;
};
-marked.setOptions({
+namp.setOptions({
namp: true,
pedantic: false,
sanitize: false,
@@ -983,22 +990,22 @@ marked.setOptions({
* Expose
*/
-marked.parser = function(src, opt) {
+namp.parser = function(src, opt) {
setOptions(opt);
return parse(src);
};
-marked.lexer = function(src, opt) {
+namp.lexer = function(src, opt) {
setOptions(opt);
return block.lexer(src);
};
-marked.parse = marked;
+namp.parse = namp;
if (typeof module !== 'undefined') {
- module.exports = marked;
+ module.exports = namp;
} else {
- this.marked = marked;
+ this.namp = namp;
}
}).call(function() {
View
49 man/marked.1
@@ -1,49 +0,0 @@
-.ds q \N'34'
-.TH marked 1
-.SH NAME
-marked \- a javascript markdown parser
-.SH SYNOPSIS
-.nf
-.B marked [\-o output] [\-i input] [\-th]
-.fi
-.SH DESCRIPTION
-.B marked
-is a full-featured javascript markdown parser, built for speed. It also includes
-multiple GFM features.
-.SH OPTIONS
-.TP
-.BI \-o,\ \-\-output\ [output]
-Specify file output. If none is specified, write to stdout.
-.TP
-.BI \-i,\ \-\-input\ [input]
-Specify file input, otherwise use last argument as input file. If no input file
-is specified, read from stdin.
-.TP
-.BI \-t,\ \-\-tokens
-Output a token stream instead of html.
-.TP
-.BI \-\-pedantic
-Conform to obscure parts of markdown.pl as much as possible. Don't fix original
-markdown bugs.
-.TP
-.BI \-\-gfm
-Enable github flavored markdown.
-.TP
-.BI \-\-sanitize
-Sanitize output. Ignore any HTML input.
-.TP
-.BI \-h,\ \-\-help
-Display help information.
-.SH EXAMPLES
-.TP
-cat in.md | marked > out.html
-.TP
-echo "hello *world*" | marked
-.TP
-marked -o out.html in.md
-.TP
-marked --output="hello world.html" -i in.md
-.SH BUGS
-Please report any bugs to https://github.com/chjj/marked.
-.SH LICENSE
-Copyright (c) 2011-2012, Christopher Jeffrey (MIT License)
View
6 package.json
@@ -1,7 +1,7 @@
{
"name" : "namp",
- "version" : "0.2.13",
- "description" : "Markdown parser for Node, with Maruku, GFM, and PHP Extras support, plus more.",
+ "version" : "0.2.14",
+ "description" : "Markdown parser for Node, with Maruku, GFM, and PHP Extras support, plus more. Based on marked.",
"keywords" : [ "markdown", "maruku", "gfm", "text processing", "ast" ],
"maintainers" : [
{
@@ -27,8 +27,6 @@
"url" : "git://github.com/gjtorikian/namp.git"
},
"main": "./lib/namp.js",
- "bin": "./bin/namp",
- "man": "./man/marked.1",
"dependencies": {
"highlight.js": ">=7.0.0"
}
View
20 test/index.js
@@ -2,7 +2,7 @@
var fs = require('fs')
, path = require('path')
- , marked = require('marked')
+ , namp = require('namp')
, dir = __dirname + '/tests';
var BREAK_ON_ERROR = false;
@@ -56,7 +56,7 @@ main:
file = files[filename];
try {
- text = marked(file.text).replace(/\s/g, '');
+ text = namp(file.text).replace(/\s/g, '');
html = file.html.replace(/\s/g, '');
} catch(e) {
console.log('%s failed.', filename);
@@ -136,14 +136,14 @@ main.bench = function(name, func) {
};
var bench = function() {
- marked.setOptions({ gfm: false });
- main.bench('marked', marked);
+ namp.setOptions({ gfm: false });
+ main.bench('namp', namp);
- marked.setOptions({ gfm: true });
- main.bench('marked (gfm)', marked);
+ namp.setOptions({ gfm: true });
+ main.bench('namp (gfm)', namp);
- marked.setOptions({ pedantic: true });
- main.bench('marked (pedantic)', marked);
+ namp.setOptions({ pedantic: true });
+ main.bench('namp (pedantic)', namp);
var discount = require('discount').parse;
main.bench('discount', discount);
@@ -173,8 +173,8 @@ var bench = function() {
};
var time = function() {
- var marked = require('../');
- main.bench('marked', marked);
+ var namp = require('../');
+ main.bench('namp', namp);
};
if (!module.parent) {
Please sign in to comment.
Something went wrong with that request. Please try again.