diff options
-rw-r--r-- | core/models.py | 4 | ||||
-rw-r--r-- | core/templatetags/wiki_markup.py | 18 | ||||
-rw-r--r-- | utils.py | 2 |
3 files changed, 16 insertions, 8 deletions
diff --git a/core/models.py b/core/models.py index 7c23ad9..a9ba8c1 100644 --- a/core/models.py +++ b/core/models.py @@ -541,9 +541,11 @@ class CaveDescription(TroggleModel): return urlparse.urljoin(settings.URL_ROOT, reverse('cavedescription', args=(self.short_name,)))
def save(self):
+ """
+ Overridden save method which stores wikilinks in text as links in database.
+ """
super(CaveDescription, self).save()
qm_list=get_related_by_wikilinks(self.description)
- print qm_list
for qm in qm_list:
self.linked_qms.add(qm)
super(CaveDescription, self).save()
diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py index 4cfd78d..cf11358 100644 --- a/core/templatetags/wiki_markup.py +++ b/core/templatetags/wiki_markup.py @@ -65,10 +65,7 @@ def wiki_to_html_short(value, autoescape=None): value = re.sub("''''([^']+)''''", r"<b><i>\1</i></b>", value, re.DOTALL)
value = re.sub("'b''([^']+)'''", r"<b>\1</b>", value, re.DOTALL)
value = re.sub("''([^']+)''", r"<i>\1</i>", value, re.DOTALL)
- #make cave links
- value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL)
- #make people links
- value = re.sub("\[\[\s*person:(.+)\]\]",r'<a href="%s/person/\1/">\1</a>' % url_root, value, re.DOTALL)
+
#make headers
def headerrepl(matchobj):
number=len(matchobj.groups()[0])
@@ -78,8 +75,7 @@ def wiki_to_html_short(value, autoescape=None): else:
print 'morethanone'
return matchobj.group()
- value = re.sub(r"(=+)([^=]+)(=+)",headerrepl,value)
-
+ value = re.sub(r"(?m)^(=+)([^=]+)(=+)$",headerrepl,value)
#make qm links. this takes a little doing
qmMatchPattern=settings.QM_PATTERN
@@ -141,7 +137,17 @@ def wiki_to_html_short(value, autoescape=None): return res
value = re.sub(photoLinkPattern,photoLinkRepl, value, re.DOTALL)
value = re.sub(photoSrcPattern,photoSrcRepl, value, re.DOTALL)
+
+ #make cave links
+ value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'<a href="%s/cave/\1/">\1</a>' % url_root, value, re.DOTALL)
+ #make people links
+ value = re.sub("\[\[\s*person:(.+)\|(.+)\]\]",r'<a href="%s/person/\1/">\2</a>' % url_root, value, re.DOTALL)
+ #make subcave links
+ value = re.sub("\[\[\s*subcave:(.+)\|(.+)\]\]",r'<a href="%s/subcave/\1/">\2</a>' % url_root, value, re.DOTALL)
+ #make cavedescription links
+ value = re.sub("\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'<a href="%s/cavedescription/\2/">\1</a>' % url_root, value, re.DOTALL)
+
#Make lists from lines starting with lists of [stars and hashes]
outValue = ""
listdepth = []
@@ -99,7 +99,7 @@ re_subs = [(re.compile(r"\<b[^>]*\>(.*?)\</b\>", re.DOTALL), r"'''\1'''"), (re.compile(r"\<h4[^>]*\>(.*?)\</h4\>", re.DOTALL), r"====\1===="),
(re.compile(r"\<h5[^>]*\>(.*?)\</h5\>", re.DOTALL), r"=====\1====="),
(re.compile(r"\<h6[^>]*\>(.*?)\</h6\>", re.DOTALL), r"======\1======"),
- (re.compile(r"\<a\s+id=['\"]([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[subcave:\1|\2]"),
+ (re.compile(r"\<a\s+id=['\"]([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[[subcave:\1|\2]]"),
#interpage link needed
(re.compile(r"\<a\s+href=['\"]#([^'\"]*)['\"]\s*\>(.*?)\</a\>", re.DOTALL), r"[[cavedescription:\1|\2]]"),
(re.compile(r"\[\<a\s+href=['\"][^'\"]*['\"]\s+id=['\"][^'\"]*['\"]\s*\>([^\s]*).*?\</a\>\]", re.DOTALL), r"[[qm:\1]]"),
|