Vitaly Puzrin
10 years ago
6 changed files with 75 additions and 59 deletions
@ -1,32 +1,40 @@ |
|||
// Proceess '\n'
|
|||
|
|||
module.exports = function escape(state) { |
|||
var pmax, pos = state.pos; |
|||
var pmax, max, pos = state.pos; |
|||
|
|||
if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; } |
|||
|
|||
pmax = state.pending.length - 1; |
|||
max = state.posMax; |
|||
|
|||
// ' \n' -> hardbreak
|
|||
if (pmax >= 1 && |
|||
state.pending.charCodeAt(pmax) === 0x20 && |
|||
state.pending.charCodeAt(pmax - 1) === 0x20) { |
|||
state.pending = state.pending.slice(0, -2); |
|||
state.pending = state.pending.replace(/ +$/, ''); |
|||
state.push({ |
|||
type: 'hardbreak' |
|||
}); |
|||
state.pos++; |
|||
|
|||
pos++; |
|||
// skip spaces
|
|||
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; } |
|||
|
|||
state.pos = pos; |
|||
return true; |
|||
} |
|||
|
|||
state.pending = state.pending.trim() + '\n'; |
|||
if (pmax > 0 && state.pending.charCodeAt(pmax) === 0x20) { |
|||
state.pending = state.pending.slice(0, -1); |
|||
} |
|||
|
|||
state.pending += '\n'; |
|||
|
|||
pos++; |
|||
|
|||
// skip spaces to simplify trim
|
|||
while (state.src.charCodeAt(pos) === 0x20) { pos++; } |
|||
// skip spaces
|
|||
while (pos < max && state.src.charCodeAt(pos) === 0x20) { pos++; } |
|||
|
|||
state.pos = pos; |
|||
|
|||
return true; |
|||
}; |
|||
|
Loading…
Reference in new issue