Skip to content

Commit

Permalink
refactor. make function syntax consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Apr 26, 2012
1 parent d3a7ec1 commit d44617a
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions lib/marked.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var block = {
newline: /^\n+/,
code: /^( {4}[^\n]+\n*)+/,
fences: noop,
hr: /^( *[\-*_]){3,} *(?:\n+|$)/,
hr: /^( *[-*_]){3,} *(?:\n+|$)/,
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
lheading: /^([^\n]+)\n *(=|-){3,} *\n*/,
blockquote: /^( *>[^\n]+(\n[^\n]+)*\n*)+/,
Expand Down Expand Up @@ -479,7 +479,7 @@ inline.lexer = function(src) {
return out;
};

var outputLink = function(cap, link) {
function outputLink(cap, link) {
if (cap[0][0] !== '!') {
return '<a href="'
+ escape(link.href)
Expand All @@ -505,7 +505,7 @@ var outputLink = function(cap, link) {
: '')
+ '>';
}
};
}

/**
* Parsing
Expand All @@ -514,11 +514,11 @@ var outputLink = function(cap, link) {
var tokens
, token;

var next = function() {
function next() {
return token = tokens.pop();
};
}

var tok = function() {
function tok() {
switch (token.type) {
case 'space': {
return '';
Expand All @@ -543,9 +543,11 @@ var tok = function() {
token.text = token.code;
}
}

if (!token.escaped) {
token.text = escape(token.text, true);
}

return '<pre><code'
+ (token.lang
? ' class="lang-'
Expand Down Expand Up @@ -626,9 +628,9 @@ var tok = function() {
+ '</p>\n';
}
}
};
}

var parseText = function() {
function parseText() {
var body = token.text
, top;

Expand All @@ -638,9 +640,9 @@ var parseText = function() {
}

return inline.lexer(body);
};
}

var parse = function(src) {
function parse(src) {
tokens = src.reverse();

var out = '';
Expand All @@ -652,22 +654,22 @@ var parse = function(src) {
token = null;

return out;
};
}

/**
* Helpers
*/

var escape = function(html, encode) {
function escape(html, encode) {
return html
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
};
}

var mangle = function(text) {
function mangle(text) {
var out = ''
, l = text.length
, i = 0
Expand All @@ -682,7 +684,7 @@ var mangle = function(text) {
}

return out;
};
}

function tag() {
var tag = '(?!(?:'
Expand Down Expand Up @@ -710,10 +712,10 @@ noop.exec = noop;
* Marked
*/

var marked = function(src, opt) {
function marked(src, opt) {
setOptions(opt);
return parse(block.lexer(src));
};
}

/**
* Options
Expand All @@ -722,7 +724,7 @@ var marked = function(src, opt) {
var options
, defaults;

var setOptions = function(opt) {
function setOptions(opt) {
if (!opt) opt = defaults;
if (options === opt) return;
options = opt;
Expand All @@ -746,7 +748,7 @@ var setOptions = function(opt) {
inline.em = inline.normal.em;
inline.strong = inline.normal.strong;
}
};
}

marked.options =
marked.setOptions = function(opt) {
Expand All @@ -755,7 +757,7 @@ marked.setOptions = function(opt) {
return marked;
};

marked.options({
marked.setOptions({
gfm: true,
pedantic: false,
sanitize: false,
Expand Down

0 comments on commit d44617a

Please sign in to comment.