Python module which helps to cut HTML strings by keeping HTML tags as they are
This is repository is an improved version of htmlcutstring (https://code.google.com/p/cut-html-string/). I’m not the original author.
Differences between original
htmlcutstr has availability to count words instead of characters
It works fine on both Python 2.x and 3.x
Run ‘setup.py install’ to install this package.
cutHtmlString(string, limit, countType=’c’)
from htmlcutstr import cutHtmlString htmlstring = '<div>insert your <a>text</a> here</div>' print(cutHtmlString(htmlstring, 10)) # '<div>insert you</div>' print(cutHtmlString(htmlstring, 3, 'w')) # '<div>insert your <a>text</a></div>'
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.