diff --git a/lib/handle/inline-code.js b/lib/handle/inline-code.js index b470685..e91631e 100644 --- a/lib/handle/inline-code.js +++ b/lib/handle/inline-code.js @@ -27,8 +27,7 @@ export function inlineCode(node, _, context) { // first or last character are a space, eol, or tick, then pad with spaces. if ( /[^ \r\n]/.test(value) && - (/[ \r\n`]/.test(value.charAt(0)) || - /[ \r\n`]/.test(value.charAt(value.length - 1))) + ((/^[ \r\n]/.test(value) && /[ \r\n]$/.test(value)) || /^`|`$/.test(value)) ) { value = ' ' + value + ' ' } diff --git a/package.json b/package.json index 29923a9..3e4f322 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "@types/unist": "^2.0.0", + "@types/mdast": "3.0.3", + "@types/unist": "2.0.4", "longest-streak": "^3.0.0", "mdast-util-to-string": "^3.0.0", "parse-entities": "^3.0.0", diff --git a/test/index.js b/test/index.js index da50ae3..18ececd 100644 --- a/test/index.js +++ b/test/index.js @@ -1436,16 +1436,22 @@ test('Code text', (t) => { 'should pad w/ a space if the value ends w/ a grave accent' ) + t.equal( + to({type: 'inlineCode', value: ' a '}), + '` a `\n', + 'should pad w/ a space if the value starts and ends w/ a space' + ) + t.equal( to({type: 'inlineCode', value: ' a'}), - '` a `\n', - 'should pad w/ a space if the value starts w/ a space' + '` a`\n', + 'should not pad w/ spaces if the value ends w/ a non-space' ) t.equal( to({type: 'inlineCode', value: 'a '}), - '` a `\n', - 'should pad w/ a space if the value ends w/ a space' + '`a `\n', + 'should not pad w/ spaces if the value starts w/ a non-space' ) t.equal( @@ -1462,7 +1468,7 @@ test('Code text', (t) => { t.equal( to({type: 'inlineCode', value: 'a\n1. '}), - '` a 1. `\n', + '`a 1. `\n', 'should prevent breaking out of code (\\d\\.)' )