From 0915b3ef56dfac3113cce55a59a5765dc94976be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:34:54 +0200 Subject: Adding upstream version 2.13.6. Signed-off-by: Daniel Baumann --- doc/update-links.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 doc/update-links.py (limited to 'doc/update-links.py') diff --git a/doc/update-links.py b/doc/update-links.py new file mode 100755 index 0000000..765d4a0 --- /dev/null +++ b/doc/update-links.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python +# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ + +import os +import sys +import re + +if len(sys.argv) < 2: + print "Syntax: %s " % sys.argv[0] + print "" + print "Updates inter-chapter links in the specified Markdown files." + sys.exit(1) + +anchors = {} + +for file in sys.argv[1:]: + text = open(file).read() + for match in re.finditer(r".*?)\">", text): + id = match.group("id") + + if id in anchors: + print "Error: Anchor '%s' is used multiple times: in %s and %s" % (id, file, anchors[id]) + + anchors[match.group("id")] = file + +def update_anchor(match): + id = match.group("id") + + try: + file = os.path.basename(anchors[id]) + except KeyError: + print "Error: Unmatched anchor: %s" % (id) + file = "" + + return "[%s](%s#%s)" % (match.group("text"), file, id) + +for file in sys.argv[1:]: + text = open(file).read() + print "> Processing file '%s'..." % (file) + new_text = re.sub(r"\[(?P.*?)\]\((?P[0-9-a-z\.]+)?#(?P[^#\)]+)\)", update_anchor, text) + open(file, "w").write(new_text) -- cgit v1.2.3