Skip to content

Commit

Permalink
[#2939] Improve the markdown_extract function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Nov 20, 2012
1 parent bcae651 commit 7875f3e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -559,10 +559,15 @@ def group_name_to_title(name):


def markdown_extract(text, extract_length=190):
''' return the plain text representation of markdown encoded text. That
is the texted without any html tags. If extract_length is 0 then it
will not be truncated.'''
if (text is None) or (text.strip() == ''):
return ''
plain = re.sub(r'<.*?>', '', markdown(text))
return literal(unicode(truncate(plain, length=extract_length, indicator='...', whole_word=True)))
if not extract_length or len(plain) < extract_length:
return plain
return truncate(plain, length=extract_length, indicator='...', whole_word=True)


def icon_url(name):
Expand Down

0 comments on commit 7875f3e

Please sign in to comment.