• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/python3
2#
3# Copyright 2020-2021 The Khronos Group Inc.
4#
5# SPDX-License-Identifier: Apache-2.0
6
7# Script that adds href to <a> anchors
8
9import os,sys,re
10
11def genAnchorLinks(in_file, out_file):
12        try:
13                with open(in_file, 'r', encoding='utf8') as f: data = f.read()
14        except FileNotFoundError:
15                print('Error: File %s does not exist.' % in_file)
16                sys.exit(2)
17
18        data = re.sub( r'(<a )(id="(VUID\-[\w\-:]+)")(>)', '\g<1>\g<2> href="#\g<3>"\g<4>', data)
19        with open(out_file, 'w', encoding='utf8') as f: data = f.write(data)
20
21if __name__ == '__main__':
22        if len(sys.argv) != 3:
23                print('Error: genanchorlinks.py requires two arguments.')
24                print('Usage: genanchorlinks.py infile.html outfile.html')
25                sys.exit(1)
26        genAnchorLinks(sys.argv[1], sys.argv[2])
27