python类markdown()的实例源码

__init__.py 文件源码 项目:website 作者: hackerspace-ntnu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, article, preview=False, *args, **kwargs):
        kwargs = settings.MARKDOWN_KWARGS
        kwargs['extensions'] = self.get_markdown_extensions()
        markdown.Markdown.__init__(self, *args, **kwargs)
        self.article = article
        self.preview = preview
test_markdown.py 文件源码 项目:website 作者: hackerspace-ntnu 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def setUp(self):
        self.md = markdown.Markdown(extensions=[
            'extra',
            ResponsiveTableExtension()
        ])
        self.md_without = markdown.Markdown(extensions=['extra'])
core.py 文件源码 项目:pipesicle 作者: anqurvanillapy 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load_posts(self, fpath=None):
        """\
            - Load valid posts from source directory
            - Convert the text to extract the HTML data, metas and filenames
            - Returns a list of tuples that store the above information
        """
        if fpath == None:
            fpath = self.ifpath

        if path.exists(fpath):
            posts = []

            for f in [fpath] if path.isfile(fpath) \
                             else list(map(lambda x: path.join(fpath, x),
                                           listdir(fpath))):
                if path.splitext(f)[1] in self._md_exts:
                    with codecs.open(f, 'r', encoding='utf-8') as fh:
                        md = Markdown(extensions=self.pymd_exts)
                        html = BeautifulSoup(md.convert(fh.read()), 'lxml')

                        if html.html:
                            # Remove html and body tags
                            html.html.hidden = True
                            html.body.hidden = True
                            meta = md.Meta

                            if not meta.get('type'):
                                meta['type'] = [self.default_post_type]

                            posts.append((html, meta, f))

            if not posts:
                print('warning: Nothing to publish')
            return posts
        else:
            raise OSError(errno.ENOENT, strerror(errno.ENOENT), fpath)
inline_list.py 文件源码 项目:markdown-extension-hbfm 作者: heartbeatsjp 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run(self, lines):
        HEADER_REGEX = re.compile('\{\{inline\(list\)::\n(.*?)\n\}\}', re.DOTALL)  # maybe too much sensitive

        def replace(m):
            text = m.groups()[0]
            md = Markdown()
            table = md.convert(text).replace("\n", "")
            return table

        new_lines = HEADER_REGEX.sub(replace, "\n".join(lines))
        return new_lines.split("\n")
md_editor.py 文件源码 项目:md_editor 作者: kghch 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def post(self):
        raw_text = self.request.body
        unicode_raw_text = unicode(raw_text, "utf-8")
        md = markdown.Markdown(extensions=MARKDOWN_EXT)
        html_text = md.reset().convert(unicode_raw_text)

        # ??????
        def convert_checkbox1(match):
            return '<li><input type="checkbox" disabled>' if match.group('checked') == ' ' \
                else '<li><input type="checkbox" disabled checked>'

        def convert_checkbox2(match):
            return '<li>\n<p><input type="checkbox" disabled>' if match.group('checked') == ' ' \
                else '<li>\n<p><input type="checkbox" disabled checked>'

        # ??img out link
        def convert_src(match):
            return 'src="' + match.group('src') + '"'

        def filter_xss(match):
            return ' '

        pattern_actions = {xss_pattern1: filter_xss,
                        xss_pattern2: filter_xss,
                        checked_pattern1: convert_checkbox1,
                        checked_pattern2: convert_checkbox2,
                        src_pattern: convert_src}
        for pattern, action in pattern_actions.items():
            html_text = re.sub(pattern, action, html_text)

        self.write(html_text)
test_pinyin_markdown.py 文件源码 项目:pinyin_markdown 作者: bcaller 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def pinyin_markdown(request):
    return Markdown(extensions=[request.param])
test_pinyin_markdown.py 文件源码 项目:pinyin_markdown 作者: bcaller 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def pinyin_md_no_classes():
    return Markdown(extensions=['pinyin_markdown(tone_class=,erhua_class=,apostrophe_class=)'])
test_pinyin_markdown.py 文件源码 项目:pinyin_markdown 作者: bcaller 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def pinyin_md_entities():
    return Markdown(extensions=['pinyin_markdown(entities=True)'])
markdown_parser.py 文件源码 项目:BlogReworkPro 作者: dtysky 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self):
        self._extensions = [
            'codehilite(css_class=highlight)',
            'markdown.extensions.tables'
        ]
        self._parser = Markdown(
            extensions=self._extensions
        )
tools.py 文件源码 项目:django-blog 作者: liuenyan 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def convert_to_html(markdown_text):
    md = markdown.Markdown(
        extensions=[
            'pymdownx.github',
            'markdown.extensions.toc',
        ],
        extension_configs={
            'markdown.extensions.toc':
            {
                'title': '??',
            },
        },
        output_format="html5"
    )
    return md.convert(markdown_text)


问题


面经


文章

微信
公众号

扫码关注公众号