当前位置: 首页>>代码示例>>Python>>正文


Python Markdown.convertFile方法代码示例

本文整理汇总了Python中markdown.Markdown.convertFile方法的典型用法代码示例。如果您正苦于以下问题:Python Markdown.convertFile方法的具体用法?Python Markdown.convertFile怎么用?Python Markdown.convertFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在markdown.Markdown的用法示例。


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

示例1: get_projects

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
def get_projects(listfile):
    with open(listfile,"r") as f:
        project_files = f.read().splitlines()
    global md
    projects = []
    for pf in project_files:
        contents = StringIO()
        md = Markdown(extensions=["extra", "meta"])
        md.convertFile(pf, contents)
        md.Meta["content"] = contents.getvalue()
        projects.append(md.Meta)
    return projects
开发者ID:mhils,项目名称:honeynet-projects,代码行数:14,代码来源:generate.py

示例2: __init__

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
    def __init__(self, request, path, parent=None):
        super(BlogEntry, self).__init__(request, path, parent=parent)
        self.base_name, self.ext = os.path.splitext(path)
        assert self.ext.lower() in self.EXT, " %s is not a markdown file" % path
        m = Markdown(extensions=md_extensions)
        m.Meta = {}
        body = cStringIO.StringIO()
        m.convertFile(input=open(self.path), output=body)
        self.body = body.getvalue()
        body.close()

        for k, v in m.Meta.items():
            setattr(self, k, " ".join(v))
        self.page = BlogPage(request, "%s.html" % self.base_name, self)
开发者ID:twillis,项目名称:diredly,代码行数:16,代码来源:blog.py

示例3: __init__

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
class MDConv:
    md = None
    md_command = None
    conv = None
    block = """<div class="content">
{}
</div>"""

    def __init__(self):
        if Markdown:
            print("Use Markdown python module to convert.")
            self.md = Markdown()
            self.conv = self.conv_py
        else:
            self.md_command = self.check_cmd("markdown.pl") or \
                self.check_cmd("markdown")
            if self.md_command:
                print("Use command {} to convert.".format(self.md_command))
                self.conv = self.conv_pl
        return

    def check_cmd(self, command):
        try:
            check_output([command, "--version"])
            return command
        except OSError:
            return None

    def conv_py(self, input, encoding):
        """accept filename and return result as string"""
        tmp = BytesIO()
        # why encoding is needed while it outputs byte string?
        self.md.convertFile(input = input, output = tmp, encoding = encoding)
        res = tmp.getvalue().decode(encoding)
        tmp.close()
        return self.block.format(res)

    def conv_pl(self, input, encoding):
        """accept filename and return result as string"""
        f = open(file = input, encoding = encoding)
        res = check_output(self.md_command, stdin = f).decode(encoding)
        f.close()
        return self.block.format(res)
开发者ID:10sr,项目名称:script,代码行数:45,代码来源:mdpage.py

示例4: __init__

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
 def __init__(self, post_path):
     self.path = post_path
     md = Markdown(extensions = MKD_EXT, output_format = 'xhtml5')
     buf = StringIO()
     md.convertFile(input = self.path, output = buf)
     self.html = buf.getvalue().decode('utf-8')
     buf.close()
     if 'slug' in md.Meta:
         self.slug = md.Meta['slug'][0]
     else:
         self.slug, _ = splitext(basename(post_path))
     print self.slug
     self.title = md.Meta['title'][0]
     self.ts = parse_date(md.Meta['date'][0])
     self.draft = 'draft' in md.Meta
     self.out_path = self._get_path()
     self.exts = md.Meta.get('exts', [])
     self.scripts = md.Meta.get('scripts', [])
     self.last_updated = os.path.getmtime(post_path)
开发者ID:vasuman,项目名称:glob,代码行数:21,代码来源:generate.py

示例5: main

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
def main():
    generate_pages()
    return
    md = Markdown(extensions=["markdown.extensions.meta"])
    env = Environment(loader=FileSystemLoader(THEME_DIR))
    for root, dirs, files in os.walk(CONTENT_DIR):
        for filename in files:
            fp = os.path.join(root, filename)
            body = md.convertFile(fp)
            context = {"body": body}
            write_file("output/" + filename, env.get_template("detail.html").render(**context))
开发者ID:yxy,项目名称:yblog,代码行数:13,代码来源:engine.py

示例6: load

# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import convertFile [as 别名]
 def load(self):
     path, t = QFileDialog.getOpenFileName()
     markdown = Markdown()
     markdown.serializer = self._loader
     markdown.convertFile(path)
开发者ID:aaronschif,项目名称:sp,代码行数:7,代码来源:__main__.py


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