Permalink
Browse files

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

  • Loading branch information...
1 parent aa800f7 commit 289158a700878ee9779a8912cc38119ca801ff27 @gjtorikian committed Oct 24, 2012
Showing with 67 additions and 223 deletions.
  1. +0 −127 bin/namp
  2. +16 −9 doc/SYNTAX.html
  3. +8 −0 doc/SYNTAX.md
  4. +1 −1 index.js
  5. +30 −23 lib/namp.js
  6. +0 −49 man/marked.1
  7. +2 −4 package.json
  8. +10 −10 test/index.js
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
@@ -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
@@ -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
@@ -1 +1 @@
-module.exports = require('./lib/marked');
+module.exports = require('./lib/namp');
View
@@ -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() {
Oops, something went wrong.

0 comments on commit 289158a

Please sign in to comment.