mdown.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:markdown-xblock 作者: hastexo 项目源码 文件源码
def student_view(self, context=None):
        """
        The student view of the MarkdownXBlock.

        """
        if self.filename:
            # These can only be imported when the XBlock is running on the LMS
            # or CMS.  Do it at runtime so that the workbench is usable for
            # regular XML content.
            from xmodule.contentstore.content import StaticContent
            from xmodule.contentstore.django import contentstore
            from xmodule.exceptions import NotFoundError
            from opaque_keys import InvalidKeyError
            try:
                course_id = self.xmodule_runtime.course_id
                loc = StaticContent.compute_location(course_id, self.filename)
                asset = contentstore().find(loc)
                content = asset.data
            except (NotFoundError, InvalidKeyError):
                pass
        else:
            content = self.content

        html_content = ""
        if content:
            html_content = markdown2.markdown(content, extras=self.extras)

        # Render the HTML template
        context = {'content': html_content}
        html = loader.render_template('templates/main.html', context)
        frag = Fragment(html)

        if "fenced-code-blocks" in self.extras:
            frag.add_css_url(self.runtime.local_resource_url(self, 'public/css/pygments.css'))

        return frag
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号