Mercurial > wikked
changeset 2:f8b3a6dc65af
Added wiki syntax for changing the title of a page.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 11 Dec 2012 22:13:29 -0800 |
parents | 37aa641facaf |
children | 59cad6ce1a1c |
files | wikked/wiki.py |
diffstat | 1 files changed, 16 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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)