
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
react-truncate-html
Advanced tools
We all know how this goes: one day you’re just minding your own business, and then suddenly hear your content manager say ‘but we also want to use html in the summaries’, you yell out ‘why?!’ and shake your head in disbelief, sadly; the choice isn’t up to you.
Good news, luckily for you there’s react-truncate-html
, which unlike react-truncate
also supports html (who would’ve guessed, right?!)
react-truncate-html is based on ellipsis.js, so it features:
react-truncate-html
As mentioned above, only use react-truncate-html
when you want to truncate HTML
Use react-truncate
for everything else.
Although you pass your html through dangerouslySetInnerHTML
, react-truncate-html
will sanitize input passed to it.
Do keep in mind that RTH explicitly santizes input, other elements besides RTH will not filter input when using dangerouslySetInnerHTML
and in that case, you are personally responsible for sanitizing input
npm i react-truncate-html --save
yarn add react-truncate-html
whatever-new-package-manager-we-will-have-next-month install react-truncate-html
etc...
Simple example (truncate after 3 lines):
import Truncate from 'react-truncate-html';
<Truncate
lines={3}
dangerouslySetInnerHTML={{
__html: "Hi, <strong>here’s some</strong> <i>HTML</i>"
}}
/>
Complex example (don't listen for browser resizing events, don’t break words, use 4 lines on portrait mode):
<Truncate
lines={3}
portrait={4}
breakWord={false}
responsive={false}
dangerouslySetInnerHTML={{
__html: "Hi, <strong>here’s some</strong> <i>HTML</i>"
}}
/>
Name | Type | Default | Desc |
---|---|---|---|
debounce | Number | 100 | Use a timeout before recalculating when resizing the window. |
responsive | Bool | true | If you want the ellipsis to move with the window resizing |
lines | Number | 2 | Number of lines you wish to have before the ellipsis will appear |
portrait | Number | null | Additionally, you can set a different amount of lines when using portrait mode |
breakWord | Bool | true | If true the words can be truncated by the ellipsis, eg: "Hello Wo…", if false they won't, eg "Hello …" |
Additional props will be transferred over to react-truncate-html’s internal tag, so, for example <Truncate style={{color: ‘yellow’}}/>
will work.
FAQs
Truncate multiline HTML with React
We found that react-truncate-html demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.