diff options
Diffstat (limited to 'mediagoblin/tools/text.py')
-rw-r--r-- | mediagoblin/tools/text.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/mediagoblin/tools/text.py b/mediagoblin/tools/text.py index de4bb281..d576224d 100644 --- a/mediagoblin/tools/text.py +++ b/mediagoblin/tools/text.py @@ -21,6 +21,7 @@ from lxml.html.clean import Cleaner from mediagoblin import mg_globals from mediagoblin.tools import url + # A super strict version of the lxml.html cleaner class HTML_CLEANER = Cleaner( scripts=True, @@ -42,6 +43,8 @@ HTML_CLEANER = Cleaner( host_whitelist=(), whitelist_tags=set([])) +TAGS_DELIMITER=','; + def clean_html(html): # clean_html barfs on an empty string if not html: @@ -49,6 +52,7 @@ def clean_html(html): return HTML_CLEANER.clean_html(html) + def convert_to_tag_list_of_dicts(tag_string): """ Filter input from incoming string containing user tags, @@ -64,7 +68,7 @@ def convert_to_tag_list_of_dicts(tag_string): # Split the tag string into a list of tags for tag in stripped_tag_string.split( - mg_globals.app_config['tags_delimiter']): + TAGS_DELIMITER): # Ignore empty or duplicate tags if tag.strip() and tag.strip() not in [t['name'] for t in taglist]: @@ -73,6 +77,7 @@ def convert_to_tag_list_of_dicts(tag_string): 'slug': url.slugify(tag.strip())}) return taglist + def media_tags_as_string(media_entry_tags): """ Generate a string from a media item's tags, stored as a list of dicts @@ -81,13 +86,15 @@ def media_tags_as_string(media_entry_tags): """ media_tag_string = '' if media_entry_tags: - media_tag_string = mg_globals.app_config['tags_delimiter'].join( + media_tag_string = (TAGS_DELIMITER+u' ').join( [tag['name'] for tag in media_entry_tags]) return media_tag_string + TOO_LONG_TAG_WARNING = \ u'Tags must be shorter than %s characters. Tags that are too long: %s' + def tag_length_validator(form, field): """ Make sure tags do not exceed the maximum tag length. @@ -105,6 +112,7 @@ def tag_length_validator(form, field): MARKDOWN_INSTANCE = markdown.Markdown(safe_mode='escape') + def cleaned_markdown_conversion(text): """ Take a block of text, run it through MarkDown, and clean its HTML. |