Skip to content

Commit 61c2f02

Browse files
committed
fix formatting
1 parent e85bad6 commit 61c2f02

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

docs/src/lib/remark/stripEmojis.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function visit(node) {
2828
}
2929

3030
if (node.type === 'code' && typeof node.value === 'string') {
31-
node.value = stripEmojis(node.value);
31+
node.value = stripEmojis(node.value, { preserveWhitespace: true });
3232
}
3333

3434
if (node.type === 'html' && typeof node.value === 'string') {
@@ -111,8 +111,9 @@ const replacements = new Map([
111111

112112
/**
113113
* @param {string} input
114+
* @param {{ preserveWhitespace?: boolean }} [options]
114115
*/
115-
function stripEmojis(input) {
116+
function stripEmojis(input, options) {
116117
let output = input;
117118

118119
for (const [from, to] of replacements.entries()) {
@@ -126,7 +127,10 @@ function stripEmojis(input) {
126127
// Node 20+ supports Unicode property escapes.
127128
output = output.replace(/\p{Extended_Pictographic}+/gu, '');
128129

129-
// Collapse double spaces introduced by removals.
130-
output = output.replace(/[ \t]{2,}/g, ' ');
130+
// Collapse double spaces introduced by removals, but not inside code blocks
131+
// where whitespace (indentation) is significant.
132+
if (!options?.preserveWhitespace) {
133+
output = output.replace(/[ \t]{2,}/g, ' ');
134+
}
131135
return output;
132136
}

0 commit comments

Comments
 (0)