Skip to content

Commit 7770ece

Browse files
authored
Fix 修复丢失的换行符
1 parent 76bf0be commit 7770ece

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

tools/line-ending-converter/app.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,17 +240,12 @@ <h1>行尾符转换器</h1>
240240
const linesEl = document.getElementById('lines');
241241

242242
function normalize(value) {
243-
return value.replace(/
244-
/g, '
245-
').replace(/
246-
/g, '
247-
');
243+
return value.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
248244
}
249245

250246
function updateLines(value) {
251247
const normalized = normalize(value);
252-
linesEl.textContent = normalized ? normalized.split('
253-
').length : '0';
248+
linesEl.textContent = normalized ? normalized.split('\n').length : '0';
254249
}
255250

256251
function convertToLf() {
@@ -261,9 +256,7 @@ <h1>行尾符转换器</h1>
261256

262257
function convertToCrlf() {
263258
const normalized = normalize(input.value);
264-
output.value = normalized.replace(/
265-
/g, '
266-
');
259+
output.value = normalized.replace(/\n/g, '\r\n');
267260
updateLines(normalized);
268261
}
269262

0 commit comments

Comments
 (0)