Skip to content
This repository has been archived by the owner on Jul 16, 2019. It is now read-only.

Commit

Permalink
Support MD in HTML blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Aug 4, 2012
1 parent ef222e7 commit 0463cef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2011-2012, Christopher Jeffrey (https://github.com/chjj/)
Copyright (c) 2011-2012, Garen Torikian https://github.com/gjtorikian/)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -24,6 +24,8 @@ Maruku only allowed you to do inline IDs for stylized text, like `code`, **stron
* Conversion of `Note: `, `Tip: `, and `Warning: ` blocks into [Twitter Bootstrap alert blocks](http://twitter.github.com/bootstrap/components.html#alerts). Awesome!
* Build-time highlighting of `<pre>` code blocks. Enabled by default, see below for configuration instructions. (**NOT YET SUPPORTED**)

* Markdown wrapped in `<div marked="1">` is processed.

namp was forked from [marked](https://github.com/chjj/marked), which is a super-fast Markdown parser that handles all the standard GFM syntax.

For a demonstration of all the additional add-ons, take a look at the _/doc_ folder.
Expand Down Expand Up @@ -189,6 +191,8 @@ $ cat hello.html
## License
Copyright (c) 2011-2012, Christopher Jeffrey. (MIT License)
Copyright (c) 2011-2012, Garen Torikian. (MIT License)
See LICENSE for more info.
Based mostly on Christopher Jeffrey (https://github.com/chjj/)
23 changes: 23 additions & 0 deletions lib/namp.js
Expand Up @@ -21,6 +21,7 @@ var block = {
blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,
list: /^( *)(bull) [^\0]+?(?:hr|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
html_closed: /^ *(?:closed) *(?:\n{2,}|\s*$)/,
def: /^ *\[([^\]]+)\]: *([^\s]+)(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
paragraph: /^([^\n]+\n?(?!body))+\n*/,
text: /^[^\n]+/
Expand All @@ -44,6 +45,11 @@ block.html = replace(block.html)
(/tag/g, tag())
();

block.html_closed = replace(block.html_closed)
('closed', /<(tag)([^\0]+?)<\/\1>/)
(/tag/g, tag())
();

block.paragraph = (function() {
var paragraph = block.paragraph.source
, body = [];
Expand Down Expand Up @@ -284,6 +290,23 @@ block.token = function(src, tokens, top) {
continue;
}

// html_closed
if (cap = block.html_closed.exec(src)) {
var atts = cap[2].substring(0,cap[2].indexOf(">"));
if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) {
var inner = cap[2].substring(atts.length+1);
src = src.substring(cap[0].length);
tokens.push({
type: 'html', pre: cap[1]==='pre', text: "<"+cap[1]+atts+">"
});
block.token(inner,tokens,false);
tokens.push({
type: 'html', pre: cap[1]==='pre', text: "</"+cap[1]+">"
});
continue;
}
}

// html
if (cap = block.html.exec(src)) {
src = src.substring(cap[0].length);
Expand Down

0 comments on commit 0463cef

Please sign in to comment.