summaryrefslogtreecommitdiffstats
path: root/doc/update-links.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:32:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:32:39 +0000
commit56ae875861ab260b80a030f50c4aff9f9dc8fff0 (patch)
tree531412110fc901a5918c7f7442202804a83cada9 /doc/update-links.py
parentInitial commit. (diff)
downloadicinga2-56ae875861ab260b80a030f50c4aff9f9dc8fff0.tar.xz
icinga2-56ae875861ab260b80a030f50c4aff9f9dc8fff0.zip
Adding upstream version 2.14.2.upstream/2.14.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xdoc/update-links.py41
1 files changed, 41 insertions, 0 deletions
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 <md-files>" % 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"<a id=\"(?P<id>.*?)\">", 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<text>.*?)\]\((?P<file>[0-9-a-z\.]+)?#(?P<id>[^#\)]+)\)", update_anchor, text)
+ open(file, "w").write(new_text)