Created
March 8, 2017 13:38
-
-
Save sykwer/17fe0e5ae871db0a63557bc30aa0e4dc to your computer and use it in GitHub Desktop.
Reactjs + lodashでの実装で、改行コードを含むテキストをフォーマットする。先頭末尾の改行はtrimして3つ以上続く改行は2つに縮める。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = "some awesome sentence"; | |
const formatted_str = _.map( | |
_.replace(str, /(\r\n){3,}|\r{3,}|\n{3,}/g, '\n\n').trim().split('\n'), | |
(line, i) => <span>{line}<br /></span> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment