From ca273947df9da5ba0f6b1f78865cfa1e02d25cea Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 18 Dec 2024 20:34:00 +0100 Subject: [PATCH 1/2] Restore possibility to use anchors --- mk_docs.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mk_docs.py b/mk_docs.py index 25e6f3f..72c040e 100755 --- a/mk_docs.py +++ b/mk_docs.py @@ -27,8 +27,11 @@ def md2html(md_file, html_file, file_name): for a in soup.findAll('a'): if not a['href'].startswith(('http://', 'https://', '#')): - if not a['href'].endswith(('html')): - a['href'] = a['href']+".html" + parts = a['href'].split('#') + if not parts[0].endswith(('html')): + a['href'] = parts[0]+".html" + if (len(parts) > 1): + a['href'] = a['href'] + '#' + parts[1] if (str(a['href']).find(":") > 0): a['href'] = a['href'].replace(":", "/") From dd07dda9ccea90d844e6e5fa56cd21f0f24a9480 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Wed, 18 Dec 2024 20:40:14 +0100 Subject: [PATCH 2/2] Fix indentation + remove lots of excess whitespace --- mk_docs.py | 95 +++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/mk_docs.py b/mk_docs.py index 72c040e..b28a726 100755 --- a/mk_docs.py +++ b/mk_docs.py @@ -18,29 +18,30 @@ # - add header, navigation and footer to the converted file def md2html(md_file, html_file, file_name): print("Transforming " + md_file + " into " + html_file) - + with open(md_file, 'r') as f: text = f.read() html = pymd.convert(text) soup = BeautifulSoup(html, 'html.parser') for a in soup.findAll('a'): - + if not a['href'].startswith(('http://', 'https://', '#')): parts = a['href'].split('#') if not parts[0].endswith(('html')): - a['href'] = parts[0]+".html" - if (len(parts) > 1): - a['href'] = a['href'] + '#' + parts[1] - + a['href'] = parts[0]+".html" + + if (len(parts) > 1): + a['href'] = a['href'] + '#' + parts[1] + if (str(a['href']).find(":") > 0): a['href'] = a['href'].replace(":", "/") - + # TODO: At this point we could use title and description to auto generate a breadcrum or an index #title = soup.find('h1').string #if (len(title.split(":")) > 1): # title = title.split(":")[1] - + #desc = "" #p = soup.find('p') #if not p is None: @@ -51,7 +52,7 @@ def md2html(md_file, html_file, file_name): # search a filesystem directory for subdirs and retum these in a list def getsubdirs(dir_path): - return(glob.glob(dir_path + '*/')) + return(glob.glob(dir_path + '*/')) # search a filesystem directory for markdown (md) files and parse these into html using the md2html function def parsefiles(docsdir, outputdir): @@ -74,22 +75,22 @@ def parsefiles(docsdir, outputdir): # filter out the ones that do not have a ssp module def getmodulerepos(): module_repos = [] - + with urllib.request.urlopen("https://api.github.com/users/simplesamlphp/repos?per_page=100") as url: repos = json.loads(url.read().decode()) - + for repo in repos: a_repo = {"name": [], "description": [], "html_url": [], "short_name": []} - - # we assume all module will have a name that starts with 'simplesamlphp-module-' + + # we assume all module will have a name that starts with 'simplesamlphp-module-' if (repo['name'].find('simplesamlphp-module-') == 0 and not repo['archived']): a_repo['name'] = str(repo['name']) a_repo['description'] = str(repo['description']) a_repo['html_url'] = str(repo['html_url']) a_repo['short_name'] = a_repo['name'].split("-")[2] - module_repos.append(a_repo) - + module_repos.append(a_repo) + return module_repos # clone a specific git repo to a given directory. Optionally fetch specific version @@ -97,15 +98,15 @@ def getmodulerepos(): def getgitrepo(repo, repo_clone_dir, repo_root, version=None): os.makedirs(os.path.join(repo_clone_dir)) os.chdir(repo_clone_dir) - + if (version is None or version == 'devel'): os.system('git clone --depth=1 ' + repo) else: os.system('git clone --depth=1 --branch simplesamlphp-' + version + ' ' + repo) os.chdir(repo_clone_dir + repo_root) - + print("Working in git repo from" + os.getcwd()) - + os.system('git status') # make the header and headerbad div contents for indjection into each documentation page @@ -140,14 +141,14 @@ def mkContentHeader(versions): content += '' content += '
' content += '' - - s = BeautifulSoup(content, 'html.parser') - + + s = BeautifulSoup(content, 'html.parser') + return s.prettify() -# make a navigation structure based on the versions we have doucmentation for +# make a navigation structure based on the versions we have doucmentation for def mkNavigation(versions): - + #content = '