From b5efe8c361c3d6b96894fec0620589b2e96d7141 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 4 Mar 2020 23:03:01 -0800 Subject: [PATCH] Use ama.parser to create draft previews --- amanuensis/resources/editor.js | 5 +++-- amanuensis/server/lexicon.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/amanuensis/resources/editor.js b/amanuensis/resources/editor.js index 64eb3f7..0cba693 100644 --- a/amanuensis/resources/editor.js +++ b/amanuensis/resources/editor.js @@ -42,10 +42,11 @@ function update(article) { var req = new XMLHttpRequest(); req.open("POST", params.updateURL, true); req.setRequestHeader("Content-type", "application/json"); + req.responseType = "json"; req.onreadystatechange = function () { if (req.readyState == 4 && req.status == 200) { - params.article = article; - document.getElementById("preview-control").innerHTML = JSON.stringify(req.response); + // params.article = article; + document.getElementById("preview-control").innerHTML = req.response.rendered; } }; req.send(JSON.stringify(article)); diff --git a/amanuensis/server/lexicon.py b/amanuensis/server/lexicon.py index 3058194..f8fbe6f 100644 --- a/amanuensis/server/lexicon.py +++ b/amanuensis/server/lexicon.py @@ -8,6 +8,7 @@ from amanuensis.config import root from amanuensis.config.loader import ReadOnlyOrderedDict from amanuensis.errors import MissingConfigError from amanuensis.lexicon.manage import valid_add, add_player, add_character +from amanuensis.parser import parse_raw_markdown, PreviewHtmlRenderer from amanuensis.server.forms import ( LexiconConfigForm, LexiconJoinForm,LexiconCharacterForm) from amanuensis.server.helpers import ( @@ -236,10 +237,14 @@ def get_bp(): def editor_update(name): article = request.json # TODO verification + parsed_draft = parse_raw_markdown(article['contents']) + rendered_html = parsed_draft.render(PreviewHtmlRenderer()) + filename = f'{article["character"]}.{article["aid"]}' with g.lexicon.ctx.draft.edit(filename) as a: a.update(article) + # TODO return more info - return {'hello': 'world'} + return {'rendered': rendered_html} return bp