summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun SAG <sagarun@gmail.com>2011-09-20 00:04:45 +0530
committerArun SAG <sagarun@gmail.com>2011-09-20 00:04:45 +0530
commit335e1cfc513dec5065f0a79a9f7180c3abeb25e7 (patch)
treec78c455476a8ca035079ce4c286467792013788d
parent28007df0bc6e944901486e337387787e2d7ddc69 (diff)
downloadaskbot-335e1cfc513dec5065f0a79a9f7180c3abeb25e7.tar.gz
askbot-335e1cfc513dec5065f0a79a9f7180c3abeb25e7.tar.bz2
askbot-335e1cfc513dec5065f0a79a9f7180c3abeb25e7.zip
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
-rw-r--r--askbot/conf/markup.py55
-rw-r--r--askbot/utils/markup.py9
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,