Beispiel #1
0
    def _heading_formatter(self, match, fullmatch):
        match = match.strip()
        self.close_table()
        self.close_paragraph()
        self.close_indentation()
        self.close_list()
        self.close_def_list()

        depth = min(len(fullmatch.group('hdepth')), 5)
        heading = match[depth + 1:len(match) - depth - 1]

        text = unescape(heading)
        sans_markup = re.sub(r'</?\w+(?: .*?)?>', '', text)

        anchor = self._anchor_re.sub('', sans_markup.decode('utf-8'))
        if not anchor or not anchor[0].isalpha():
            # an ID must start with a letter in HTML
            anchor = 'a' + anchor
        i = 1
        anchor = anchor_base = anchor.encode('utf-8')
        while anchor in self._anchors:
            anchor = anchor_base + str(i)
            i += 1
        self._anchors.append(anchor)
        self.out.write('<h%d id="%s">%s</h%d>' % (depth, anchor, text, depth))
Beispiel #2
0
 def _format_link(self, formatter, ns, query, label):
     if query[0] == '?':
         return '<a class="query" href="%s">%s</a>' \
                % (escape(formatter.href.query()) + query.replace(' ', '+'),
                   label)
     else:
         from trac.ticket.query import Query, QuerySyntaxError
         try:
             query = Query.from_string(formatter.env, unescape(query))
             return '<a class="query" href="%s">%s</a>' \
                    % (escape(query.get_href()), label)
         except QuerySyntaxError, e:
             return '<em class="error">[Error: %s]</em>' % escape(e)
Beispiel #3
0
    def _macro_formatter(self, match, fullmatch):
        name = fullmatch.group('macroname')
        if name in ['br', 'BR']:
            return '<br />'
        elif name in ['html']: 
            args = fullmatch.group('macroargs')
            args = unescape(args)
            try:
                macro = WikiProcessor(self.env, name)
                return macro.process(self.req, args, 1)
            except Exception, e:
                self.env.log.error('Macro %s(%s) failed' % (name, args),
                                   exc_info=True)
                return system_message('Error: Macro %s(%s) failed' % (name, args), e)

            return match
Beispiel #4
0
   def process_request(self, req, chrome, projects):
        milestones = []
        stats = []
        for project in projects:
            env = project["env"]
            for m in Milestone.select(env, False, env.get_db_cnx()):
                req.href = env.href
                milestone = milestone_to_hdf(env, env.get_db_cnx(), req, m)
                milestone['project'] = project
                milestones.append(milestone)

        milestones.sort(milestone_cmp)

        idx = 0
        for m in milestones:
            project = m['project']
            env = project['env']
            milestone_name = unescape(m['name']) # Kludge
            prefix = 'roadmap.milestones.%d.' % idx
            tickets = get_tickets_for_milestone(env, env.get_db_cnx(), milestone_name,
                                                'owner')
            stat = calc_ticket_stats(tickets)
            stats.append({'stats': stat})
            m['queries'] = {}
            for k, v in get_query_links(env, milestone_name).items():
                m['queries'][k] = v
            m['tickets'] = tickets # for the iCalendar view
            idx += 1

            # make milestone names unique
            m["name"] = project["name"] + " " + m["name"]

        data = {
            'milestones': milestones,
            'milestone_stats': stats
        }

        data["chrome.nav.mainnav.roadmap.active"] = 1
        data['title'] = _('Roadmap')
        template_dir = os.path.dirname(__file__) + '/templates/'
        chrome.populate_data(req, data)
        output = chrome.render_template(req, template_dir + "roadmap.html", data)
        req.session.save()
        req.send(output, 'text/html')
Beispiel #5
0
    def handle_endtag(self, tag): 
        if self.need_end_flag == True:
            data = '</' + tag + '>'
        else:
            data = ''
        
        if self.mode == self.MODE_A:
            if tag == 'a':
                self.output_texts()
                self.output.append(data)
                self.mode = self.MODE_TEXT
                
            else:
                self.texts.append(data)
        if self.mode == self.MODE_H:
            if tag in ('h1','h2','h3','h4','h5','h6') :
                self.output_texts()
                data = self.output.pop()
                id = self.output.pop()
                self.output.append('<%s id="%s">%s</%s>' %
                     (self.head_tag,id,unescape(data),self.head_tag))
                self.mode = self.MODE_TEXT
                

        elif self.mode == self.MODE_PRE:
            if tag == 'pre':
                if self.can_process == True:
                    self.texts.append('}}}'+os.linesep)
                    self.output_texts()
                else:
                    self.output_texts()
                    self.output.append(data)
                self.mode = self.MODE_TEXT
            else:
                pass
        else:
            if tag == 'span':
                if self.spans.pop() == 'hit':
                    return
            self.output_texts()
            self.output.append(data)