-
Notifications
You must be signed in to change notification settings - Fork 3.5k
fix: Join adjacent inlineText tokens #1926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
65b7a35
0ade5ac
72e7cc8
87f4704
d7bb213
1c5cf59
ead6e66
3b1130e
296e327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,14 +136,15 @@ module.exports = class Lexer { | |
| } | ||
|
|
||
| // code | ||
| if (token = this.tokenizer.code(src, tokens)) { | ||
| if (token = this.tokenizer.code(src)) { | ||
| src = src.substring(token.raw.length); | ||
| if (token.type) { | ||
| tokens.push(token); | ||
| } else { | ||
| lastToken = tokens[tokens.length - 1]; | ||
| lastToken = tokens[tokens.length - 1]; | ||
| // An indented code block cannot interrupt a paragraph. | ||
| if (lastToken && lastToken.type === 'paragraph') { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should check for a paragraph before we call the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth trying. It's a tradeoff of always checking Edit: If
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point. I suppose we would still need to call code tokenizer to see if we should skip the other tokens. Maybe it is still better to check code tokenizer first. |
||
| lastToken.raw += '\n' + token.raw; | ||
| lastToken.text += '\n' + token.text; | ||
| } else { | ||
| tokens.push(token); | ||
| } | ||
| continue; | ||
| } | ||
|
|
@@ -236,14 +237,14 @@ module.exports = class Lexer { | |
| } | ||
|
|
||
| // text | ||
| if (token = this.tokenizer.text(src, tokens)) { | ||
| if (token = this.tokenizer.text(src)) { | ||
| src = src.substring(token.raw.length); | ||
| if (token.type) { | ||
| tokens.push(token); | ||
| } else { | ||
| lastToken = tokens[tokens.length - 1]; | ||
| lastToken = tokens[tokens.length - 1]; | ||
| if (lastToken && lastToken.type === 'text') { | ||
| lastToken.raw += '\n' + token.raw; | ||
| lastToken.text += '\n' + token.text; | ||
| } else { | ||
| tokens.push(token); | ||
| } | ||
| continue; | ||
| } | ||
|
|
@@ -331,7 +332,7 @@ module.exports = class Lexer { | |
| * Lexing/Compiling | ||
| */ | ||
| inlineTokens(src, tokens = [], inLink = false, inRawBlock = false) { | ||
| let token; | ||
| let token, lastToken; | ||
|
|
||
| // String with links masked to avoid interference with em and strong | ||
| let maskedSrc = src; | ||
|
|
@@ -371,7 +372,13 @@ module.exports = class Lexer { | |
| src = src.substring(token.raw.length); | ||
| inLink = token.inLink; | ||
| inRawBlock = token.inRawBlock; | ||
| tokens.push(token); | ||
| const lastToken = tokens[tokens.length - 1]; | ||
| if (lastToken && token.type === 'text' && lastToken.type === 'text') { | ||
| lastToken.raw += token.raw; | ||
| lastToken.text += token.text; | ||
| } else { | ||
| tokens.push(token); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -388,10 +395,16 @@ module.exports = class Lexer { | |
| // reflink, nolink | ||
| if (token = this.tokenizer.reflink(src, this.tokens.links)) { | ||
| src = src.substring(token.raw.length); | ||
| const lastToken = tokens[tokens.length - 1]; | ||
| if (token.type === 'link') { | ||
| token.tokens = this.inlineTokens(token.text, [], true, inRawBlock); | ||
| tokens.push(token); | ||
| } else if (lastToken && token.type === 'text' && lastToken.type === 'text') { | ||
| lastToken.raw += token.raw; | ||
| lastToken.text += token.text; | ||
| } else { | ||
| tokens.push(token); | ||
| } | ||
| tokens.push(token); | ||
| continue; | ||
| } | ||
|
|
||
|
|
@@ -452,7 +465,13 @@ module.exports = class Lexer { | |
| src = src.substring(token.raw.length); | ||
| prevChar = token.raw.slice(-1); | ||
| keepPrevChar = true; | ||
| tokens.push(token); | ||
| lastToken = tokens[tokens.length - 1]; | ||
| if (lastToken && lastToken.type === 'text') { | ||
| lastToken.raw += token.raw; | ||
| lastToken.text += token.text; | ||
| } else { | ||
| tokens.push(token); | ||
| } | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.