Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
clean up code
  • Loading branch information
UziTech committed Jan 4, 2022
commit bd3e9806193e134a032ea50f3238a03e80676959
11 changes: 5 additions & 6 deletions src/Lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,11 @@ export class Lexer {
// newline
if (token = this.tokenizer.space(src)) {
src = src.substring(token.raw.length);
if (token.raw.length === 1 && tokens[tokens.length - 1]) {
// if there's a single \n as a spacer, it's terminating the last line, so move it there so that we don't get unecessary paragraph tags
tokens[tokens.length - 1].raw = `${tokens[tokens.length - 1].raw}\n`;
continue;
}
if (token.type) {
if (token.raw.length === 1 && tokens.length > 0) {
// if there's a single \n as a spacer, it's terminating the last line,
// so move it there so that we don't get unecessary paragraph tags
tokens[tokens.length - 1].raw += '\n';
} else {
tokens.push(token);
}
continue;
Expand Down
13 changes: 5 additions & 8 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,11 @@ export class Tokenizer {

space(src) {
const cap = this.rules.block.newline.exec(src);
if (cap) {
if (cap[0].length) {
return {
type: 'space',
raw: cap[0]
};
}
return { raw: '\n' };
if (cap && cap[0].length > 0) {
return {
type: 'space',
raw: cap[0]
};
}
}

Expand Down