From 335e1cfc513dec5065f0a79a9f7180c3abeb25e7 Mon Sep 17 00:00:00 2001 From: Arun SAG Date: Tue, 20 Sep 2011 00:04:45 +0530 Subject: Add support for linking multiple key terms - Use LongStringValue of livesettings to capture multiple patterns and links - Honor all the patterns for autolinking with URLS in utils/markup.py --- askbot/conf/markup.py | 55 +++++++++++++++++++++++++++----------------------- askbot/utils/markup.py | 9 ++++++--- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/askbot/conf/markup.py b/askbot/conf/markup.py index 07f60c39..7ec0d73f 100644 --- a/askbot/conf/markup.py +++ b/askbot/conf/markup.py @@ -4,7 +4,7 @@ Settings that modify processing of user text input from askbot.conf.settings_wrapper import settings from askbot.deps.livesettings import ConfigurationGroup -from askbot.deps.livesettings import BooleanValue, StringValue +from askbot.deps.livesettings import BooleanValue, StringValue, LongStringValue from django.utils.translation import ugettext as _ import askbot from askbot import const @@ -89,32 +89,37 @@ settings.register( settings.register( - StringValue( - AUTOLINK, - 'PATTERN', - description=_('Regex to detect the pattern'), - help_text=_( - 'Enter a valid regular expression to ' - 'detect the pattern. For example to' - 'detect something like #rhbz 637402 ' - 'use a regular expression like #rhbz\s(\d+)' - ), - default = '' - ) + LongStringValue( + AUTOLINK, + 'PATTERN', + description=_('Regex to detect the pattern'), + help_text=_( + 'Enter a valid regular expression to ' + 'detect the pattern. For example to' + 'detect something like #rhbz 637402 ' + 'use a regular expression like #rhbz\s(\d+)' + 'If you want to process multiple regex enter' + ' them line by line' + ), + default = '' ) + ) settings.register( - StringValue( - AUTOLINK, - 'AUTO_LINK_URL', - description=_('URL for autolinking'), - help_text=_( - 'Let us assume that to detect a pattern #rhbz 637402' - ' the regex is #rhbz\s(\d+) ' - 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' - ' Where \1 is the saved match (bugid) from the regular expression' - ), - default = '' - ) + LongStringValue( + AUTOLINK, + 'AUTO_LINK_URL', + description=_('URL for autolinking'), + help_text=_( + 'Let us assume that to detect a pattern #rhbz 637402' + ' the regex is #rhbz\s(\d+) ' + 'then the autolink URL should be https://bugzilla.redhat.com/show_bug.cgi?id=\1' + ' Where \1 is the saved match (bugid) from the regular expression' + ' If you want to process multiple regex enter' + ' them line by line. The URL in first line will be used to link the' + ' pattern on the first line' + ), + default = '' ) + ) diff --git a/askbot/utils/markup.py b/askbot/utils/markup.py index ef67b315..8d072325 100644 --- a/askbot/utils/markup.py +++ b/askbot/utils/markup.py @@ -24,9 +24,12 @@ def get_parser(): extras.append('video') if askbot_settings.ENABLE_AUTO_LINKING: - LINK_PATTERNS.append((re.compile(askbot_settings.PATTERN),askbot_settings.AUTO_LINK_URL)) - - + pattern_list = askbot_settings.PATTERN.split('\n') + url_list = askbot_settings.AUTO_LINK_URL.split('\n') + + for i in range(0,len(pattern_list)): + LINK_PATTERNS.append((re.compile(pattern_list[i].strip()),url_list[i].strip())) + return Markdown( html4tags=True, extras=extras, -- cgit v1.2.3-1-g7c22