marked/lib/marked.js

691 lines
14 KiB
JavaScript
Raw Normal View History

2011-07-24 08:15:35 -05:00
/**
* marked - A markdown parser (https://github.com/chjj/marked)
2012-01-03 00:35:47 -06:00
* Copyright (c) 2011-2012, Christopher Jeffrey. (MIT Licensed)
2011-07-24 08:15:35 -05:00
*/
2011-08-13 23:19:46 -05:00
;(function() {
2011-07-24 08:15:35 -05:00
/**
* Block-Level Grammar
*/
2011-08-13 23:19:46 -05:00
var block = {
2011-08-18 18:59:42 -05:00
newline: /^\n+/,
code: /^ {4,}[^\n]*(?:\n {4,}[^\n]*|\n)*(?:\n+| *$)/,
gfm_code: /^ *``` *(\w+)? *\n([^\0]+?)\s*```(?: *\n+| *$)/,
hr: /^( *[\-*_]){3,} *\n+/,
2011-09-14 12:41:51 -05:00
heading: /^ *(#{1,6}) *([^\0]+?) *#* *\n+/,
lheading: /^([^\n]+)\n *(=|-){3,} *\n*/,
blockquote: /^( *>[^\n]+(\n[^\n]+)*)+\n*/,
list: /^( *)([*+-]|\d+\.) [^\0]+?(?:\n{2,}(?! )|\s*$)(?!\1bullet)\n*/,
2012-01-06 14:41:27 -06:00
html: /^ *(?:comment|closed|closing) *(?:\n{2,}|\s*$)/,
paragraph: /^([^\n]+\n?(?!body))+\n*/,
text: /^[^\n]+/
2011-07-24 08:15:35 -05:00
};
2012-01-10 14:13:57 -06:00
block.list = (function() {
var list = block.list.source;
list = list
.replace('bullet', /(?:[*+-](?!(?: *[-*]){2,})|\d+\.)/.source);
2012-01-10 14:13:57 -06:00
return new RegExp(list);
})();
2012-01-06 14:41:27 -06:00
block.html = (function() {
var html = block.html.source;
2012-01-14 03:39:32 -06:00
// The real markdown checks for block elements.
// It's better to check for non-inline elements.
// Unknown elements will then be treated as block elements.
var closed = '<(?!(?:'
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
+ '|span|br|wbr|ins|del|img)\\b)'
+ '(\\w+)[^\\0]+?</\\1>';
2012-01-06 14:41:27 -06:00
html = html
.replace('comment', /<!--[^\0]*?-->/.source)
2012-01-14 03:39:32 -06:00
.replace('closed', closed)
.replace('closing', /<\w+(?!:\/|@)\b(?:"[^"]*"|'[^']*'|[^>])*>/.source);
2012-01-06 16:44:48 -06:00
2012-01-10 14:13:57 -06:00
return new RegExp(html);
2012-01-06 14:41:27 -06:00
})();
block.paragraph = (function() {
2012-01-06 14:41:27 -06:00
var paragraph = block.paragraph.source
, body = [];
(function push(rule) {
rule = rule.source || block[rule].source;
body.push(rule.replace(/(^|[^\[])\^/g, '$1'));
return push;
})
('gfm_code')
('hr')
('heading')
('lheading')
('blockquote')
(new RegExp('<'
+ '(?:article|aside|audio|blockquote|canvas|caption|col|colgroup|dialog|div'
+ '|d[ltd]|embed|fieldset|figure|figcaption|footer|form|h[1-6r]|header'
+ '|hgroup|input|label|legend|li|nav|noscript|object|[ou]l|optgroup|option'
+ '|p|param|pre|script|section|select|source|table|t(?:body|foot|head)'
+ '|t[dhr]|textarea|video)\\b'));
return new
2012-01-06 14:41:27 -06:00
RegExp(paragraph.replace('body', body.join('|')));
})();
2011-07-24 08:15:35 -05:00
/**
2011-10-22 23:39:04 -05:00
* Block Lexer
2011-07-24 08:15:35 -05:00
*/
2011-08-13 23:19:46 -05:00
block.lexer = function(str) {
2011-08-13 17:06:08 -05:00
var tokens = []
, links = {};
2011-07-24 08:15:35 -05:00
2011-10-04 17:40:33 -05:00
str = str.replace(/\r\n|\r/g, '\n')
2011-08-14 02:47:56 -05:00
.replace(/\t/g, ' ');
2011-08-13 23:19:46 -05:00
2011-08-13 17:06:08 -05:00
str = str.replace(
/^ {0,3}\[([^\]]+)\]: *([^ ]+)(?: +["(]([^\n]+)[")])? *$/gm,
2011-08-21 09:01:03 -05:00
function(__, id, href, title) {
links[id.toLowerCase()] = {
2011-08-13 23:19:46 -05:00
href: href,
2011-08-21 09:01:03 -05:00
title: title
2011-08-13 23:19:46 -05:00
};
return '';
}
);
2011-08-13 17:06:08 -05:00
tokens.links = links;
2011-07-24 08:15:35 -05:00
return block.token(str, tokens, true);
2011-08-13 17:06:08 -05:00
};
2011-08-13 16:53:15 -05:00
block.token = function(str, tokens, top) {
2011-10-22 06:09:28 -05:00
var str = str.replace(/^ +$/gm, '')
, loose
2011-10-22 07:49:11 -05:00
, cap
, item
, space
, i
, l;
2011-10-22 06:09:28 -05:00
while (str) {
2011-10-22 23:39:04 -05:00
// newline
2011-10-22 06:09:28 -05:00
if (cap = block.newline.exec(str)) {
str = str.substring(cap[0].length);
if (cap[0].length > 1) {
tokens.push({
type: 'space'
});
2011-08-14 01:02:14 -05:00
}
2011-10-22 06:09:28 -05:00
}
2011-10-22 23:39:04 -05:00
// code
2011-10-22 08:05:31 -05:00
if (cap = block.code.exec(str)) {
2011-10-22 06:09:28 -05:00
str = str.substring(cap[0].length);
cap = cap[0].replace(/^ {4}/gm, '');
tokens.push({
2011-10-22 08:05:31 -05:00
type: 'code',
text: cap.replace(/\n+$/, '')
2011-10-22 06:09:28 -05:00
});
continue;
}
2012-01-02 04:10:23 -06:00
// gfm_code
if (cap = block.gfm_code.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'code',
lang: cap[1],
text: cap[2]
});
continue;
}
2011-10-22 23:39:04 -05:00
// heading
2011-10-22 06:09:28 -05:00
if (cap = block.heading.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'heading',
depth: cap[1].length,
text: cap[2]
});
continue;
}
2011-10-22 23:39:04 -05:00
// lheading
2011-10-22 06:09:28 -05:00
if (cap = block.lheading.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'heading',
depth: cap[2] === '=' ? 1 : 2,
text: cap[1]
});
continue;
}
2011-10-22 23:39:04 -05:00
// hr
2011-10-22 06:09:28 -05:00
if (cap = block.hr.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'hr'
});
continue;
}
2011-10-22 23:39:04 -05:00
// blockquote
2011-10-22 06:09:28 -05:00
if (cap = block.blockquote.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'blockquote_start'
});
2012-01-06 16:44:48 -06:00
2011-10-22 06:09:28 -05:00
cap = cap[0].replace(/^ *>/gm, '');
// Pass `top` to keep the current
// "toplevel" state. This is exactly
// how markdown.pl works.
block.token(cap, tokens, top);
2011-10-22 06:09:28 -05:00
tokens.push({
type: 'blockquote_end'
});
continue;
2011-08-14 01:02:14 -05:00
}
2011-10-22 06:09:28 -05:00
2011-10-22 23:39:04 -05:00
// list
2011-10-22 06:09:28 -05:00
if (cap = block.list.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'list_start',
ordered: isFinite(cap[2])
});
loose = /\n *\n *(?:[*+-]|\d+\.)/.test(cap[0]);
// Get each top-level item.
2011-10-22 06:09:28 -05:00
cap = cap[0].match(
/^( *)([*+-]|\d+\.)[^\n]*(?:\n(?!\1(?:[*+-]|\d+\.))[^\n]*)*/gm
2011-10-22 06:09:28 -05:00
);
2011-10-22 23:39:04 -05:00
i = 0;
l = cap.length;
2011-10-22 07:49:11 -05:00
for (; i < l; i++) {
// Remove the list item's bullet
// so it is seen as the next token.
2011-10-22 07:49:11 -05:00
item = cap[i].replace(/^ *([*+-]|\d+\.) */, '');
// Outdent whatever the
// list item contains. Hacky.
2011-10-22 07:49:11 -05:00
space = /\n( +)/.exec(item);
2011-10-22 06:09:28 -05:00
if (space) {
space = new RegExp('^' + space[1], 'gm');
item = item.replace(space, '');
2011-08-18 18:59:42 -05:00
}
2011-08-14 01:04:35 -05:00
tokens.push({
2011-10-22 06:09:28 -05:00
type: loose
? 'loose_item_start'
: 'list_item_start'
2011-08-14 01:04:35 -05:00
});
// Recurse.
2011-10-22 06:09:28 -05:00
block.token(item, tokens);
2011-08-14 01:04:35 -05:00
tokens.push({
2011-10-22 06:09:28 -05:00
type: 'list_item_end'
2011-08-14 01:04:35 -05:00
});
2011-10-22 07:49:11 -05:00
}
2011-10-22 06:09:28 -05:00
tokens.push({
type: 'list_end'
});
continue;
}
2011-10-22 23:39:04 -05:00
// html
2011-10-22 06:09:28 -05:00
if (cap = block.html.exec(str)) {
str = str.substring(cap[0].length);
tokens.push({
type: 'html',
text: cap[0]
});
continue;
}
// top-level paragraph
if (top && (cap = block.paragraph.exec(str))) {
2011-10-22 06:09:28 -05:00
str = str.substring(cap[0].length);
tokens.push({
type: 'paragraph',
2011-10-22 06:09:28 -05:00
text: cap[0]
});
continue;
2011-08-14 01:04:35 -05:00
}
2012-01-03 02:25:47 -06:00
// text
if (cap = block.text.exec(str)) {
// Top-level should never reach here.
2012-01-03 02:25:47 -06:00
str = str.substring(cap[0].length);
tokens.push({
type: 'text',
text: cap[0]
});
continue;
}
2011-08-13 16:53:15 -05:00
}
2011-07-24 08:15:35 -05:00
return tokens;
};
/**
* Inline Processing
*/
2011-08-13 23:19:46 -05:00
var inline = {
2012-01-09 11:58:03 -06:00
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
2011-08-18 19:31:53 -05:00
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
gfm_autolink: /^(\w+:\/\/[^\s]+[^.,:;"')\]\s])/,
tag: /^<!--[^\0]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^>])*>/,
link: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\[|\](?=[^[\]]*\]))*)\]\(([^\)]*)\)/,
reflink: /^!?\[((?:\[[^\]]*\]|[^\[\]]|\[|\](?=[^[\]]*\]))*)\]\s*\[([^\]]*)\]/,
2011-08-22 11:02:21 -05:00
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
// discount em/strong behavior
// strong: /^__([^\0]+?)__(?!_)|^\*\*([^\0]+?)\*\*(?!\*)/,
// em: /^\b_(?=\S)([^\0]*?\S)_\b|^\*(?=\S)([^\0]*?(?:\*\*|[^\s*]))\*(?!\*)/,
// markdown.js em/strong behavior
strong: /^__([^\0]+?)__(?!_)|^\*\*([^\0]+?)\*\*(?!\*)/,
em: /^\b_([^\0]+?)_\b|^\*((?:\*\*|[^\0])+?)\*(?!\*)/,
// markdown.pl em/strong behavior
// strong: /^__(?=\S)([^\0]*?\S)__(?!_)|^\*\*(?=\S)([^\0]*?\S)\*\*(?!\*)/,
// em: /^\b_(?=\S)([^\0]*?\S)_\b|^\*(?=\S)([^\0]*?\S)\*(?!\*)/,
2012-01-09 07:13:03 -06:00
code: /^(`+)([^\0]*?[^`])\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
2012-01-06 14:41:27 -06:00
text: /^[^\0]+?(?=body|$)/
2011-08-13 23:19:46 -05:00
};
2011-08-13 21:04:18 -05:00
2011-08-22 16:19:43 -05:00
inline.text = (function() {
2012-01-06 14:41:27 -06:00
var text = inline.text.source
, body = [];
2011-08-14 02:35:37 -05:00
2011-08-22 16:19:43 -05:00
(function push(rule) {
rule = inline[rule].source;
body.push(rule.replace(/(^|[^\[])\^/g, '$1'));
return push;
})
('escape')
('gfm_autolink')
2011-08-22 16:19:43 -05:00
('tag')
('nolink')
('strong')
('em')
2011-08-24 10:10:34 -05:00
('code')
('br');
2011-08-14 02:35:37 -05:00
2011-10-04 17:32:59 -05:00
return new
2012-01-06 14:41:27 -06:00
RegExp(text.replace('body', body.join('|')));
2011-08-22 16:19:43 -05:00
})();
2011-08-13 23:19:46 -05:00
/**
* Inline Lexer
*/
inline.lexer = function(str) {
2011-08-14 01:02:14 -05:00
var out = ''
, links = tokens.links
2011-08-18 19:26:23 -05:00
, link
2011-08-14 01:02:14 -05:00
, text
2011-10-22 06:09:28 -05:00
, href
2011-08-14 01:02:14 -05:00
, cap;
2011-08-13 23:36:44 -05:00
2011-10-22 06:09:28 -05:00
while (str) {
2011-10-22 23:39:04 -05:00
// escape
2011-10-22 06:09:28 -05:00
if (cap = inline.escape.exec(str)) {
str = str.substring(cap[0].length);
out += cap[1];
continue;
}
2011-10-22 23:39:04 -05:00
// autolink
2011-10-22 06:09:28 -05:00
if (cap = inline.autolink.exec(str)) {
str = str.substring(cap[0].length);
if (cap[2] === '@') {
text = cap[1][6] === ':'
? mangle(cap[1].substring(7))
: mangle(cap[1]);
href = mangle('mailto:') + text;
} else {
text = escape(cap[1]);
href = text;
2011-08-13 21:04:18 -05:00
}
2011-10-22 08:05:31 -05:00
out += '<a href="'
+ href
+ '">'
2011-10-22 06:09:28 -05:00
+ text
+ '</a>';
continue;
2011-08-13 21:04:18 -05:00
}
2011-10-22 06:09:28 -05:00
// gfm_autolink
if (cap = inline.gfm_autolink.exec(str)) {
str = str.substring(cap[0].length);
text = escape(cap[1]);
href = text;
out += '<a href="'
+ href
+ '">'
+ text
+ '</a>';
continue;
}
2011-10-22 23:39:04 -05:00
// tag
2011-10-22 06:09:28 -05:00
if (cap = inline.tag.exec(str)) {
str = str.substring(cap[0].length);
out += cap[0];
continue;
}
2011-10-22 23:39:04 -05:00
// link
2011-10-22 06:09:28 -05:00
if (cap = inline.link.exec(str)) {
str = str.substring(cap[0].length);
text = /^\s*<?([^\s]*?)>?(?:\s+"([^\n]+)")?\s*$/.exec(cap[2]);
2012-01-09 06:57:57 -06:00
if (!text) {
out += cap[0][0];
str = cap[0].substring(1) + str;
continue;
}
2011-10-22 06:09:28 -05:00
link = {
href: text[1],
title: text[2]
};
out += mlink(cap, link);
continue;
}
2011-10-22 23:39:04 -05:00
// reflink, nolink
2011-10-22 06:09:28 -05:00
if ((cap = inline.reflink.exec(str))
|| (cap = inline.nolink.exec(str))) {
str = str.substring(cap[0].length);
link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
link = links[link.toLowerCase()];
2012-01-14 03:33:28 -06:00
if (!link || !link.href) {
2011-10-22 06:09:28 -05:00
out += cap[0][0];
str = cap[0].substring(1) + str;
continue;
}
out += mlink(cap, link);
continue;
}
2011-10-22 23:39:04 -05:00
// strong
2011-10-22 06:09:28 -05:00
if (cap = inline.strong.exec(str)) {
str = str.substring(cap[0].length);
out += '<strong>'
+ inline.lexer(cap[2] || cap[1])
+ '</strong>';
continue;
}
2011-10-22 23:39:04 -05:00
// em
2011-10-22 06:09:28 -05:00
if (cap = inline.em.exec(str)) {
str = str.substring(cap[0].length);
out += '<em>'
+ inline.lexer(cap[2] || cap[1])
+ '</em>';
continue;
}
2011-10-22 23:39:04 -05:00
// code
2011-10-22 06:09:28 -05:00
if (cap = inline.code.exec(str)) {
str = str.substring(cap[0].length);
out += '<code>'
+ escape(cap[2] || cap[1], true)
2011-10-22 06:09:28 -05:00
+ '</code>';
continue;
}
2011-10-22 23:39:04 -05:00
// br
2011-10-22 06:09:28 -05:00
if (cap = inline.br.exec(str)) {
str = str.substring(cap[0].length);
out += '<br>';
continue;
}
2011-10-22 23:39:04 -05:00
// text
2011-10-22 06:09:28 -05:00
if (cap = inline.text.exec(str)) {
str = str.substring(cap[0].length);
out += escape(cap[0]);
continue;
2011-08-14 01:04:35 -05:00
}
2011-08-13 23:19:46 -05:00
}
2011-08-13 21:04:18 -05:00
2011-08-13 23:19:46 -05:00
return out;
};
2011-08-13 21:04:18 -05:00
2011-10-22 06:09:28 -05:00
var mlink = function(cap, link) {
if (cap[0][0] !== '!') {
return '<a href="'
+ escape(link.href)
+ '"'
+ (link.title
2012-01-14 03:27:06 -06:00
? ' title="'
+ escape(link.title)
+ '"'
: '')
2011-10-22 06:09:28 -05:00
+ '>'
+ inline.lexer(cap[1])
+ '</a>';
} else {
return '<img src="'
+ escape(link.href)
+ '" alt="'
+ escape(cap[1])
+ '"'
+ (link.title
2012-01-14 03:27:06 -06:00
? ' title="'
+ escape(link.title)
+ '"'
: '')
2011-10-22 06:09:28 -05:00
+ '>';
}
};
2011-07-24 08:15:35 -05:00
/**
* Parsing
*/
2011-08-13 17:06:08 -05:00
var tokens
, token;
2011-08-13 16:38:46 -05:00
2011-07-24 08:15:35 -05:00
var next = function() {
return token = tokens.pop();
};
var tok = function() {
switch (token.type) {
2011-10-22 06:18:15 -05:00
case 'space': {
2011-08-18 18:59:42 -05:00
return '';
2011-10-22 06:18:15 -05:00
}
case 'hr': {
2011-07-24 08:15:35 -05:00
return '<hr>';
2011-10-22 06:18:15 -05:00
}
case 'heading': {
return '<h'
+ token.depth
+ '>'
2011-08-13 23:19:46 -05:00
+ inline.lexer(token.text)
2011-10-22 06:18:15 -05:00
+ '</h'
+ token.depth
+ '>';
}
2011-10-22 08:05:31 -05:00
case 'code': {
return '<pre><code'
+ (token.lang
2012-01-14 03:27:06 -06:00
? ' class="'
+ token.lang
+ '"'
: '')
+ '>'
+ (token.escaped
2012-01-14 03:27:06 -06:00
? token.text
: escape(token.text, true))
2011-07-24 08:15:35 -05:00
+ '</code></pre>';
2011-10-22 06:18:15 -05:00
}
case 'blockquote_start': {
2011-07-24 08:15:35 -05:00
var body = [];
2011-10-22 06:18:15 -05:00
2011-07-24 08:15:35 -05:00
while (next().type !== 'blockquote_end') {
body.push(tok());
}
2011-10-22 06:18:15 -05:00
2011-10-04 17:32:59 -05:00
return '<blockquote>'
+ body.join('')
2011-07-24 08:15:35 -05:00
+ '</blockquote>';
2011-10-22 06:18:15 -05:00
}
case 'list_start': {
2011-10-04 17:32:59 -05:00
var type = token.ordered ? 'ol' : 'ul'
, body = [];
2011-10-22 06:18:15 -05:00
2011-07-24 08:15:35 -05:00
while (next().type !== 'list_end') {
body.push(tok());
}
2011-10-22 06:18:15 -05:00
return '<'
+ type
+ '>'
2011-10-04 17:32:59 -05:00
+ body.join('')
2011-10-22 06:18:15 -05:00
+ '</'
+ type
+ '>';
}
case 'list_item_start': {
2011-07-24 08:15:35 -05:00
var body = [];
2011-10-22 06:18:15 -05:00
2011-07-24 08:15:35 -05:00
while (next().type !== 'list_item_end') {
2011-08-20 10:46:35 -05:00
body.push(token.type === 'text'
2011-10-04 17:32:59 -05:00
? text()
2011-08-15 20:35:57 -05:00
: tok());
2011-07-24 08:15:35 -05:00
}
2011-10-22 06:18:15 -05:00
2011-10-04 17:32:59 -05:00
return '<li>'
+ body.join(' ')
2011-07-24 08:15:35 -05:00
+ '</li>';
2011-10-22 06:18:15 -05:00
}
case 'loose_item_start': {
2011-08-20 08:59:47 -05:00
var body = [];
2011-10-22 06:18:15 -05:00
2011-08-20 08:59:47 -05:00
while (next().type !== 'list_item_end') {
body.push(tok());
}
2011-10-22 06:18:15 -05:00
2011-10-04 17:32:59 -05:00
return '<li>'
+ body.join(' ')
2011-08-20 10:46:35 -05:00
+ '</li>';
2011-10-22 06:18:15 -05:00
}
case 'html': {
2011-08-13 23:19:46 -05:00
return inline.lexer(token.text);
2011-10-22 06:18:15 -05:00
}
case 'paragraph': {
return '<p>'
+ inline.lexer(token.text)
+ '</p>';
}
2011-10-22 06:18:15 -05:00
case 'text': {
2011-10-22 06:09:28 -05:00
return '<p>'
+ text()
+ '</p>';
2011-10-22 06:18:15 -05:00
}
}
2011-10-04 17:32:59 -05:00
};
var text = function() {
var body = [ token.text ]
, top;
2011-10-04 17:32:59 -05:00
while ((top = tokens[tokens.length-1])
&& top.type === 'text') {
2011-10-04 17:32:59 -05:00
body.push(next().text);
2011-07-24 08:15:35 -05:00
}
2011-10-04 17:32:59 -05:00
return inline.lexer(body.join('\n'));
2011-07-24 08:15:35 -05:00
};
var parse = function(src) {
tokens = src.reverse();
var out = [];
while (next()) {
out.push(tok());
}
tokens = null;
token = null;
2011-12-30 19:30:32 -06:00
return out.join('\n');
2011-07-24 08:15:35 -05:00
};
/**
* Helpers
*/
var escape = function(html, dbl) {
2011-07-24 08:15:35 -05:00
return html
.replace(!dbl
? /&(?!#?\w+;)/g
: /&/g, '&amp;')
2011-07-24 08:15:35 -05:00
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
};
var mangle = function(str) {
2011-08-14 02:47:56 -05:00
var out = ''
, ch
2011-07-24 08:15:35 -05:00
, i = 0
2011-08-14 02:47:56 -05:00
, l = str.length;
2011-07-24 08:15:35 -05:00
for (; i < l; i++) {
2011-08-13 23:19:46 -05:00
ch = str.charCodeAt(i);
if (Math.random() > 0.5) {
2011-07-24 08:15:35 -05:00
ch = 'x' + ch.toString(16);
}
out += '&#' + ch + ';';
}
return out;
};
/**
* Expose
*/
2011-08-13 23:19:46 -05:00
var marked = function(str) {
return parse(block.lexer(str));
2011-07-24 08:15:35 -05:00
};
2011-08-13 23:19:46 -05:00
marked.parser = parse;
marked.lexer = block.lexer;
2011-11-26 22:12:02 -06:00
marked.parse = marked;
2011-08-13 23:19:46 -05:00
if (typeof module !== 'undefined') {
module.exports = marked;
} else {
this.marked = marked;
}
2011-07-24 08:15:35 -05:00
2011-08-13 23:19:46 -05:00
}).call(this);