Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

difference between \r\n, \r, and \n #137

Open
gracekrcx opened this issue Dec 15, 2022 · 5 comments
Open

difference between \r\n, \r, and \n #137

gracekrcx opened this issue Dec 15, 2022 · 5 comments

Comments

@gracekrcx
Copy link
Owner

gracekrcx commented Dec 15, 2022

wiki 有列表顯示 Software applications and operating system representation of a newline with one or two control characters

'white-space': 'pre-wrap' 是非常適合的換行方式
NewLines.jsx
其實真的不懂 white-space

white-space

The white-space CSS property sets how white space inside an element is handled.

Whitespace characters 有哪些

Infra 動態標準將五個字元定義為「ASCII 空白字元」:

  1. U+0009 TAB、
  2. U+000A LF、
  3. U+000C FF、
  4. U+000D CR
  5. U+0020 SPACE。

Example

<span>
 Example #1: <br /> newline
</span>
<span style={{ whiteSpace: 'pre-wrap' }}>
 {"Example #2: \r new line or \u000A new line"}
</span>
{/* do not forget add style { white-space: pre-wrap } */}
<Example3 text={"Example #2: \r new line or \u000A new line"} />

New line in react

文章

React JSX 字串處理
What is the difference between \r\n, \r, and \n? [duplicate]
Unix / Linux / OS X / Windows 系统下的回车换行符都分别是什么?
https://hackmd.io/@mike-liu/By32a6lyi

@gracekrcx
Copy link
Owner Author

gracekrcx commented Dec 19, 2022

img

img

HTML Letter Symbols, Letter Entities and ASCII Letter Character Code Reference

HTML ENTITY : &middot;link

怎麼 &middot; 有反應但 &#10; 沒反應???
所以查了 u000a not work in jsx element
(其實不是沒反應,只是 browser 處理的方式,需要加上 css 才會有反應)

function createMarkup() {
  return {__html: 'First &middot; Second'};
}

function MyComponent() {
  return <div dangerouslySetInnerHTML={createMarkup()} />;
}

@gracekrcx
Copy link
Owner Author

gracekrcx commented Dec 19, 2022

關鍵字:u000a not work in jsx element 找到了底下的文章

newline characters are normally interpreted by HTML as spaces
Newline character doesn't render in browser
Why does the browser renders a newline as space?
newlines character ignored by jsx table

@gracekrcx
Copy link
Owner Author

gracekrcx commented Dec 19, 2022

跳脫符號
除了常規的、可印出來的字元,特殊字元也可以被跳脫符號來表示編碼。

解釋:
跳脫符號 \
表示編碼 \n 所以 \n 內涵編碼的成分,只是看起來是反斜線n

字串中的跳脫字元(Escaping characters)

@gracekrcx
Copy link
Owner Author

  • dangerouslySetInnerHTML 使用 HTML ENTITY
  • 變數字串 使用 UNICODE
export default function App() {
  function createMarkup() {
    return {__html: 'First &#10; Second'};
  }
  
  const text = 'Tommy Tommy \u000a Carl Carl'

  return (
    <div className="App">
      <div style={{
      'white-space': 'pre-wrap'
      }} dangerouslySetInnerHTML={createMarkup()} />
      <h2 style={{
      'white-space': 'pre-wrap'
      }}>{text}</h2>
    </div>
  );
}

@gracekrcx
Copy link
Owner Author

gracekrcx commented Feb 17, 2024

使用的「語法」跟你的「平台」有關
ASCII 表格
從ASCII到Unicode
CRLF和LF的差異
CRLF
回车(CR)与换行(LF), '\r'和'\n'的区别

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant