-
No idea of these: // If this is not just spaces or eols (tabs don’t count), and either the
// 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)))
) {
value = ' ' + value + ' '
} https://github.com/syntax-tree/mdast-util-to-markdown/blob/main/lib/handle/inline-code.js#L28-L34 A inline-code with value |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
This behavior is needed to roundtrip the value (see the comment above it): https://spec.commonmark.org/0.30/#code-span. As you can see from your example, they are equivalent: the spaces around it are dropped. |
Beta Was this translation helpful? Give feedback.
This behavior is needed to roundtrip the value (see the comment above it): https://spec.commonmark.org/0.30/#code-span.
The padding has to be done on both sides: it doesn’t work if it’s only on one side, then it changes the code.
As you can see from your example, they are equivalent: the spaces around it are dropped.
See some example: https://spec.commonmark.org/dingus/?text=1.%20%60%20%60%20one%20space%20(persists)%0A1.%20%60%20%20%20%20%60%20four%20spaces%20(persists)%0A1.%20%60a%20%60%20final%20space%20(persists)%0A1.%20%60%20a%60%20initial%20space%20(persists)%0A1.%20%60%20a%20%60%20initial%20and%20final%20space%20(dropped)%0A1.%20%60%60%20%60a%60%20%60%60%20spaces%20around%20ticks%20…