Use ama.parser to create draft previews

This commit is contained in:
Tim Van Baak 2020-03-04 23:03:01 -08:00
parent 626dfc523c
commit b5efe8c361
2 changed files with 9 additions and 3 deletions

View File

@ -42,10 +42,11 @@ function update(article) {
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open("POST", params.updateURL, true); req.open("POST", params.updateURL, true);
req.setRequestHeader("Content-type", "application/json"); req.setRequestHeader("Content-type", "application/json");
req.responseType = "json";
req.onreadystatechange = function () { req.onreadystatechange = function () {
if (req.readyState == 4 && req.status == 200) { if (req.readyState == 4 && req.status == 200) {
params.article = article; // params.article = article;
document.getElementById("preview-control").innerHTML = JSON.stringify(req.response); document.getElementById("preview-control").innerHTML = req.response.rendered;
} }
}; };
req.send(JSON.stringify(article)); req.send(JSON.stringify(article));

View File

@ -8,6 +8,7 @@ from amanuensis.config import root
from amanuensis.config.loader import ReadOnlyOrderedDict from amanuensis.config.loader import ReadOnlyOrderedDict
from amanuensis.errors import MissingConfigError from amanuensis.errors import MissingConfigError
from amanuensis.lexicon.manage import valid_add, add_player, add_character from amanuensis.lexicon.manage import valid_add, add_player, add_character
from amanuensis.parser import parse_raw_markdown, PreviewHtmlRenderer
from amanuensis.server.forms import ( from amanuensis.server.forms import (
LexiconConfigForm, LexiconJoinForm,LexiconCharacterForm) LexiconConfigForm, LexiconJoinForm,LexiconCharacterForm)
from amanuensis.server.helpers import ( from amanuensis.server.helpers import (
@ -236,10 +237,14 @@ def get_bp():
def editor_update(name): def editor_update(name):
article = request.json article = request.json
# TODO verification # TODO verification
parsed_draft = parse_raw_markdown(article['contents'])
rendered_html = parsed_draft.render(PreviewHtmlRenderer())
filename = f'{article["character"]}.{article["aid"]}' filename = f'{article["character"]}.{article["aid"]}'
with g.lexicon.ctx.draft.edit(filename) as a: with g.lexicon.ctx.draft.edit(filename) as a:
a.update(article) a.update(article)
# TODO return more info # TODO return more info
return {'hello': 'world'} return {'rendered': rendered_html}
return bp return bp