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"\1", value, re.DOTALL) value = re.sub("'b''([^']+)'''", r"\1", value, re.DOTALL) value = re.sub("''([^']+)''", r"\1", value, re.DOTALL) - #make cave links - value = re.sub("\[\[\s*cave:([^\s]+)\s*\s*\]\]", r'\1' % url_root, value, re.DOTALL) - #make people links - value = re.sub("\[\[\s*person:(.+)\]\]",r'\1' % 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'\1' % url_root, value, re.DOTALL) + #make people links + value = re.sub("\[\[\s*person:(.+)\|(.+)\]\]",r'\2' % url_root, value, re.DOTALL) + #make subcave links + value = re.sub("\[\[\s*subcave:(.+)\|(.+)\]\]",r'\2' % url_root, value, re.DOTALL) + #make cavedescription links + value = re.sub("\[\[\s*cavedescription:(.+)\|(.+)\]\]",r'\1' % url_root, value, re.DOTALL) + #Make lists from lines starting with lists of [stars and hashes] outValue = "" listdepth = [] diff --git a/utils.py b/utils.py index 5245589..1b16059 100644 --- a/utils.py +++ b/utils.py @@ -99,7 +99,7 @@ re_subs = [(re.compile(r"\]*\>(.*?)\", re.DOTALL), r"'''\1'''"), (re.compile(r"\]*\>(.*?)\", re.DOTALL), r"====\1===="), (re.compile(r"\]*\>(.*?)\", re.DOTALL), r"=====\1====="), (re.compile(r"\]*\>(.*?)\", re.DOTALL), r"======\1======"), - (re.compile(r"\(.*?)\", re.DOTALL), r"[subcave:\1|\2]"), + (re.compile(r"\(.*?)\", re.DOTALL), r"[[subcave:\1|\2]]"), #interpage link needed (re.compile(r"\(.*?)\", re.DOTALL), r"[[cavedescription:\1|\2]]"), (re.compile(r"\[\([^\s]*).*?\\]", re.DOTALL), r"[[qm:\1]]"),