From 09dac2bad71206c8ec4a0fe04c734e01d7876066 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Fri, 4 Oct 2024 17:38:06 +0900 Subject: Quote URL in atom:id --- atom-encode-ids | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 atom-encode-ids (limited to 'atom-encode-ids') diff --git a/atom-encode-ids b/atom-encode-ids new file mode 100755 index 0000000..79ac509 --- /dev/null +++ b/atom-encode-ids @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +import re +from urllib.parse import quote +from sys import stdin, stdout + +ID_LINE = re.compile(r'(?P +)(?P.+)(?P)\n') + + +def encode_id(line: str) -> str: + match = re.fullmatch(ID_LINE, line) + if match is None: return line + return '{open}{iri}{close}\n'.format(iri=quote(match.group('url'), ':/#'), + **match.groupdict()) + + +stdout.writelines(map(encode_id, stdin.readlines())) -- cgit 1.4.1