• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python formatter.format_to_html函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中trac.wiki.formatter.format_to_html函数的典型用法代码示例。如果您正苦于以下问题:Python format_to_html函数的具体用法?Python format_to_html怎么用?Python format_to_html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了format_to_html函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _ticket_links

def _ticket_links(env, formatter, t, a_class=""):
    """Build links to tickets."""
    tkt_id = str(t.get("id"))
    status = t.get("status")
    summary = to_unicode(t.get("summary"))
    owner = to_unicode(t.get("owner"))
    description = to_unicode(t.get("description"))
    url = t.get("href")

    if status == "closed":
        a_class = a_class + "closed"
    else:
        a_class = a_class + "open"

    # Reduce content for tooltips.
    markup = format_to_html(env, formatter.context, description)
    extractor = TextExtractor()
    extractor.feed(markup)
    tip = tag.span(shorten_line(extractor.getvalue()))

    ticket = tag.a("#" + tkt_id, href=url)
    ticket(tip, class_="tip", target="_blank")
    ticket = tag.div(ticket, class_=a_class, align="left")
    # Fix stripping of regular leading space in IE.
    blank = " "
    ticket(Markup(blank), summary, " (", owner, ")")

    summary = tag(summary, " (", owner, ")")
    ticket_short = tag.span(tag.a("#" + tkt_id, href=url, target="_blank", title_=summary), class_=a_class)
    return ticket, ticket_short
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:macros.py


示例2: expand_macro

 def expand_macro(self, formatter, name, content, args={}):
     reponame = args.get("repository") or ""
     rev = args.get("revision")
     repos = RepositoryManager(self.env).get_repository(reponame)
     try:
         changeset = repos.get_changeset(rev)
         message = changeset.message
         rev = changeset.rev
         resource = repos.resource
     except Exception:
         message = content
         resource = Resource("repository", reponame)
     if formatter.context.resource.realm == "ticket":
         ticket_re = CommitTicketUpdater.ticket_re
         if not any(int(tkt_id) == int(formatter.context.resource.id) for tkt_id in ticket_re.findall(message)):
             return tag.p("(The changeset message doesn't reference this " "ticket)", class_="hint")
     if ChangesetModule(self.env).wiki_format_messages:
         return tag.div(
             format_to_html(
                 self.env, formatter.context.child("changeset", rev, parent=resource), message, escape_newlines=True
             ),
             class_="message",
         )
     else:
         return tag.pre(message, class_="message")
开发者ID:moreati,项目名称:trac-gitsvn,代码行数:25,代码来源:commit_updater.py


示例3: expand_macro

 def expand_macro(self, formatter, name, content, args=None):
     args = args or {}
     reponame = args.get('repository') or ''
     rev = args.get('revision')
     repos = RepositoryManager(self.env).get_repository(reponame)
     try:
         changeset = repos.get_changeset(rev)
         message = changeset.message
         rev = changeset.rev
         resource = repos.resource
     except Exception:
         message = content
         resource = Resource('repository', reponame)
     if formatter.context.resource.realm == 'ticket':
         ticket_re = CommitTicketUpdater.ticket_re
         if not any(int(tkt_id) == int(formatter.context.resource.id)
                    for tkt_id in ticket_re.findall(message)):
             return tag.p(_("(The changeset message doesn't reference this "
                            "ticket)"), class_='hint')
     if ChangesetModule(self.env).wiki_format_messages:
         return tag.div(format_to_html(self.env,
             formatter.context.child('changeset', rev, parent=resource),
             message, escape_newlines=True), class_='message')
     else:
         return tag.pre(message, class_='message')
开发者ID:aroth-arsoft,项目名称:arsoft-trac-commitupdater,代码行数:25,代码来源:commit_updater.py


示例4: get_macro_descr

 def get_macro_descr():
     for macro_provider in formatter.wiki.macro_providers:
         names = list(macro_provider.get_macros() or [])
         if name_filter and not any(name.startswith(name_filter)
                                    for name in names):
             continue
         try:
             name_descriptions = [
                 (name, macro_provider.get_macro_description(name))
                 for name in names]
         except Exception, e:
             yield system_message(
                 _("Error: Can't get description for macro %(name)s",
                   name=names[0]), e), names
         else:
             for descr, pairs in groupby(name_descriptions,
                                         key=lambda p: p[1]):
                 if descr:
                     if isinstance(descr, (tuple, list)):
                         descr = dgettext(descr[0],
                                          to_unicode(descr[1])) \
                                 if descr[1] else ''
                     else:
                         descr = to_unicode(descr) or ''
                     if content == '*':
                         descr = format_to_oneliner(
                             self.env, formatter.context, descr,
                             shorten=True)
                     else:
                         descr = format_to_html(
                             self.env, formatter.context, descr)
                 yield descr, [name for name, descr in pairs]
开发者ID:exocad,项目名称:exotrac,代码行数:32,代码来源:macros.py


示例5: safe_wiki_to_html

 def safe_wiki_to_html(context, text):
     try:
         return format_to_html(self.env, context, text)
     except Exception, e:
         self.log.error('Unable to render component documentation: %s',
                        exception_to_unicode(e, traceback=True))
         return tag.pre(text)
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:7,代码来源:web_ui.py


示例6: expand_macro

 def expand_macro(self, formatter, name, content):
     add_stylesheet(formatter.req, 'notebox/css/notebox.css')
     args, kwargs = parse_args(content)
     width = len(args) > 2 and args[2] or '70%'
     return tag.div(format_to_html(self.env, formatter.context, args[1]), 
                    class_='notebox-%s' % (args[0],),
                    style='width: %s' % (width,))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:7,代码来源:macro.py


示例7: product_media_data

 def product_media_data(icons, product):
     return dict(href=product.href(),
                 thumb=icons.get(product.prefix, no_thumbnail),
                 title=product.name,
                 description=format_to_html(self.env,
                                            product_ctx(product),
                                            product.description),
                 links={'extras': (([{'href': req.href.products(
                                         product.prefix, action='edit'),
                                      'title': _('Edit product %(prefix)s',
                                                 prefix=product.prefix),
                                      'icon': tag.i(class_='icon-edit'),
                                      'label': _('Edit')},]
                                    if 'PRODUCT_MODIFY' in req.perm
                                    else []) +
                                   [{'href': product.href(),
                                     'title': _('Home page'),
                                     'icon': tag.i(class_='icon-home'),
                                     'label': _('Home')},
                                    {'href': product.href.dashboard(),
                                     'title': _('Tickets dashboard'),
                                     'icon': tag.i(class_='icon-tasks'),
                                     'label': _('Tickets')},
                                    {'href': product.href.wiki(),
                                     'title': _('Wiki'),
                                     'icon': tag.i(class_='icon-book'),
                                     'label': _('Wiki')}]),
                        'main': {'href': product.href(),
                                 'title': None,
                                 'icon': tag.i(class_='icon-chevron-right'),
                                 'label': _('Browse')}})
开发者ID:mohsadki,项目名称:dargest,代码行数:31,代码来源:theme.py


示例8: serialized

 def serialized(self, env, context):
     return {
         'id': self.id,
         'stack': self.stack,
         'rank': self.rank,
         'title': self.title, 
         'title_html': format_to_html(env, context, self.title),
     }
开发者ID:folpindo,项目名称:psuter-cards-plugin,代码行数:8,代码来源:model.py


示例9: render

 def render(self, context, mimetype, content, filename=None, url=None):
     if url is not None:
         match = re.match(self.PREVIEW_PATTERN, urllib.unquote(str(url)))
         if match:
             path_info = match.groupdict()
             macro = unicode(self.MACRO_FORMAT % path_info, self.ENCODING)
             return format_to_html(self.env, context, macro)
     return None
开发者ID:arielnetworks,项目名称:TracMovieMacro,代码行数:8,代码来源:web_ui.py


示例10: render_timeline_event

    def render_timeline_event(self, context, field, event):
        ev = event[3]

        if field=='title':
            return tag(tag.em(ev[0]), ' found on ', ev[1])
        elif field=='description':
            return format_to_html(self.env, context, ev[3])
        elif field=='url':
            return ev[2]
开发者ID:trac-hacks,项目名称:tracmentions,代码行数:9,代码来源:plugin.py


示例11: getPageHTML

 def getPageHTML(self, req, pagename, version=None):
     """ Return latest version of page as rendered HTML, utf8 encoded. """
     page = self._fetch_page(req, pagename, version)
     fields = {"text": page.text}
     for manipulator in self.manipulators:
         manipulator.prepare_wiki_page(req, page, fields)
     context = Context.from_request(req, page.resource, absurls=True)
     html = format_to_html(self.env, context, fields["text"])
     return "<html><body>%s</body></html>" % html.encode("utf-8")
开发者ID:nextview,项目名称:tracxmlrpc,代码行数:9,代码来源:wiki.py


示例12: _gen_ticket_entry

    def _gen_ticket_entry(self, t, a_class=''):
        id = str(t.get('id'))
        status = t.get('status')
        priority = t.get('priority')
        hours = t.get(self.hours_field_name)
        summary = to_unicode(t.get('summary'))
        owner = to_unicode(t.get('owner'))
        description = to_unicode(t.get('description')[:1024])
        url = t.get('href')

        if status == 'closed':
            a_class = a_class + 'closed'
        else:
            a_class = a_class + 'open'
        
        a_class += " ticket priority-" + priority            
        
        markup = format_to_html(self.env, self.ref.context, description)
        # Escape, if requested
        if self.sanitize is True:
            try:
                description = HTMLParser(StringIO(markup)
                                           ).parse() | HTMLSanitizer()
            except ParseError:
                description = escape(markup)
        else:
            description = markup

        # Replace tags that destruct tooltips too much
        desc = self.end_RE.sub(']', Markup(description))
        desc = self.del_RE.sub('', desc)
        # need 2nd run after purging newline in table cells in 1st run
        desc = self.del_RE.sub('', desc)
        desc = self.item_RE.sub('X', desc)
        desc = self.tab_RE.sub('[|||]', desc)
        description = self.open_RE.sub('[', desc)

        tip = tag.span(Markup(description))
        ticket = '#' + id
        ticket = tag.a(ticket, href=url)
        ticket(tip, class_='tip', target='_blank')
        ticket = tag.div(ticket)
        ticket(class_=a_class, align='left', **{"data-ticketid": id})
        # fix stripping of regular leading space in IE
        blank = '&nbsp;'
        ticket(Markup(blank), summary, ' (', owner, ')')
        ticket(tag.span(str(hours) + "h", class_="hours"))

        summary = tag(summary, ' (', owner, ')')
        ticket_short = '#' + id
        ticket_short = tag.a(ticket_short, href=url)
        ticket_short(target='_blank', title_=summary)
        ticket_short = tag.span(ticket_short)
        ticket_short(class_=a_class)

        return ticket,ticket_short
开发者ID:Techlightenment,项目名称:trac-plugins,代码行数:56,代码来源:macros.py


示例13: expand_macro

 def expand_macro(self, formatter, name, content, args):
     self.log.debug("SpoilerMacro: expand_macro")
     add_stylesheet(formatter.req, 'spoiler/css/spoiler.css')
     add_javascript(formatter.req, 'spoiler/js/spoiler.js')
     if '\n' in content:
         output = tag.div(class_="spoiler")(format_to_html(self.env, formatter.context,content))
     else:
         output = tag.span(class_="spoiler")(format_to_oneliner(self.env, formatter.context,content))
     self.log.debug("SpoilerMacro: expand_macro output")
     return output
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:10,代码来源:macro.py


示例14: expand_macro

    def expand_macro(self, formatter, name, args):
        from trac.config import ConfigSection, Option
        section_filter = key_filter = ''
        args, kw = parse_args(args)
        if args:
            section_filter = args.pop(0).strip()
        if args:
            key_filter = args.pop(0).strip()

        def getdoc(option_or_section):
            doc = to_unicode(option_or_section.__doc__)
            if doc:
                doc = dgettext(option_or_section.doc_domain, doc)
            return doc

        registry = ConfigSection.get_registry(self.compmgr)
        sections = dict((name, getdoc(section))
                        for name, section in registry.iteritems()
                        if name.startswith(section_filter))

        registry = Option.get_registry(self.compmgr)
        options = {}
        for (section, key), option in registry.iteritems():
            if section.startswith(section_filter):
                options.setdefault(section, {})[key] = option
                sections.setdefault(section, '')

        def default_cell(option):
            default = option.default
            if default is True:
                default = 'true'
            elif default is False:
                default = 'false'
            elif default == 0:
                default = '0.0' if isinstance(default, float) else '0'
            elif default:
                default = ', '.join(to_unicode(val) for val in default) \
                          if isinstance(default, (list, tuple)) \
                          else to_unicode(default)
            else:
                return tag.td(_("(no default)"), class_='nodefault')
            return tag.td(tag.code(default), class_='default')

        return tag.div(class_='tracini')(
            (tag.h3(tag.code('[%s]' % section), id='%s-section' % section),
             format_to_html(self.env, formatter.context, section_doc),
             tag.table(class_='wiki')(tag.tbody(
                 tag.tr(tag.td(tag.tt(option.name)),
                        tag.td(format_to_oneliner(
                            self.env, formatter.context, getdoc(option))),
                        default_cell(option))
                 for option in sorted(options.get(section, {}).itervalues(),
                                      key=lambda o: o.name)
                 if option.name.startswith(key_filter))))
            for section, section_doc in sorted(sections.iteritems()))
开发者ID:thimalk,项目名称:bloodhound,代码行数:55,代码来源:macros.py


示例15: _discussion_attachment_link

    def _discussion_attachment_link(self, formatter, namespace, params, label):
        id, name = params.split(':')

        # Create request context.
        context = Context.from_request(formatter.req)
        context.realm = 'discussion-wiki'

        # Get database access.
        db = self.env.get_db_cnx()
        context.cursor = db.cursor()

        if namespace == 'topic-attachment':
            return format_to_html(self.env, context,
              '[attachment:discussion:topic/%s:%s %s]' % (id, name, label))
        elif namespace == 'raw-topic-attachment':
            return format_to_html(self.env, context,
              '[raw-attachment:discussion:topic/%s:%s %s]' % (id, name, label))
        else:
            return tag.a(label, href = formatter.href.discussion('topic', id),
              title = label.replace('"', ''), class_ = 'missing')
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:20,代码来源:wiki.py


示例16: wikipage_to_html

    def wikipage_to_html(self, text, page_name, req):
        """
        Converts a wiki text to HTML, and makes some replacements in order to fix
        internal and external links and references
        """

        self.env.log.debug('WikiPrint => Start function wikipage_to_html')

        #Remove exclude expressions
        for r in EXCLUDE_RES:
            text = r.sub('', text)
        
        #Escape [[PageOutline]], to avoid wiki processing
        for r in [re.compile(r'\[\[TOC(\(.*\))?\]\]'), re.compile(r'\[\[PageOutline(\(.*\))?\]\]')]:
            text = r.sub('![[pdf-toc]]', text)
            
        for macro in self.omit_macros:
            r = re.compile(r'\[\[' + macro + r'\(.*?\]\]')
            text = r.sub('', text)
            r = re.compile(r'^\{\{\{\r?\n#!' + macro + r'\r?\n(^.*\r?\n)*?^\}\}\}', re.MULTILINE)
            text = r.sub('', text)

        link_format = req.args.get('link_format', None)
            
        if self.omit_links:
            r1 = re.compile(r'\[wiki:(.*?) (.*?)\]')
            text = r1.sub('[\g<2>]', text)            
            r2 = re.compile(r'\[wiki:(.*?)\]')
            text = r2.sub('[\g<1>]', text)            
        elif link_format:
            #Keep links to the same export format
            r = re.compile(r'(?<=\[wiki:)(.*?)(?=(?: .*?)?\])')
            text = r.sub('\g<1>?format=%s&link_format=%s' % (link_format, link_format), text)
            
        if self.rebase_links:
            r = re.compile(r'\[wiki:(.*?)\]')
            text = r.sub('[%s/wiki/\g<1>]' % self.rebase_links, text)

        self.env.log.debug('WikiPrint => Wiki input for WikiPrint: %r' % text)
        
        #First create a Context object from the wiki page
        context = Context(Resource('wiki', page_name), req.abs_href, req.perm)
        context.req = req
        
        #Now convert in that context
        page = format_to_html(self.env, context, text)
        self.env.log.debug('WikiPrint => Wiki to HTML output: %r' % page)
        
        self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r' % page)
        self.env.log.debug('WikiPrint => Finish function wikipage_to_html')

        return page
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:52,代码来源:wikiprint.py


示例17: renderWiki

 def renderWiki(self, context, items, convertList):
     '''
     Convert selected wiki fields from the database into html
     Return values to calling application for publishing to the web page. 
     '''
     
     for data_row in items:
         '''
         Index through data row, process select elements of record set.
         '''
         for wikify in convertList:
             data_row[wikify] = format_to_html(self.env, context, data_row[wikify])
     return items
开发者ID:shilanguedangue,项目名称:tracpm,代码行数:13,代码来源:web_ui.py


示例18: wiki2html

 def wiki2html(self, wiki):
     """ The easiest way to convert wiki to html """
     req = Mock(href=Href(self.env.abs_href.base),
                abs_href=self.env.abs_href,
                authname='anonymous',
                perm=MockPerm(),
                args={})
     context = Context.from_request(req, 'wiki')
     try:
         html = format_to_html(self.env, context, wiki).encode('utf8','ignore')
     except AttributeError:
         html = wiki
     return html
开发者ID:getpenelope,项目名称:trac.por,代码行数:13,代码来源:plugins.py


示例19: expand_macro

    def expand_macro(self, formatter, name, txt):
	db = self.env.get_db_cnx()


	txt = txt or ''
	args = txt.split(',')

        # strip off quotes and re markers 
        pagename = args[0].replace('"','')
        pagename = pagename.replace('$','')
        pagename = pagename.replace('^','')

        # get the page
        sql  = "SELECT text from wiki where name = '%s' order by version desc limit 1" % pagename
	cs = db.cursor()
	cs.execute(sql )
	
	row = cs.fetchone()
	if row == None:
		return ''
	text = row[0]

        # put in the heading if a style is provided
        if len(args) == 3:
            return tag.div(class_=args[2])(
                                tag.div(class_=args[1])(pagename),
                                format_to_html(self.env,
                                               formatter.context,
                                               text)
                                )
        if len(args) == 2:
            return tag.div(tag.div(class_=args[1])(pagename),
                           format_to_html(self.env,
                                          formatter.context,
                                          text)
                           )
        else:
            return format_to_html(self.env, formatter.context, text)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:38,代码来源:macro.py


示例20: expand_macro

    def expand_macro(self, formatter, name, txt):

        if txt:
            sourcepage = txt.strip('"')
        else:
            sourcepage = 'Fortune Cookies'

        wikiobj = randomwiki(self.env.get_db_cnx())
        pagelist = wikiobj.getentries(sourcepage,1)
        if pagelist[0]:
            pagelist[0] = pagelist[0].replace('*','')
            return format_to_html(self.env,formatter.context,pagelist[0])
        else:
            return "Quotes not found"
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:14,代码来源:randomquote.py



注:本文中的trac.wiki.formatter.format_to_html函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python formatter.format_to_oneliner函数代码示例发布时间:2022-05-27
下一篇:
Python api.parse_args函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap