{"".join(span.recurse(self))}
' + + def SignatureParagraph(self, span: SignatureParagraph): + return ( + '' + f'{"".join(span.recurse(self))}' + '
' + ) + + def BoldSpan(self, span: BoldSpan): + return f'{"".join(span.recurse(self))}' + + def ItalicSpan(self, span: ItalicSpan): + return f'{"".join(span.recurse(self))}' + + def CitationSpan(self, span: CitationSpan): + return "".join(span.recurse(self)) + + +def render_post_body(post: Post) -> str: + """Parse and render the body of a post into post-safe HTML.""" + renderable: ParsedArticle = parse_raw_markdown(post.body) + rendered: str = renderable.render(PostFormatter()) + return rendered + + +@bp.get("/") +@lexicon_param +@player_required +def list(lexicon_name): + form = CreatePostForm() + return render_template( + "posts.jinja", + lexicon_name=lexicon_name, + form=form, + render_post_body=render_post_body, + ) + + +@bp.post("/") +@lexicon_param +@player_required +def create(lexicon_name): + form = CreatePostForm() + if form.validate(): + # Data is valid + postq.create(g.db, current_lexicon.id, current_user.id, form.body.data) + return redirect(url_for("lexicon.posts.list", lexicon_name=lexicon_name)) + + else: + # POST received invalid data + return render_template( + "posts.jinja", + lexicon_name=lexicon_name, + form=form, + render_post_body=render_post_body, + ) diff --git a/amanuensis/server/lexicon/posts/forms.py b/amanuensis/server/lexicon/posts/forms.py new file mode 100644 index 0000000..76ebd83 --- /dev/null +++ b/amanuensis/server/lexicon/posts/forms.py @@ -0,0 +1,10 @@ +from flask_wtf import FlaskForm +from wtforms import SubmitField, TextAreaField +from wtforms.validators import DataRequired + + +class CreatePostForm(FlaskForm): + """/lexicon/{{ render_post_body(post) }}
+ +