File tree Expand file tree Collapse file tree
tools/line-ending-converter Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments