|
@ -18,14 +18,25 @@ function unescapeMd(str) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// check if we need to hide '\n' before next token
|
|
|
|
|
|
function getBreak(state, idx) { |
|
|
|
|
|
if (++idx < state.tokens.length && |
|
|
|
|
|
state.tokens[idx].type === 'list_item_close') { |
|
|
|
|
|
return ''; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return '\n'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rules = {}; |
|
|
var rules = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.blockquote_open = function (state /*, token*/) { |
|
|
rules.blockquote_open = function (state /*, token, idx*/) { |
|
|
state.result += '<blockquote>\n'; |
|
|
state.result += '<blockquote>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.blockquote_close = function (state /*, token*/) { |
|
|
rules.blockquote_close = function (state, token, idx) { |
|
|
state.result += '</blockquote>\n'; |
|
|
state.result += '</blockquote>' + getBreak(state, idx); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -54,21 +65,21 @@ rules.heading_close = function (state, token) { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.hr = function (state/*, token*/) { |
|
|
rules.hr = function (state, token, idx) { |
|
|
state.result += state.options.xhtml ? '<hr />\n' : '<hr>\n'; |
|
|
state.result += (state.options.xhtml ? '<hr />' : '<hr>') + getBreak(state, idx); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.bullet_list_open = function (state /*, token*/) { |
|
|
rules.bullet_list_open = function (state /*, token, idx*/) { |
|
|
state.result += '<ul>\n'; |
|
|
state.result += '<ul>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.bullet_list_close = function (state /*, token*/) { |
|
|
rules.bullet_list_close = function (state /*, token, idx*/) { |
|
|
state.result += '</ul>\n'; |
|
|
state.result += '</ul>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.list_item_open = function (state /*, token*/) { |
|
|
rules.list_item_open = function (state /*, token, idx*/) { |
|
|
state.result += '<li>'; |
|
|
state.result += '<li>'; |
|
|
}; |
|
|
}; |
|
|
rules.list_item_close = function (state /*, token*/) { |
|
|
rules.list_item_close = function (state /*, token, idx*/) { |
|
|
state.result += '</li>\n'; |
|
|
state.result += '</li>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.ordered_list_open = function (state, token) { |
|
|
rules.ordered_list_open = function (state, token) { |
|
@ -76,29 +87,29 @@ rules.ordered_list_open = function (state, token) { |
|
|
+ (token.order > 1 ? ' start="' + token.order + '"' : '') |
|
|
+ (token.order > 1 ? ' start="' + token.order + '"' : '') |
|
|
+ '>\n'; |
|
|
+ '>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.ordered_list_close = function (state /*, token*/) { |
|
|
rules.ordered_list_close = function (state /*, token, idx*/) { |
|
|
state.result += '</ol>\n'; |
|
|
state.result += '</ol>\n'; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.paragraph_open = function (state /*, token*/) { |
|
|
rules.paragraph_open = function (state /*, token, idx*/) { |
|
|
state.result += '<p>'; |
|
|
state.result += '<p>'; |
|
|
}; |
|
|
}; |
|
|
rules.paragraph_close = function (state /*, token*/) { |
|
|
rules.paragraph_close = function (state, token, idx) { |
|
|
state.result += '</p>\n'; |
|
|
state.result += '</p>' + getBreak(state, idx); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules.table_open = function (state /*, token*/) { |
|
|
rules.table_open = function (state /*, token, idx*/) { |
|
|
state.result += '<table>\n'; |
|
|
state.result += '<table>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.table_close = function (state /*, token*/) { |
|
|
rules.table_close = function (state /*, token, idx*/) { |
|
|
state.result += '</table>\n'; |
|
|
state.result += '</table>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.tr_open = function (state /*, token*/) { |
|
|
rules.tr_open = function (state /*, token, idx*/) { |
|
|
state.result += '<tr>\n'; |
|
|
state.result += '<tr>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.tr_close = function (state /*, token*/) { |
|
|
rules.tr_close = function (state /*, token, idx*/) { |
|
|
state.result += '</tr>\n'; |
|
|
state.result += '</tr>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.th_open = function (state, token) { |
|
|
rules.th_open = function (state, token) { |
|
@ -106,7 +117,7 @@ rules.th_open = function (state, token) { |
|
|
+ (token.align ? ' align="' + token.align + '"' : '') |
|
|
+ (token.align ? ' align="' + token.align + '"' : '') |
|
|
+ '>'; |
|
|
+ '>'; |
|
|
}; |
|
|
}; |
|
|
rules.th_close = function (state /*, token*/) { |
|
|
rules.th_close = function (state /*, token, idx*/) { |
|
|
state.result += '</th>\n'; |
|
|
state.result += '</th>\n'; |
|
|
}; |
|
|
}; |
|
|
rules.td_open = function (state, token) { |
|
|
rules.td_open = function (state, token) { |
|
@ -114,7 +125,7 @@ rules.td_open = function (state, token) { |
|
|
+ (token.align ? ' align="' + token.align + '"' : '') |
|
|
+ (token.align ? ' align="' + token.align + '"' : '') |
|
|
+ '>'; |
|
|
+ '>'; |
|
|
}; |
|
|
}; |
|
|
rules.td_close = function (state /*, token*/) { |
|
|
rules.td_close = function (state /*, token, idx*/) { |
|
|
state.result += '</td>\n'; |
|
|
state.result += '</td>\n'; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -143,7 +154,7 @@ Renderer.prototype.render = function (state) { |
|
|
throw new Error('Renderer error: unknown token ' + tokens[i].type); |
|
|
throw new Error('Renderer error: unknown token ' + tokens[i].type); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
rule(state, tokens[i]); |
|
|
rule(state, tokens[i], i); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return state.result; |
|
|
return state.result; |
|
|