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

Python md.convert函数代码示例

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

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



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

示例1: test_rel

    def test_rel(self):
        actual = md.convert(u'[[sameAs::heyyou]]')
        expected = u'<p><a class="wikipage" href="/heyyou" itemprop="sameAs">' \
                   u'heyyou</a></p>'
        self.assertEqual(expected, actual)

        actual = md.convert(u'[[birthDate::1979-03-05 BCE]]')
        expected = u'<p><time datetime="1979-03-05 BCE" itemprop="birthDate">' \
                   u'<a class="wikipage" href="/1979_BCE">1979</a>' \
                   u'<span>-</span>' \
                   u'<a class="wikipage" href="/March_5">03-05</a>' \
                   u'<span> BCE</span></time></p>'
        self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:13,代码来源:test_models.py


示例2: validate_new_content

    def validate_new_content(self, base_revision, new_body, user):
        # check metadata
        new_md = PageOperationMixin.parse_metadata(new_body)

        ## prevent self-revoke
        acl_r = new_md.get('read', '')
        acl_r = acl_r.split(',') if acl_r else []
        acl_w = new_md.get('write', '')
        acl_w = acl_w.split(',') if acl_w else []

        if not self.can_read(user, acl_r=acl_r, acl_w=acl_w):
            raise ValueError('Cannot restrict your permission')
        if not self.can_write(user, acl_r=acl_r, acl_w=acl_w):
            raise ValueError('Cannot restrict your permission')

        ## prevent circular-redirection
        try:
            WikiPage._follow_redirect(self, new_md.get(u'redirect'))
        except ValueError as e:
            raise e

        # check data
        new_data = PageOperationMixin.parse_data(self.title, new_body, new_md['schema'])
        if any(type(value) == schema.InvalidProperty for value in new_data.values()):
            raise ValueError('Invalid schema data')

        # check revision
        if self.revision < base_revision:
            raise ValueError('Invalid revision number: %d' % base_revision)

        # check headings
        if not TocGenerator(md.convert(new_body)).validate():
            raise ValueError("Duplicate paths not allowed")

        return new_data, new_md
开发者ID:jangxyz,项目名称:ecogwiki,代码行数:35,代码来源:wiki_page.py


示例3: test_url

    def test_url(self):
        actuals = [
            u'http://x.co',
            u'(http://x.co)',
            u'http://x.co에',
            u'http://x.co?y',
            u'codeRepository::http://x.co',
            u'[email protected]',
            u'[email protected]에',
            u'http://www.youtube.com/watch?v=w5gmK-ZXIMQ',
            u'http://vimeo.com/1747316',
        ]
        expecteds = [
            u'<p><a class="plainurl" href="http://x.co">http://x.co</a></p>',
            u'<p>(<a class="plainurl" href="http://x.co">http://x.co</a>)</p>',
            u'<p><a class="plainurl" href="http://x.co">http://x.co</a>에</p>',
            u'<p><a class="plainurl" href="http://x.co?y">http://x.co?y</a></p>',
            u'<p><a class="plainurl" href="http://x.co" '
            u'itemprop="codeRepository">http://x.co</a></p>',
            u'<p><a class="email" href="mailto:[email protected]">[email protected]</a></p>',
            u'<p><a class="email" href="mailto:[email protected]">[email protected]</a>에</p>',
            u'<p>\n<div class="video youtube">\n<iframe allowfullscreen="true" frameborder="0" height="390" src="http://www.youtube.com/embed/w5gmK-ZXIMQ" width="640"></iframe>\n</div>\n</p>',
            u'<p>\n<div class="video vimeo">\n<iframe allowfullscreen="true" frameborder="0" height="281" src="http://player.vimeo.com/video/1747316" width="500"></iframe>\n</div>\n</p>',
        ]

        for e, a in zip(expecteds, actuals):
            self.assertEqual(e, md.convert(a))
开发者ID:namongk,项目名称:ecogwiki,代码行数:27,代码来源:test_models.py


示例4: test_isbn

 def test_isbn(self):
     actual = md.convert(u"{{isbn::0618680004}}")
     expected = (
         u'<p><a class="isbn" href="http://www.amazon.com/gp/'
         u'product/0618680004" itemprop="isbn">0618680004</a></p>'
     )
     self.assertEqual(expected, actual)
开发者ID:uastory,项目名称:ecogwiki,代码行数:7,代码来源:test_models.py


示例5: test_yyyymmdd_bce

 def test_yyyymmdd_bce(self):
     actual = md.convert(u'[[1979-03-05 BCE]]')
     expected = u'<p><time datetime="1979-03-05 BCE">' \
                u'<a class="wikipage" href="/1979_BCE">1979</a>' \
                u'<span>-</span>' \
                u'<a class="wikipage" href="/March_5">03-05</a>' \
                u'<span> BCE</span></time></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:8,代码来源:test_models.py


示例6: test_yyyyxxxx

 def test_yyyyxxxx(self):
     actual = md.convert(u'[[1979-??-??]]')
     expected = u'<p><time datetime="1979-??-??">' \
                u'<a class="wikipage" href="/1979">1979</a>' \
                u'<span>-</span>' \
                u'<span>??-??</span>' \
                u'</time></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:8,代码来源:test_models.py


示例7: test_isbn_kr

 def test_isbn_kr(self):
     actual = md.convert(u"{{isbn::8936437267}}")
     expected = (
         u'<p><a class="isbn" href="http://www.aladin.co.kr/'
         u"shop/wproduct.aspx?ISBN="
         u'8936437267" itemprop="isbn">8936437267</a></p>'
     )
     self.assertEqual(expected, actual)
开发者ID:uastory,项目名称:ecogwiki,代码行数:8,代码来源:test_models.py


示例8: test_yyyymmxx

 def test_yyyymmxx(self):
     actual = md.convert(u"[[1979-03-??]]")
     expected = (
         u'<p><time datetime="1979-03-??">'
         u'<a class="wikipage" href="/1979">1979</a>'
         u"<span>-</span>"
         u'<a class="wikipage" href="/March">03-??</a>'
         u"</time></p>"
     )
     self.assertEqual(expected, actual)
开发者ID:uastory,项目名称:ecogwiki,代码行数:10,代码来源:test_models.py


示例9: render_body

    def render_body(
        cls, title, body, rendered_data="", inlinks={}, related_links_by_score={}, older_title=None, newer_title=None
    ):
        # body
        body_parts = [cls.remove_metadata(body)]

        # incoming links
        if len(inlinks) > 0:
            lines = [u"# Incoming Links"]
            for i, (rel, links) in enumerate(inlinks.items()):
                itemtype, rel = rel.split("/")
                lines.append(
                    u'## %s <span class="hidden">(%s %d)</span>'
                    % (schema.humane_property(itemtype, rel, True), itemtype, i)
                )
                # remove dups and sort
                links = list(set(links))
                links.sort()

                lines += [u"* [[%s]]" % t for t in links]
            body_parts.append(u"\n".join(lines))

        # related links
        related_links = related_links_by_score
        if len(related_links) > 0:
            lines = [u"# Suggested Pages"]
            lines += [u"* {{.score::%.3f}} [[%s]]\n{.noli}" % (score, t) for t, score in related_links.items()[:10]]
            body_parts.append(u"\n".join(lines))
            body_parts.append(u"* [More suggestions...](/+%s)\n{.more-suggestions}" % (cls.title_to_path(title)))

        # other posts
        if older_title or newer_title:
            lines = [u"# Other Posts"]
            if newer_title:
                lines.append(u"* {{.newer::newer}} [[%s]]\n{.noli}" % newer_title)
            if older_title:
                lines.append(u"* {{.older::older}} [[%s]]\n{.noli}" % older_title)
            body_parts.append(u"\n".join(lines))

        # remove yaml/schema block
        joined = u"\n".join(body_parts)
        joined = re.sub(PageOperationMixin.re_yaml_schema, u"\n", joined)

        # render to html
        rendered = md.convert(joined)

        # add table of contents
        rendered = TocGenerator(rendered).add_toc()

        # add class for embedded image
        rendered = PageOperationMixin.re_img.sub(ur'<\1 class="img-container"><img\2/></\3>', rendered)

        # add structured data block
        rendered = rendered_data + rendered
        return cls.sanitize_html(rendered)
开发者ID:gcmcom,项目名称:ecogwiki,代码行数:55,代码来源:page_operation_mixin.py


示例10: render_body

    def render_body(cls, body, rendered_data='', inlinks={}, related_links_by_score={}, older_title=None, newer_title=None):
        # body
        body_parts = [cls.remove_metadata(body)]

        # incoming links
        if len(inlinks) > 0:
            lines = [u'# Incoming Links']
            for rel, links in inlinks.items():
                itemtype, rel = rel.split('/')
                lines.append(u'## %s' % schema.humane_property(itemtype, rel, True))
                # remove dups and sort
                links = list(set(links))
                links.sort()

                lines += [u'* [[%s]]' % title for title in links]
            body_parts.append(u'\n'.join(lines))

        # related links
        related_links = related_links_by_score
        if len(related_links) > 0:
            lines = [u'# Suggested Pages']
            lines += [u'* {{.score::%.3f}} [[%s]]\n{.noli}' % (score, title)
                      for title, score in related_links.items()[:10]]
            body_parts.append(u'\n'.join(lines))

        # other posts
        if older_title or newer_title:
            lines = [u'# Other Posts']
            if newer_title:
                lines.append(u'* {{.newer::newer}} [[%s]]\n{.noli}' % newer_title)
            if older_title:
                lines.append(u'* {{.older::older}} [[%s]]\n{.noli}' % older_title)
            body_parts.append(u'\n'.join(lines))

        # remove yaml/schema block
        joined = u'\n'.join(body_parts)
        joined = re.sub(PageOperationMixin.re_yaml_schema, u'\n', joined)

        # render to html
        rendered = md.convert(joined)

        # add table of contents
        rendered = TocGenerator(rendered).add_toc()

        # add class for embedded image
        rendered = PageOperationMixin.re_img.sub(ur'<\1 class="img-container"><img\2/></\3>', rendered)

        # add structured data block
        rendered = rendered_data + rendered

        return cls.sanitize_html(rendered)
开发者ID:jangxyz,项目名称:ecogwiki,代码行数:51,代码来源:page_operation_mixin.py


示例11: test_url

 def test_url(self):
     actuals = [
         u"http://x.co",
         u"(http://x.co)",
         u"http://x.co에",
         u"http://x.co?y",
         u"codeRepository::http://x.co",
         u"[email protected]",
         u"[email protected]에",
     ]
     expecteds = [
         u'<p><a class="plainurl" href="http://x.co">http://x.co</a></p>',
         u'<p>(<a class="plainurl" href="http://x.co">http://x.co</a>)</p>',
         u'<p><a class="plainurl" href="http://x.co">http://x.co</a>에</p>',
         u'<p><a class="plainurl" href="http://x.co?y">http://x.co?y</a></p>',
         u'<p><a class="plainurl" href="http://x.co" ' u'itemprop="codeRepository">http://x.co</a></p>',
         u'<p><a class="email" href="mailto:[email protected]">[email protected]</a></p>',
         u'<p><a class="email" href="mailto:[email protected]">[email protected]</a>에</p>',
     ]
     for e, a in zip(expecteds, actuals):
         self.assertEqual(e, md.convert(a))
开发者ID:uastory,项目名称:ecogwiki,代码行数:21,代码来源:test_models.py


示例12: test_plain

 def test_plain(self):
     actual = md.convert(u'[[heyyou]]')
     expected = u'<p><a class="wikipage" href="/heyyou">heyyou</a></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例13: test_possible_conflict_with_plain_link

 def test_possible_conflict_with_plain_link(self):
     actual = md.convert(u'[[Hello]](there)')
     expected = u'<p><a class="wikipage" href="/Hello">Hello</a>(there)</p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例14: test_unicode_character

 def test_unicode_character(self):
     actual = md.convert(u'[[가]]')
     expected = u'<p><a class="wikipage" href="/%EA%B0%80">가</a></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例15: test_generic_key_value

 def test_generic_key_value(self):
     actual = md.convert(u'{{hello::world from ak}}')
     expected = u'<p><span itemprop="hello">world from ak</span></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例16: test_div

 def test_div(self):
     actual = md.convert(u'<div class="test">He*l*lo</div>\nWo*r*ld')
     expected = u'<div class="test">He*l*lo</div>\n\n<p>Wo<em>r</em>ld</p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例17: test_strikethrough

 def test_strikethrough(self):
     actual = md.convert(u'Hello ~~AK~~?')
     expected = u'<p>Hello <strike>AK</strike>?</p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例18: test_isbn13_kr

 def test_isbn13_kr(self):
     actual = md.convert(u'{{isbn::9788936437267}}')
     expected = u'<p><a class="isbn" href="http://www.aladin.co.kr/' \
                u'shop/wproduct.aspx?ISBN=' \
                u'9788936437267" itemprop="isbn">9788936437267</a></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:6,代码来源:test_models.py


示例19: test_space

 def test_space(self):
     actual = md.convert(u'[[Hey you]]')
     expected = u'<p><a class="wikipage" href="/Hey_you">Hey you</a></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py


示例20: test_class

 def test_class(self):
     actual = md.convert(u'{{.hello::world from ak}}')
     expected = u'<p><span class="hello">world from ak</span></p>'
     self.assertEqual(expected, actual)
开发者ID:namongk,项目名称:ecogwiki,代码行数:4,代码来源:test_models.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python media.Media类代码示例发布时间:2022-05-27
下一篇:
Python match.Match类代码示例发布时间: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