diff --git a/BUGS.md b/BUGS.md index dfe6096..621bc91 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,10 @@ # BUGS +- fazer renderer para formulas com mathjax serverside (mathjax-node). +- fazer renderer para imagens, com links /file?ref=xpto;name=zzz.jpg +- fazer renderer para linguagem assembly mips? +- converter markdown para mistune. - qual a diferenca entre md_to_html e md_to_html_review, parece desnecessario haver dois. - servir imagens das perguntas - hints nao funciona diff --git a/demo/questions/questions-tutorial.yaml b/demo/questions/questions-tutorial.yaml index 2049520..380cb0d 100644 --- a/demo/questions/questions-tutorial.yaml +++ b/demo/questions/questions-tutorial.yaml @@ -42,7 +42,8 @@ ref: tut-alert type: alert title: alert - text: Texto negativo (alerta). Não conta para avaliação. + text: Texto negativo (alerta). Não conta para avaliação.  + # ---------------------------------------------------------------------------- - ref: tut-radio diff --git a/serve.py b/serve.py index 79d5ee3..34f7ab1 100755 --- a/serve.py +++ b/serve.py @@ -18,7 +18,7 @@ import tornado.httpserver from tornado import template, gen # project -from tools import load_yaml, md_to_html, md_to_html_review +from tools import load_yaml, md_to_html #, md_to_html_review from app import App, AppException @@ -98,7 +98,9 @@ class FileHandler(BaseHandler): def get(self): uid = self.current_user qref = self.get_query_argument('ref') - qfile = self.get_query_argument('filename') + qfile = self.get_query_argument('file') + print(f'FileHandler: ref={ref}, file={file}') + self.write(self.testapp.get_file(ref, filename)) @@ -222,7 +224,7 @@ class ReviewHandler(BaseHandler): else: with f: t = json.load(f) - self.render('review.html', t=t, md=md_to_html_review, templ=self._templates) + self.render('review.html', t=t, md=md_to_html, templ=self._templates) # --- FILE ------------------------------------------------------------- diff --git a/templates/question-checkbox.html b/templates/question-checkbox.html index b4586d8..3a63df1 100644 --- a/templates/question-checkbox.html +++ b/templates/question-checkbox.html @@ -7,7 +7,7 @@ {% for n, opt in enumerate(q['options']) %} - + {% end %} diff --git a/templates/question-radio.html b/templates/question-radio.html index dbcf58d..5688b34 100644 --- a/templates/question-radio.html +++ b/templates/question-radio.html @@ -7,7 +7,7 @@ {% for n, opt in enumerate(q['options']) %} - + {% end %} diff --git a/templates/question.html b/templates/question.html index 734abff..3de1aac 100644 --- a/templates/question.html +++ b/templates/question.html @@ -11,7 +11,7 @@
{mistune.escape(code)}
\n'
+ else:
+ lexer = get_lexer_by_name(lang, stripall=True)
+ formatter = html.HtmlFormatter()
+ return highlight(code, lexer, formatter)
+
+ def image(self, src, title, text):
+ src = 'FIXME' # FIXME
+ return super().image(src, title, text)
+
+renderer = HighlightRenderer(hard_wrap=True)
+markdown = mistune.Markdown(renderer=renderer)
+
+
# ---------------------------------------------------------------------------
# load data from yaml file
# ---------------------------------------------------------------------------
@@ -16,7 +39,7 @@ def load_yaml(filename, default=None):
try:
f = open(path.expanduser(filename), 'r', encoding='utf-8')
except IOError:
- logger.error('Can\'t open file "{}"'.format(filename))
+ logger.error(f'Can\'t open file "{filename}"')
return default
else:
with f:
@@ -29,7 +52,6 @@ def load_yaml(filename, default=None):
# ---------------------------------------------------------------------------
# Runs a script and returns its stdout parsed as yaml, or None on error.
-# Note: requires python 3.5+
# ---------------------------------------------------------------------------
def run_script(script, stdin='', timeout=5):
script = path.expanduser(script)
@@ -42,45 +64,48 @@ def run_script(script, stdin='', timeout=5):
timeout=timeout,
)
except FileNotFoundError:
- logger.error('Script not found: "{0}".'.format(script))
+ logger.error(f'Script "{script}" not found.')
except PermissionError:
- logger.error('Script "{0}" not executable (wrong permissions?).'.format(script))
+ logger.error(f'Script "{script}" not executable. Wrong permissions?')
except subprocess.TimeoutExpired:
- logger.error('Timeout {0}s exceeded while running script "{1}"'.format(timeout, script))
+ logger.error(f'Timeout {timeout}s exceeded while running "{script}".')
else:
if p.returncode != 0:
- logger.error('Script "{0}" returned error code {1}.'.format(script, p.returncode))
+ logger.error(f'Script "{script}" returned error code {p.returncode}.')
else:
try:
output = yaml.load(p.stdout)
except:
- logger.error('Error parsing yaml output of script "{0}"'.format(script))
+ logger.error('Error parsing yaml output of "{script}"')
else:
return output
# ---------------------------------------------------------------------------
-def md_to_html(text, ref=None, files={}):
- if ref is not None:
- # given q['ref'] and q['files'] replaces references to files by a
- # GET to /file?ref=???;name=???
- for k in files:
- text = text.replace(k, '/file?ref={};name={}'.format(ref, k))
- return markdown.markdown(text, extensions=[
- 'markdown.extensions.tables',
- 'markdown.extensions.fenced_code',
- 'markdown.extensions.codehilite',
- 'markdown.extensions.def_list',
- 'markdown.extensions.sane_lists'
- ])
+def md_to_html(text, q=None):
+ return markdown(text)
+
+# def md_to_html(text, ref=None, files={}):
+# if ref is not None:
+# # given q['ref'] and q['files'] replaces references to files by a
+# # GET to /file?ref=???;name=???
+# for k in files:
+# text = text.replace(k, '/file?ref={};name={}'.format(ref, k))
+# return markdown.markdown(text, extensions=[
+# 'markdown.extensions.tables',
+# 'markdown.extensions.fenced_code',
+# 'markdown.extensions.codehilite',
+# 'markdown.extensions.def_list',
+# 'markdown.extensions.sane_lists'
+# ])
# ---------------------------------------------------------------------------
-def md_to_html_review(text, q):
- for k,f in q['files'].items():
- text = text.replace(k, '/absfile?name={}'.format(q['files'][k]))
- return markdown.markdown(text, extensions=[
- 'markdown.extensions.tables',
- 'markdown.extensions.fenced_code',
- 'markdown.extensions.codehilite',
- 'markdown.extensions.def_list',
- 'markdown.extensions.sane_lists'
- ])
+# def md_to_html_review(text, q):
+# for k,f in q['files'].items():
+# text = text.replace(k, '/absfile?name={}'.format(q['files'][k]))
+# return markdown.markdown(text, extensions=[
+# 'markdown.extensions.tables',
+# 'markdown.extensions.fenced_code',
+# 'markdown.extensions.codehilite',
+# 'markdown.extensions.def_list',
+# 'markdown.extensions.sane_lists'
+# ])
--
libgit2 0.21.2