GitLab Markdown Wiki Table of Contents
**Note: This is a modification of https://github.com/amaiorano/md-to-toc. All credit for the vast majority of this script goes there.
if len(files) > 0:
level = root.count(os.sep) - base_level
indent = ' ' * level
if root != cwd:
indent = ' ' * (level - 1)
md_lines.append('{0} {2} **{1}/**\n'.format(indent,
os.path.basename(root),
TOC_LIST_PREFIX))
if len(files) > 0:
level = root.count(os.sep) - base_level
indent = ' ' * level
if root != cwd:
indent = ' ' * (level - 1)
md_lines.append('{0} {2} **{1}**\n'.format(indent, # Removed '/' after the {1}
os.path.basename(root),
TOC_LIST_PREFIX))
rel_dir = '.{1}{0}'.format(os.sep, root[base_len:])
for md_filename in files:
indent = ' ' * level
if wikilinks:
md_lines.append('{0} {3} [[{2}{1}]]\n'.format(indent,
os.path.splitext(md_filename)[0],
rel_dir,
TOC_LIST_PREFIX))
else:
md_lines.append('{0} {3} [{1}]({2}{1})\n'.format(indent,
md_filename,
rel_dir,
TOC_LIST_PREFIX))
rel_dir = '.{1}{0}'.format(os.sep, root[base_len:])
for md_filename in files:
indent = ' ' * level
rel_dir = rel_dir.replace('.\\','.') # Remove '.\\' from the front of the file link
rel_dir = rel_dir.replace('\\','/') # Replace '\\' from the file link path with '/'
md_filename = md_filename.replace('.md','') # Remove the '.md' from the file name and link
if wikilinks:
md_lines.append('{0} {3} [[{2}{1}]]\n'.format(indent,
os.path.splitext(md_filename)[0],
rel_dir,
TOC_LIST_PREFIX))
else:
md_lines.append('{0} {3} [{1}]({2}{1})\n'.format(indent,
md_filename,
rel_dir,
TOC_LIST_PREFIX))