diff options
author | Lukas Fleischer <lfleischer@archlinux.org> | 2017-04-26 06:37:31 +0200 |
---|---|---|
committer | Lukas Fleischer <lfleischer@archlinux.org> | 2017-04-26 06:43:12 +0200 |
commit | e4dcd913d15d813cc227df90a8129d1c3685ea07 (patch) | |
tree | a53a78b4f8f8836f9e44ad8089dc865e74cd06ff /aurweb | |
parent | dec9077339b4cb280430a98204df97ca84bac784 (diff) | |
download | aur-e4dcd913d15d813cc227df90a8129d1c3685ea07.tar.gz aur-e4dcd913d15d813cc227df90a8129d1c3685ea07.tar.xz |
Support headings in package comments
Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'aurweb')
-rwxr-xr-x | aurweb/scripts/rendercomment.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/aurweb/scripts/rendercomment.py b/aurweb/scripts/rendercomment.py index f32c8274..9c0aa6a3 100755 --- a/aurweb/scripts/rendercomment.py +++ b/aurweb/scripts/rendercomment.py @@ -67,6 +67,20 @@ class GitCommitsExtension(markdown.extensions.Extension): md.preprocessors.add('git-commits', preprocessor, '_end') +class HeadingTreeprocessor(markdown.treeprocessors.Treeprocessor): + def run(self, doc): + for elem in doc: + if elem.tag == 'h1': + elem.tag = 'h5' + elif elem.tag in ['h2', 'h3', 'h4', 'h5']: + elem.tag = 'h6' + + +class HeadingExtension(markdown.extensions.Extension): + def extendMarkdown(self, md, md_globals): + md.treeprocessors.add('heading', HeadingTreeprocessor(md), '_end') + + def get_comment(conn, commentid): cur = conn.execute('SELECT PackageComments.Comments, PackageBases.Name ' 'FROM PackageComments INNER JOIN PackageBases ' @@ -88,8 +102,10 @@ def main(): text, pkgbase = get_comment(conn, commentid) html = markdown.markdown(text, extensions=['fenced_code', LinkifyExtension(), - GitCommitsExtension(pkgbase)]) - allowed_tags = bleach.sanitizer.ALLOWED_TAGS + ['p', 'pre'] + GitCommitsExtension(pkgbase), + HeadingExtension()]) + allowed_tags = bleach.sanitizer.ALLOWED_TAGS + \ + ['p', 'pre', 'h4', 'h5', 'h6'] html = bleach.clean(html, tags=allowed_tags) save_rendered_comment(conn, commentid, html) |