diff --git a/lib/lexer_block.js b/lib/lexer_block.js index 0fbfc50..e5bada7 100644 --- a/lib/lexer_block.js +++ b/lib/lexer_block.js @@ -13,11 +13,11 @@ var rules = []; // `list` should be after `hr`, but before `heading` rules.push(require('./lexer_block/code')); rules.push(require('./lexer_block/fences')); +rules.push(require('./lexer_block/blockquote')); rules.push(require('./lexer_block/hr')); rules.push(require('./lexer_block/list')); rules.push(require('./lexer_block/heading')); rules.push(require('./lexer_block/lheading')); -rules.push(require('./lexer_block/blockquote')); rules.push(require('./lexer_block/table')); rules.push(require('./lexer_block/paragraph')); diff --git a/lib/lexer_block/code.js b/lib/lexer_block/code.js index 4480075..6d00e35 100644 --- a/lib/lexer_block/code.js +++ b/lib/lexer_block/code.js @@ -34,7 +34,7 @@ module.exports = function code(state, startLine, endLine, silent) { state.tokens.push({ type: 'code', - content: getLines(state, startLine, last, true).replace(/^ {4}/gm, '') + content: getLines(state, startLine, last, true).replace(/^ {1,4}/gm, '') }); state.line = nextLine; diff --git a/lib/lexer_block/fences.js b/lib/lexer_block/fences.js index 27bd99d..8b56bcb 100644 --- a/lib/lexer_block/fences.js +++ b/lib/lexer_block/fences.js @@ -66,10 +66,17 @@ module.exports = function fences(state, startLine, endLine, silent) { if (silent) { return true; } + // If fense has heading spases, those should be removed from inner block + len = state.tShift[startLine]; + state.tokens.push({ type: 'fence', params: params ? params.split(/\s+/g) : [], - content: getLines(state, startLine + 1, nextLine, true) + content: len === 0 ? + getLines(state, startLine + 1, nextLine, true) + : + getLines(state, startLine + 1, nextLine, true) + .replace(RegExp('^ {1,' + len + '}', 'mg'), '') }); state.line = nextLine + 1; diff --git a/lib/renderer.js b/lib/renderer.js index 8ac9dea..91cce50 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -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 = {}; -rules.blockquote_open = function (state /*, token*/) { +rules.blockquote_open = function (state /*, token, idx*/) { state.result += '
\n'; }; -rules.blockquote_close = function (state /*, token*/) { - state.result += '\n'; +rules.blockquote_close = function (state, token, idx) { + state.result += '' + getBreak(state, idx); }; @@ -54,21 +65,21 @@ rules.heading_close = function (state, token) { }; -rules.hr = function (state/*, token*/) { - state.result += state.options.xhtml ? '
'; }; -rules.paragraph_close = function (state /*, token*/) { - state.result += '
\n'; +rules.paragraph_close = function (state, token, idx) { + state.result += '' + getBreak(state, idx); }; -rules.table_open = function (state /*, token*/) { +rules.table_open = function (state /*, token, idx*/) { state.result += '