diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2023-12-13 16:26:31 +0300 |
---|---|---|
committer | Jon Turney <jon.turney@dronecode.org.uk> | 2024-01-05 22:00:15 +0300 |
commit | a9826e13ff7e19a0b446ca22d58d8819ffcabd06 (patch) | |
tree | 2c342cbaa0cb61406600d70f91d554b35a931428 | |
parent | 72a36434339e74676904906db287e720a0b75a0d (diff) |
Improve rendering of minimal Markdown for description in package summary
Retain the heuristic which makes URLs in the description, and improve
it's handling of some cases.
-rwxr-xr-x | calm/pkg2html.py | 21 | ||||
-rw-r--r-- | requirements.txt | 1 | ||||
-rwxr-xr-x | test/testdata/htdocs.expected/summary/openssh-src.html | 4 | ||||
-rw-r--r-- | test/testdata/htdocs.expected/summary/openssh.html | 4 |
4 files changed, 19 insertions, 11 deletions
diff --git a/calm/pkg2html.py b/calm/pkg2html.py index d44b40b..ea4cb8f 100755 --- a/calm/pkg2html.py +++ b/calm/pkg2html.py @@ -52,6 +52,8 @@ import textwrap import time from typing import NamedTuple +import markdown + import xtarfile from . import common_constants @@ -80,13 +82,18 @@ def ldesc(po, bv): return sdesc(po, bv) header = header.strip('"') - # escape html entities - header = html.escape(header, quote=False) - header = header.replace('\n\n', '\n<br>\n') - # try to recognize things which look like bullet points - header = re.sub(r'\n(\s*[*-]\s)', r'<br>\n\1', header) - # linkify things which look like hyperlinks - header = re.sub(r'http(s|)://[^\s\)]*', r'<a href="\g<0>">\g<0></a>', header) + header = markdown.markdown(header) + + # linkify things which look like URLs + def linkify_without_fullstop(m): + url = m.group(0) + suffix = '' + if url[-1] == '.': + suffix = url[-1] + url = url[0:-1] + return '<a href="{0}">{0}</a>{1}'.format(url, suffix) + + header = re.sub(r'http(s|)://[\w./_-]*', linkify_without_fullstop, header) return header diff --git a/requirements.txt b/requirements.txt index b75566e..3cb6f87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ flake8-builtins flake8-import-order license_expression lockfile +markdown pycodestyle python-daemon xtarfile[zstd] diff --git a/test/testdata/htdocs.expected/summary/openssh-src.html b/test/testdata/htdocs.expected/summary/openssh-src.html index 2bf497c..9ac2ab1 100755 --- a/test/testdata/htdocs.expected/summary/openssh-src.html +++ b/test/testdata/htdocs.expected/summary/openssh-src.html @@ -13,8 +13,8 @@ <table class="pkgdetails"> <tr><td><p><span class="detail">summary</span>:</p></td><td><p>The OpenSSH server and client programs</p></td></tr> <tr><td><p><span class="detail">description</span>:</p></td><td><p>OpenSSH is a program for logging into a remote machine and for - executing commands on a remote machine. It can replace rlogin and rsh, - providing encrypted communication between two machines.</p></td></tr> + executing commands on a remote machine. It can replace rlogin and rsh, + providing encrypted communication between two machines.</p></td></tr> <tr><td><p><span class="detail">categories</span>:</p></td><td><p>Net</p></td></tr> <tr><td><p><span class="detail">install package(s)</span>:</p></td><td><p><a href="openssh.html">openssh</a></p></td></tr> <tr><td><p><span class="detail">maintainer(s)</span>:</p></td><td><p>Corinna Vinschen diff --git a/test/testdata/htdocs.expected/summary/openssh.html b/test/testdata/htdocs.expected/summary/openssh.html index a97c3ca..75f3bc2 100644 --- a/test/testdata/htdocs.expected/summary/openssh.html +++ b/test/testdata/htdocs.expected/summary/openssh.html @@ -13,8 +13,8 @@ <table class="pkgdetails"> <tr><td><p><span class="detail">summary</span>:</p></td><td><p>The OpenSSH server and client programs</p></td></tr> <tr><td><p><span class="detail">description</span>:</p></td><td><p>OpenSSH is a program for logging into a remote machine and for - executing commands on a remote machine. It can replace rlogin and rsh, - providing encrypted communication between two machines.</p></td></tr> + executing commands on a remote machine. It can replace rlogin and rsh, + providing encrypted communication between two machines.</p></td></tr> <tr><td><p><span class="detail">categories</span>:</p></td><td><p>Net</p></td></tr> <tr><td><p><span class="detail">rdepends</span>:</p></td><td><p><a href="keychain.html">keychain</a></p></td></tr> <tr><td><p><span class="detail">source package</span>:</p></td><td><p><a href="openssh-src.html">openssh</a></p></td></tr> |