mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Support Markdown syntax in package comments. Among other things, this makes it easier to paste command line output and patches. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
37 lines
841 B
Python
Executable file
37 lines
841 B
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import bleach
|
|
import markdown
|
|
|
|
import aurweb.db
|
|
|
|
|
|
def get_comment(conn, commentid):
|
|
cur = conn.execute('SELECT Comments FROM PackageComments WHERE ID = ?',
|
|
[commentid])
|
|
return cur.fetchone()[0]
|
|
|
|
|
|
def save_rendered_comment(conn, commentid, html):
|
|
conn.execute('UPDATE PackageComments SET RenderedComment = ? WHERE ID = ?',
|
|
[html, commentid])
|
|
|
|
|
|
def main():
|
|
commentid = int(sys.argv[1])
|
|
|
|
conn = aurweb.db.Connection()
|
|
|
|
text = get_comment(conn, commentid)
|
|
html = markdown.markdown(text, extensions=['nl2br'])
|
|
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + ['p', 'br']
|
|
html = bleach.clean(html, tags=allowed_tags)
|
|
save_rendered_comment(conn, commentid, html)
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|