From 369fea019b418e941fde7333ca5dd3f40701df6c Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Tue, 21 Sep 2021 13:06:05 +0200 Subject: [PATCH] Add script to reconcile references and anchors --- tools/reconcile_references.py | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tools/reconcile_references.py diff --git a/tools/reconcile_references.py b/tools/reconcile_references.py new file mode 100644 index 0000000..d2fc947 --- /dev/null +++ b/tools/reconcile_references.py @@ -0,0 +1,37 @@ +from __future__ import print_function +import glob +import re + +markup_files = glob.glob('*.asciidoc') +anchor_re = re.compile("\[\[(.*)\]\]") +ref_re = re.compile(".*\<\<([^\>]*)\>\>.") + +refs = [] +anchors = [] +dup_anchors = [] + +for markup_file in markup_files: + markup_f = open(markup_file, 'r') + markup_contents = markup_f.read() + markup_f.close() + for line in markup_contents.splitlines(): + ref_match = ref_re.match(line) + if ref_match: + if ref_match.group(1) not in refs: + refs.append(ref_match.group(1)) + anchor_match = anchor_re.match(line) + if anchor_match: + if anchor_match.group(1) not in anchors: + anchors.append(anchor_match.group(1)) + else: + dup_anchors.append(anchor_match.group(1)) + +print("\nAnchors: ", len(anchors)) +print("\nDuplicated Anchors: ", len(dup_anchors)) +print(dup_anchors) +print("\nReferences: ", len(refs)) +print(refs) +broken_refs = list(set(refs) - set(anchors)) +print("\nBroken references: ", len(broken_refs), broken_refs) +missing_refs = list(set(anchors) - set(refs)) +print("\nUn-referenced Anchors: ", len(missing_refs), missing_refs)