-
-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inline code and vertical bars in tables
Fix inline code and code in tables This removes support for empty inline code, and only trims inline code content by one character on both sides, if both the initial and final character are a space or a line feed. Previously, inline code got preference over the table cell itself. This was added due to GH-73 in GH-83 four years ago. That behaviour does not match current GFM and lead to unexpected results in GH-295, GH-320, and GH-396. Related to GH-73. Related to GH-83. Closes GH-295. Closes GH-320. Closes GH-396. Closes GH-420. Reviewed-by: Merlijn Vos <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,571 additions
and
1,924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,109 @@ | ||
'use strict' | ||
|
||
var locate = require('../locate/code-inline') | ||
var whitespace = require('../util/is-markdown-whitespace-character') | ||
|
||
module.exports = inlineCode | ||
inlineCode.locator = locate | ||
|
||
var graveAccent = '`' | ||
var lineFeed = 10 // '\n' | ||
var space = 32 // ' ' | ||
var graveAccent = 96 // '`' | ||
|
||
function inlineCode(eat, value, silent) { | ||
var length = value.length | ||
var index = 0 | ||
var queue = '' | ||
var tickQueue = '' | ||
var contentQueue | ||
var subqueue | ||
var count | ||
var openingCount | ||
var subvalue | ||
var character | ||
var found | ||
var openingFenceEnd | ||
var closingFenceStart | ||
var closingFenceEnd | ||
var code | ||
var next | ||
var found | ||
|
||
while (index < length) { | ||
if (value.charAt(index) !== graveAccent) { | ||
if (value.charCodeAt(index) !== graveAccent) { | ||
break | ||
} | ||
|
||
queue += graveAccent | ||
index++ | ||
} | ||
|
||
if (!queue) { | ||
if (index === 0 || index === length) { | ||
return | ||
} | ||
|
||
subvalue = queue | ||
openingCount = index | ||
queue = '' | ||
next = value.charAt(index) | ||
count = 0 | ||
openingFenceEnd = index | ||
next = value.charCodeAt(index) | ||
|
||
while (index < length) { | ||
character = next | ||
next = value.charAt(index + 1) | ||
|
||
if (character === graveAccent) { | ||
count++ | ||
tickQueue += character | ||
} else { | ||
count = 0 | ||
queue += character | ||
} | ||
code = next | ||
next = value.charCodeAt(index + 1) | ||
|
||
if (code === graveAccent) { | ||
if (closingFenceStart === undefined) { | ||
closingFenceStart = index | ||
} | ||
|
||
closingFenceEnd = index + 1 | ||
|
||
if (count && next !== graveAccent) { | ||
if (count === openingCount) { | ||
subvalue += queue + tickQueue | ||
if ( | ||
next !== graveAccent && | ||
closingFenceEnd - closingFenceStart === openingFenceEnd | ||
) { | ||
found = true | ||
break | ||
} | ||
|
||
queue += tickQueue | ||
tickQueue = '' | ||
} else if (closingFenceStart !== undefined) { | ||
closingFenceStart = undefined | ||
closingFenceEnd = undefined | ||
} | ||
|
||
index++ | ||
} | ||
|
||
if (!found) { | ||
if (openingCount % 2 !== 0) { | ||
return | ||
} | ||
|
||
queue = '' | ||
return | ||
} | ||
|
||
/* istanbul ignore if - never used (yet) */ | ||
if (silent) { | ||
return true | ||
} | ||
|
||
contentQueue = '' | ||
subqueue = '' | ||
length = queue.length | ||
index = -1 | ||
|
||
while (++index < length) { | ||
character = queue.charAt(index) | ||
// Remove the initial and final space (or line feed), iff they exist and there | ||
// are non-space characters in the content. | ||
index = openingFenceEnd | ||
length = closingFenceStart | ||
code = value.charCodeAt(index) | ||
next = value.charCodeAt(length - 1) | ||
found = false | ||
|
||
if ( | ||
length - index > 2 && | ||
(code === space || code === lineFeed) && | ||
(next === space || next === lineFeed) | ||
) { | ||
index++ | ||
length-- | ||
|
||
if (whitespace(character)) { | ||
subqueue += character | ||
continue | ||
} | ||
while (index < length) { | ||
code = value.charCodeAt(index) | ||
|
||
if (subqueue) { | ||
if (contentQueue) { | ||
contentQueue += subqueue | ||
if (code !== space && code !== lineFeed) { | ||
found = true | ||
break | ||
} | ||
|
||
subqueue = '' | ||
index++ | ||
} | ||
|
||
contentQueue += character | ||
if (found === true) { | ||
openingFenceEnd++ | ||
closingFenceStart-- | ||
} | ||
} | ||
|
||
return eat(subvalue)({type: 'inlineCode', value: contentQueue}) | ||
return eat(value.slice(0, closingFenceEnd))({ | ||
type: 'inlineCode', | ||
value: value.slice(openingFenceEnd, closingFenceStart) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Grave accent in cell: | ||
|
||
| A | B | | ||
|--------------|---| | ||
| <kbd>`</kbd> | C | | ||
|
||
Escaped grave accent in inline code in cell (is not an escape): | ||
|
||
| A | | ||
|-----| | ||
| `\` | | ||
|
||
“Empty” inline code: | ||
|
||
| 1 | 2 | 3 | | ||
|---|------|----| | ||
| a | `` | | | ||
| b | `` | `` | | ||
| c | ` | ` | | ||
| d | `|` | | ||
| e | `\|` | | | ||
| f | \| | | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.