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