Skip to content

Commit 515781e

Browse files
adi790uuAditya Agarwal
andauthored
Tested the push workflow and made the md files mpx compatible (#1769)
* Tested the push workflow and made the md files mpx compatible * changes to schema.graphql --------- Co-authored-by: Aditya Agarwal <adi790u@Adityas-MacBook-Air.local>
1 parent bd4cb55 commit 515781e

File tree

3 files changed

+94
-5
lines changed

3 files changed

+94
-5
lines changed

.github/workflows/md_to_mpx.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Script to make Markdown files MPX compatible.
3+
This script scans Markdown files and escapes special characters (<, >, {, })
4+
to make them compatible with the MPX standard used in Docusaurus v3.
5+
This script complies with:
6+
1) Pylint
7+
2) Pydocstyle
8+
3) Pycodestyle
9+
4) Flake8
10+
"""
11+
12+
import os
13+
import argparse
14+
import re
15+
16+
def escape_mpx_characters(text):
17+
"""
18+
Escape special characters in a text string for MPX compatibility.
19+
Avoids escaping already escaped characters.
20+
Args:
21+
text: A string containing the text to be processed.
22+
Returns:
23+
A string with special characters (<, >, {, }) escaped, avoiding
24+
double escaping.
25+
"""
26+
# Regular expressions to find unescaped special characters
27+
patterns = {
28+
"<": r"(?<!\\)<",
29+
">": r"(?<!\\)>",
30+
"{": r"(?<!\\){",
31+
"}": r"(?<!\\)}"
32+
}
33+
34+
# Replace unescaped special characters
35+
for char, pattern in patterns.items():
36+
text = re.sub(pattern, f"\\{char}", text)
37+
38+
return text
39+
40+
def process_file(filepath):
41+
"""
42+
Process a single Markdown file for MPX compatibility.
43+
Args:
44+
filepath: The path to the Markdown file to process.
45+
Returns:
46+
None, writes the processed content back to the file only if there are changes.
47+
"""
48+
with open(filepath, 'r', encoding='utf-8') as file:
49+
content = file.read()
50+
51+
# Escape MPX characters
52+
new_content = escape_mpx_characters(content)
53+
54+
# Write the processed content back to the file only if there is a change
55+
if new_content != content:
56+
with open(filepath, 'w', encoding='utf-8') as file:
57+
file.write(new_content)
58+
59+
def main():
60+
"""
61+
Main function to process all Markdown files in a given directory.
62+
Scans for all Markdown files in the specified directory and processes each
63+
one for MPX compatibility.
64+
Args:
65+
None
66+
Returns:
67+
None
68+
"""
69+
parser = argparse.ArgumentParser(description="Make Markdown files MPX compatible.")
70+
parser.add_argument(
71+
"--directory",
72+
type=str,
73+
required=True,
74+
help="Directory containing Markdown files to process."
75+
)
76+
77+
args = parser.parse_args()
78+
79+
# Process each Markdown file in the directory
80+
for root, _, files in os.walk(args.directory):
81+
for file in files:
82+
if file.lower().endswith(".md"):
83+
process_file(os.path.join(root, file))
84+
85+
if __name__ == "__main__":
86+
main()

.github/workflows/push.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ jobs:
108108
npm install typedoc-plugin-markdown
109109
npm i --save-dev @types/node
110110
npx typedoc --entryPoints src --out talawa-api-docs --plugin typedoc-plugin-markdown --theme markdown --entryPointStrategy expand
111+
112+
- name: Make Markdown Files MPX Compatible
113+
run: python3 .github/workflows/md_to_mpx.py --directory talawa-api-docs
111114

112115
- name: Checking doc updated
113116
id: DocUpdated

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Talawa API
2+
23
💬 Join the community on Slack. The link can be found in the `Talawa` [README.md](https://github.com/PalisadoesFoundation/talawa) file.
34

45
[![N|Solid](public/markdown/images/talawa-logo-lite-200x200.png)](https://github.com/PalisadoesFoundation/talawa-api)
@@ -24,11 +25,10 @@ Core features include:
2425

2526
<!-- toc -->
2627

27-
- [Talawa API](#talawa-api)
28-
- [Talawa Components](#talawa-components)
29-
- [Documentation](#documentation)
30-
- [Installation](#installation)
31-
- [Image Upload](#image-upload)
28+
- [Talawa Components](#talawa-components)
29+
- [Documentation](#documentation)
30+
- [Installation](#installation)
31+
- [Image Upload](#image-upload)
3232

3333
<!-- tocstop -->
3434

0 commit comments

Comments
 (0)