-
-
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 non-ASCII whitespace in inline code
Closes GH-321. Closes GH-424. Reviewed-by: Marouane Fazouane <fazouanem3@gmail.com> Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
- Loading branch information
Showing
4 changed files
with
175 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
packages/remark-parse/lib/util/is-markdown-whitespace-character.js
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,27 @@ | ||
'use strict' | ||
|
||
module.exports = whitespace | ||
|
||
var tab = 9 // '\t' | ||
var lineFeed = 10 // '\n' | ||
var lineTabulation = 11 // '\v' | ||
var formFeed = 12 // '\f' | ||
var carriageReturn = 13 // '\r' | ||
var space = 32 // ' ' | ||
|
||
function whitespace(char) { | ||
/* istanbul ignore next - `number` handling for future */ | ||
var code = typeof char === 'number' ? char : char.charCodeAt(0) | ||
|
||
switch (code) { | ||
case tab: | ||
case lineFeed: | ||
case lineTabulation: | ||
case formFeed: | ||
case carriageReturn: | ||
case space: | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
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,3 @@ | ||
Markdown strips regular whitespaces: ` hello ` | ||
Including tabs: ` hello ` | ||
However it preserves non-breaking whitespaces: ` hello ` |
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,144 @@ | ||
{ | ||
"type": "root", | ||
"children": [ | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "Markdown strips regular whitespaces: ", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 38, | ||
"offset": 37 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "inlineCode", | ||
"value": "hello", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 38, | ||
"offset": 37 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 51, | ||
"offset": 50 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"value": "\nIncluding tabs: ", | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 51, | ||
"offset": 50 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 17, | ||
"offset": 67 | ||
}, | ||
"indent": [ | ||
1 | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "inlineCode", | ||
"value": "hello", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 17, | ||
"offset": 67 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 26, | ||
"offset": 76 | ||
}, | ||
"indent": [] | ||
} | ||
}, | ||
{ | ||
"type": "text", | ||
"value": "\nHowever it preserves non-breaking whitespaces: ", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 26, | ||
"offset": 76 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 48, | ||
"offset": 124 | ||
}, | ||
"indent": [ | ||
1 | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "inlineCode", | ||
"value": " hello ", | ||
"position": { | ||
"start": { | ||
"line": 3, | ||
"column": 48, | ||
"offset": 124 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 61, | ||
"offset": 137 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 61, | ||
"offset": 137 | ||
}, | ||
"indent": [ | ||
1, | ||
1 | ||
] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 4, | ||
"column": 1, | ||
"offset": 138 | ||
} | ||
} | ||
} |