diff --git a/plugins/util/text.py b/plugins/util/text.py index 8e5c8a0..2d32cd6 100755 --- a/plugins/util/text.py +++ b/plugins/util/text.py @@ -95,6 +95,24 @@ def multiword_replace(text, wordDic): return rc.sub(translate, text) +def truncate_words(content, length=10, suffix='...'): + "Truncates a string after a certain number of words." + nmsg = content.split(" ") + out = None + x = 0 + for i in nmsg: + if x <= length: + if out: + out = out + " " + nmsg[x] + else: + out = nmsg[x] + x = x + 1 + if x <= length: + return out + else: + return out + suffix + + # from def truncate_str(content, length=100, suffix='...'): "Truncates a string after a certain number of chars."