Edgewall Software

ChristopherLenz: wiki2x_in_templates.2.diff

File wiki2x_in_templates.2.diff, 4.2 kB (added by cmlenz, 2 years ago)

See this thread, patch against r4014

  • trac/wiki/web_ui.py

     
    396396        if page.name == 'WikiStart': 
    397397            data['title'] = '' 
    398398 
    399         page_html = comment_html = attach_href = '' 
    400         latest_page = WikiPage(self.env, page.name) 
    401  
     399        comment_html = attach_href = '' 
    402400        if page.exists: 
    403             page_html = wiki_to_html(page.text, self.env, req, db) 
     401            latest_page = WikiPage(self.env, page.name) 
    404402            if version: 
    405403                comment_html = wiki_to_oneliner(page.comment or '--', 
    406404                                                self.env, db) 
    407405        else: 
    408406            if not req.perm.has_permission('WIKI_CREATE'): 
    409407                raise HTTPNotFound('Page %s not found', page.name) 
    410             page_html = html.P('Describe "%s" here' % data['page_name']) 
    411408 
    412409        # Show attachments 
    413410        attachments = attachments_data(self.env, req, db, 'wiki', page.name) 
     
    419416                     WikiSystem(self.env).get_pages(prefix)] 
    420417 
    421418        data.update({'action': 'view', 
    422                      'page_html': page_html, 
    423419                     'comment_html': comment_html, 
    424420                     'latest_version': latest_page.version, 
    425421                     'attachments': attachments, 
  • trac/web/chrome.py

     
    3636                              format_time, http_date 
    3737from trac.web.api import IRequestHandler, HTTPNotFound 
    3838from trac.web.href import Href 
    39 from trac.wiki import IWikiSyntaxProvider 
     39from trac.wiki import wiki_to_html, wiki_to_oneliner, IWikiSyntaxProvider 
    4040 
    4141def add_link(req, rel, href, title=None, mimetype=None, classname=None): 
    4242    """Add a link to the HDF data set that will be inserted as <link> element in 
     
    427427        data['format_time'] = partial(format_time, tzinfo=tzinfo) 
    428428        data['fromtimestamp'] = partial(datetime.fromtimestamp, tz=tzinfo) 
    429429 
     430        # Wiki-formatting functions 
     431        data['wiki_to_html'] = partial(wiki_to_html, env=self.env, req=req) 
     432        data['wiki_to_oneliner'] = partial(wiki_to_html, env=self.env, req=req) 
     433 
    430434    def load_template(self, filename, method=None): 
    431435        """Retrieve a Template and optionally preset the template data. 
    432436 
     
    468472            return stream.render('text') 
    469473        else: 
    470474            doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type) 
     475            req.environ['trac.chrome.links'] = {} 
     476            req.environ['trac.chrome.scripts'] = [] 
     477            data['chrome'].update({ 
     478                'post_links': req.environ['trac.chrome.links'], 
     479                'post_scripts': req.environ['trac.chrome.scripts'], 
     480            }) 
    471481            return stream.render(method, doctype=doctype) 
  • templates/layout.html

     
    5050    <div id="main"> 
    5151      ${select('*|text()')} 
    5252 
     53      <script type="text/javascript" py:if="chrome.post_links"> 
     54        <py:for each="link in chrome.post_links.get('stylesheet')"> 
     55          $.loadStyleSheet("${link.href}", "${link.title}"); 
     56        </py:for> 
     57      </script> 
     58      <script py:for="script in chrome.post_scripts" 
     59              type="${script.type}" src="${script.href}"></script> 
     60 
    5361      <div id="altlinks" py:if="chrome.links.alternate"> 
    5462        <h3>Download in other formats:</h3> 
    5563        <ul> 
  • templates/wiki_view.html

     
    4040        </table> 
    4141      </py:if> 
    4242 
    43       <div class="wikipage searchable"> 
    44         $page_html 
     43      <div class="wikipage searchable" py:choose=""> 
     44        <py:when test="page.exists"> 
     45          ${wiki_to_html(page.text)} 
     46        </py:when> 
     47        <py:otherwise> 
     48          Describe ${page.name} here. 
     49        </py:otherwise> 
    4550      </div> 
    4651 
    4752      ${list_of_attachments(attachments, attach_href, compact=True)}