eentzel / htmltruncate.py Goto Github PK
View Code? Open in Web Editor NEWPython module for truncating text that contains markup
Python module for truncating text that contains markup
I was wondering if you could package this project onto PyPI so we could just do pip install htmltruncate
. I think it would be nicer than having to copy paste the files manually or set up a git submodule.
You wrote great module thanks you!
But it seems little bug.
>>> htmltruncate.truncate('фывафдывфдлсв<br><strong>фыварфылвр </strong><br>ываыва<br><br><em>ываываыавфв</em><br><br><br><strong>вфвфывфыв<br><br><img class="img-responsive" src="/files/076e3caed758a1c18c91a0e9cae3368f.jpg"><br><br>fdfgdfg<br>sdfsdfsf<em>sdfsfdsfs
df</em></strong><br><ol><li><strong><em>aasd</em></strong></li></ol>', 50)
'фывафдывфдлсв<br><strong>фыварфылвр\xa0</strong><br>ываыва<br><br><em>ываываыавфв</em><br><br><br><strong>вфвфывфыв</strong></br></br></br></br></br></br></br>'
>>>
>>> htmltruncate.truncate('фывафдывфдлсв<br><strong>фыварфылвр </strong><br>ываыва<br><br><em>ываываыавфв</em><br><br><br><strong>вфвфывфыв<br><br><img class="img-responsive" src="/files/076e3caed758a1c18c91a0e9cae3368f.jpg"><br><br>fdfgdfg<br>sdfsdfsf<em>sdfsfdsfs
df</em></strong><br><ol><li><strong><em>aasd</em></strong></li></ol>', 200)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\GitLab\personal\exp_14\app\htmltruncate.py", line 143, in truncate
raise UnbalancedError( tok.as_string() )
htmltruncate.UnbalancedError: </strong>
>>>
If I replace <img>
tag with same but closing <img />
then the problem disappears.
I really just wanted to say thanks. Your code save me hours. But I would also suggest that you add some attributation information at the beginning of htmltruncate.py (the source file) as I just copied the file into
my project and I'd like to give credit where credit is due.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.