def format(self): '''Formats the self.wikitext and returns the content as HTML source (unicode). ''' # Format the content. content = format_text(self.wikitext, self.pagename) # Process links to subpages in this category. subpages = [] for fname, prag in all_pragmas.items(): if self.pagename in prag.multiple('#category'): subpages.append(wikiutil.inputFile2pageName(fname)) if subpages: lines = [ '', '<a name="#category-subpages"></a>', '<h1>%s</h1>' % (config.text.subpages % dict(value=self.pagename)), '<div id="category-subpages">', '<table>', '<tr>', '<td>', '<ul>' ] subpages.sort(lambda a, b: -(a.lower() < b.lower())) num_of_columns = 3 m = len(subpages) p = m / num_of_columns if m % num_of_columns: p += 1 for i in xrange(m): if i > 0 and i % p == 0: lines.extend(['</ul>', '</td>', '<td>', '<ul>']) lines.append( '<li><a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(subpages[i]), subpages[i])) lines.extend(['</ul>', '</td>', '</tr>', '</table>', '</div>']) content += '\n'.join(lines) # Process categories this page belongs to. categories = self.pragmas.multiple('#category') if categories: categories.sort(lambda a, b: -(a.lower() < b.lower())) for category in categories: fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) assert os.path.exists(fname), '%s does not exist' % fname links = [ '<a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(name), name) for name in categories ] if len(links) > 1: format = config.text.categories else: format = config.text.category lines = ['', '<p class="categories-links">'] lines.append(format % dict(value=' | '.join(links))) lines.append('</p>') content += '\n'.join(lines) return content
def format(self): '''Formats the self.wikitext and returns the content as HTML source (unicode). ''' # Format the content. content = format_text(self.wikitext, self.pagename) # Process links to subpages in this category. subpages = [] for fname, prag in all_pragmas.items(): if self.pagename in prag.multiple('#category'): subpages.append(wikiutil.inputFile2pageName(fname)) if subpages: lines = ['', '<a name="#category-subpages"></a>', '<h1>%s</h1>' % (config.text.subpages % dict(value=self.pagename)), '<div id="category-subpages">', '<table>', '<tr>', '<td>', '<ul>'] subpages.sort(lambda a, b: -(a.lower() < b.lower())) num_of_columns = 3 m = len(subpages) p = m / num_of_columns if m % num_of_columns: p += 1 for i in xrange(m): if i > 0 and i % p == 0: lines.extend(['</ul>', '</td>', '<td>', '<ul>']) lines.append('<li><a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(subpages[i]), subpages[i])) lines.extend(['</ul>', '</td>', '</tr>', '</table>', '</div>']) content += '\n'.join(lines) # Process categories this page belongs to. categories = self.pragmas.multiple('#category') if categories: categories.sort(lambda a, b: -(a.lower() < b.lower())) for category in categories: fname = wikiutil.pageName2inputFile(category) wikiutil.assertFileNameCase(fname) assert os.path.exists(fname), '%s does not exist' % fname links = ['<a href="%s.html">%s</a>' % (wikiutil.quoteWikinameURL(name), name) for name in categories] if len(links) > 1: format = config.text.categories else: format = config.text.category lines = ['', '<p class="categories-links">'] lines.append(format % dict(value=' | '.join(links))) lines.append('</p>') content += '\n'.join(lines) return content
def pagelink(self, on, pagename='', anchor=None, css=None, **kw): """ Link to a page. formatter.text_python will use an optimized call with a page!=None parameter. DO NOT USE THIS YOURSELF OR IT WILL BREAK. See wikiutil.link_tag() for possible keyword parameters. """ apply(FormatterBase.pagelink, (self, on, pagename), kw) if on: attrs = {} # Warn about non-existing pages. if not os.path.exists(wikiutil.pageName2inputFile(pagename)): warning('linked "%s" page does not exists' % pagename) if pagename == config.general.indexpagename: pagename = 'index' # FIXME: url = wikiutil.quoteWikinameURL(pagename + ".html") # Add anchor if anchor: url = "%s#%s" % (url, wikiutil.url_quote_plus(anchor)) attrs['href'] = url if css: attrs['class'] = css markup = self._open('a', attr=attrs, **kw) else: markup = self._close('a') return markup