-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update markdown links from inline to reference (footnote) style (…
…#1116) * Clean up links in contributing * done: CONTRIBUTING.md * done: INSTALL.md * done: User-Mantual-For-Project-Managers.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Moving script file to a new directory * move new script file to a new directory * deleted superfluous XINSTALL copy.md --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
60399ca
commit 512b130
Showing
4 changed files
with
163 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import re | ||
|
||
this_file_in_docs = "User-Manual-For-Project-Managers.md" | ||
|
||
|
||
def reformat_links_as_refs(file_name: str) -> None: | ||
""" | ||
Function takes in a mark down file, searches for inline links and changes them to reference (footnote) version. | ||
NB the path to "docs" is hardcoded. | ||
NB: Care should be taken to make sure that inline url links are formatted correctly (broken lines, spaces, parenthesis, etc.) | ||
function created by contributor @cordovez. | ||
""" | ||
pattern = r"\[([^\]]+)\]\(([^)]+)\)" | ||
|
||
# Read the original markdown document | ||
with open(f"./docs/{this_file_in_docs}", "r") as file: | ||
lines = file.readlines() | ||
|
||
# Create a list to store the footnotes | ||
footnotes = [] | ||
|
||
# Create a new list to store the modified lines | ||
modified_lines = [] | ||
|
||
# Iterate through each line in the document | ||
for line in lines: | ||
# Find all matches of the pattern in the line | ||
matches = re.findall(pattern, line) | ||
|
||
# Iterate through the matches in reverse order | ||
for match in reversed(matches): | ||
label = match[0] | ||
url = match[1] | ||
|
||
# Generate the footnote reference | ||
footnote_ref = f"[{label}][{len(footnotes) + 1}]" | ||
|
||
# Replace the original hyperlink with the footnote reference | ||
line = line.replace(f"[{label}]({url})", footnote_ref) | ||
|
||
# Append the footnote to the list | ||
footnotes.append(f'[{len(footnotes) + 1}]: {url} "{label}"') | ||
|
||
# Append the modified line to the new list | ||
modified_lines.append(line) | ||
|
||
# Write the modified lines to the new document | ||
with open(f"./docs/{this_file_in_docs}", "w") as file: | ||
file.writelines(modified_lines) | ||
|
||
# Append the footnotes to the end of the document | ||
with open(f"./docs/{this_file_in_docs}", "a") as file: | ||
file.write("\n\n") | ||
file.write("\n".join(footnotes)) | ||
|
||
|
||
if __name__ == "__main__": | ||
reformat_links_as_refs(this_file_in_docs) |
Oops, something went wrong.