简体   繁体   中英

Strip formatted text

I have a nested html that i wanna limit its content.

Is there any way??

there is an Example:

 <div id="description-list-31553" style="display: flow-root;"> <p dir="ltr" style=""><span id="docs"> <span ">Many people regularly put</span> <a href="https://www.realbuzz.com/challenges/run-a-marathon/">running a marathon</a> <span style="color: rgb(51, 51, 51);">&nbsp;in their list of things to do before they die, so why not make this the year that you actually do it? </span></span></p> <p dir="ltr"><span><span ></span><span style="color: rgb(173, 0, 87);">Completing a marathon is a great personal achievement that requires months of dedication to training, and the exhilaration you'll feel when crossing the line will certainly be something special</span><span style="color: rgb(51, 51, 51);">. </span></span></p> <p dir="ltr"><span><span style="color: rgb(51, 51, 51);">If you're already a marathon runner, then why not consider taking on some of the more extreme running events such as the Great Wall Marathon in China, the Antarctica Marathon, or even the Marathon des Sables run in the Sahara Desert?</span></span><span style="color: rgb(51, 51, 51);">&nbsp;&nbsp;</span></p><h2 dir="ltr" ></h2> </div>

i need just part of its content with keeping its formatting.

 <div id="description-list-31553" style="display: flow-root;"> <p dir="ltr" style=""><span id="docs"> <span ">Many people regularly put</span> <a href="https://www.realbuzz.com/challenges/run-a-marathon/">running a marathon</a> <span style="color: rgb(51, 51, 51);">&nbsp;in their list of things to do before they die, so why not make this the year that you actually do it? </span></span></p> <p dir="ltr"><span><span ></span><span style="color: rgb(173, 0, 87);">Completing a marathon ...</span><span style="color: rgb(51, 51, 51);">. </span></span></p> <p dir="ltr"><span><span style="color: rgb(51, 51, 51);"></span></span><span style="color: rgb(51, 51, 51);">&nbsp;&nbsp;</span></p><h2 dir="ltr" ></h2> </div>

If you are using jquery you can try this plugin: http://dotdotdot.frebsite.nl/

EDIT

Maybe this post can help you, you have to replace text with a substring of n given characters and add the three dots at the end

Truncate text to fit in 3 lines and show three dots in end In Html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM