From a9826e13ff7e19a0b446ca22d58d8819ffcabd06 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Wed, 13 Dec 2023 13:26:31 +0000 Subject: 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. --- calm/pkg2html.py | 21 ++++++++++++++------- requirements.txt | 1 + .../htdocs.expected/summary/openssh-src.html | 4 ++-- 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
\n') - # try to recognize things which look like bullet points - header = re.sub(r'\n(\s*[*-]\s)', r'
\n\1', header) - # linkify things which look like hyperlinks - header = re.sub(r'http(s|)://[^\s\)]*', r'\g<0>', 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 '{0}{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 @@ + executing commands on a remote machine. It can replace rlogin and rsh, + providing encrypted communication between two machines.

summary:

The OpenSSH server and client programs

description:

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.

categories:

Net

install package(s):

openssh

maintainer(s):

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 @@ + executing commands on a remote machine. It can replace rlogin and rsh, + providing encrypted communication between two machines.

-- cgit v1.2.3

summary:

The OpenSSH server and client programs

description:

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.

categories:

Net

rdepends:

keychain

source package:

openssh