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
评论列表
文章目录