# HG changeset patch # User Ludovic Chabant # Date 1355292809 28800 # Node ID f8b3a6dc65afcb24fe21c9b96c5af542b0047926 # Parent 37aa641facaf46a2e8c44b5dc1403df230ba7651 Added wiki syntax for changing the title of a page. diff -r 37aa641facaf -r f8b3a6dc65af wikked/wiki.py --- a/wikked/wiki.py Tue Dec 11 22:13:10 2012 -0800 +++ b/wikked/wiki.py Tue Dec 11 22:13:29 2012 -0800 @@ -19,6 +19,7 @@ self.url = url self.ext = ext self.out_links = [] + self.title = None class PageFormatter(object): @@ -40,11 +41,20 @@ raise FormatterNotFound("No formatter mapped to file extension: " + extension) def _preProcessWikiSyntax(self, ctx, text): - return self._processWikiLinks(ctx, text) + text = self._processWikiMeta(ctx, text) + text = self._processWikiLinks(ctx, text) + return text def _postProcessWikiSyntax(self, ctx, text): return text + def _processWikiMeta(self, ctx, text): + def repl1(m): + ctx.title = m.group(1) + return '' + text = re.sub(r'^\[\[title:\s*(.+)\]\]\s*$', repl1, text, flags=re.MULTILINE) + return text + def _processWikiLinks(self, ctx, text): s = self @@ -78,7 +88,7 @@ @property def title(self): self._ensureMeta() - return self._meta['name'] + return self._meta['title'] @property def raw_text(self): @@ -128,6 +138,10 @@ f = PageFormatter(self.wiki) self._meta['formatted'] = f.formatText(ctx, self._meta['content']) + self._meta['title'] = re.sub(r'\-', ' ', self._meta['name']) + if ctx.title is not None: + self._meta['title'] = ctx.title + self._meta['out_links'] = [] for l in ctx.out_links: self._meta['out_links'].append(l)