Merge pull request #40 from Sagittal-ai/FLAS-67_markdown_in_post_body
FLAS-67: Implement Markdown Support in Blog Post Body
This commit is contained in:
commit
6a07547875
5 changed files with 10 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from flask import Flask, request, g
|
from flask import Flask, request, g
|
||||||
|
import markdown
|
||||||
|
|
||||||
|
|
||||||
def create_app(test_config=None):
|
def create_app(test_config=None):
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from flask import render_template
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from werkzeug.exceptions import abort
|
from werkzeug.exceptions import abort
|
||||||
|
import markdown
|
||||||
|
|
||||||
from .auth import login_required
|
from .auth import login_required
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
|
|
@ -22,6 +23,11 @@ def index():
|
||||||
" FROM post p JOIN user u ON p.author_id = u.id"
|
" FROM post p JOIN user u ON p.author_id = u.id"
|
||||||
" ORDER BY created DESC"
|
" ORDER BY created DESC"
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
# Convert the immutable cursor to a list of dictionaries
|
||||||
|
posts = [dict(post) for post in posts]
|
||||||
|
# Convert markdown to HTML for each post body
|
||||||
|
for post in posts:
|
||||||
|
post['body'] = markdown.markdown(post['body'])
|
||||||
return render_template("blog/index.html", posts=posts)
|
return render_template("blog/index.html", posts=posts)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
<input name="title" id="title" value="{{ request.form['title'] }}" required>
|
<input name="title" id="title" value="{{ request.form['title'] }}" required>
|
||||||
<label for="body">Body</label>
|
<label for="body">Body (Markdown supported)</label>
|
||||||
<textarea name="body" id="body">{{ request.form['body'] }}</textarea>
|
<textarea name="body" id="body">{{ request.form['body'] }}</textarea>
|
||||||
<input type="submit" value="Save">
|
<input type="submit" value="Save">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
<a class="action" href="{{ url_for('blog.update', id=post['id']) }}">Edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</header>
|
</header>
|
||||||
<p class="body">{{ post['body'] }}</p>
|
<p class="body">{{ post['body']|safe }}</p>
|
||||||
</article>
|
</article>
|
||||||
{% if not loop.last %}
|
{% if not loop.last %}
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label for="title">Title</label>
|
<label for="title">Title</label>
|
||||||
<input name="title" id="title" value="{{ request.form['title'] or post['title'] }}" required>
|
<input name="title" id="title" value="{{ request.form['title'] or post['title'] }}" required>
|
||||||
<label for="body">Body</label>
|
<label for="body">Body (Markdown supported)</label>
|
||||||
<textarea name="body" id="body">{{ request.form['body'] or post['body'] }}</textarea>
|
<textarea name="body" id="body">{{ request.form['body'] or post['body'] }}</textarea>
|
||||||
<input type="submit" value="Save">
|
<input type="submit" value="Save">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue