|
| 1 | +import markdown, re |
| 2 | + |
| 3 | +test_md = """ |
| 4 | +## Description |
| 5 | +[Provide a brief description of the feature, including why it is needed and what it will accomplish. You can skip any of Goals, Expected Outcome, Implementation Details, Mockups / Wireframes if they are irrelevant] |
| 6 | +
|
| 7 | +## Goals |
| 8 | +- [ ] [Goal 1] |
| 9 | +- [ ] [Goal 2] |
| 10 | +- [ ] [Goal 3] |
| 11 | +- [ ] [Goal 4] |
| 12 | +- [ ] [Goal 5] |
| 13 | +
|
| 14 | +## Expected Outcome |
| 15 | +[Describe in detail what the final product or result should look like and how it should behave.] |
| 16 | +
|
| 17 | +## Acceptance Criteria |
| 18 | +- [ ] [Criteria 1] |
| 19 | +- [ ] [Criteria 2] |
| 20 | +- [ ] [Criteria 3] |
| 21 | +- [ ] [Criteria 4] |
| 22 | +- [ ] [Criteria 5] |
| 23 | +
|
| 24 | +## Implementation Details |
| 25 | +[List any technical details about the proposed implementation, including any specific technologies that will be used.] |
| 26 | +
|
| 27 | +## Mockups / Wireframes |
| 28 | +[Include links to any visual aids, mockups, wireframes, or diagrams that help illustrate what the final product should look like. This is not always necessary, but can be very helpful in many cases.] |
| 29 | +
|
| 30 | +--- |
| 31 | +
|
| 32 | +### Project |
| 33 | +[Project Name] |
| 34 | +
|
| 35 | +### Organization Name: |
| 36 | +[Organization Name] |
| 37 | +
|
| 38 | +### Domain |
| 39 | +[Area of governance] |
| 40 | +
|
| 41 | +### Tech Skills Needed: |
| 42 | +[Required technical skills for the project] |
| 43 | +
|
| 44 | +### Mentor(s) |
| 45 | +[@Mentor1] [@Mentor2] [@Mentor3] |
| 46 | +
|
| 47 | +### Complexity |
| 48 | +Pick one of [High]/[Medium]/[Low] |
| 49 | +
|
| 50 | +### Category |
| 51 | +Pick one or more of [CI/CD], [Integrations], [Performance Improvement], [Security], [UI/UX/Design], [Bug], [Feature], [Documentation], [Deployment], [Test], [PoC] |
| 52 | +
|
| 53 | +### Sub Category |
| 54 | +Pick one or more of [API], [Database], [Analytics], [Refactoring], [Data Science], [Machine Learning], [Accessibility], [Internationalization], [Localization], [Frontend], [Backend], [Mobile], [SEO], [Configuration], [Deprecation], [Breaking Change], [Maintenance], [Support], [Question], [Technical Debt], [Beginner friendly], [Research], [Reproducible], [Needs Reproduction]. |
| 55 | +
|
| 56 | +
|
| 57 | +""" |
| 58 | + |
| 59 | +class MarkdownHandler: |
| 60 | + def __init__(self) -> None: |
| 61 | + return |
| 62 | + |
| 63 | + def markdownParser(self, markdown_content): |
| 64 | + |
| 65 | + #Taking metadata |
| 66 | + markdown_metadata = markdown_content.split('---')[1] |
| 67 | + |
| 68 | + # Parse Markdown to HTML |
| 69 | + html = markdown.markdown(markdown_metadata) |
| 70 | + # print("-------METADATA----------") |
| 71 | + |
| 72 | + # Split HTML into sections using heading tags as delimiters |
| 73 | + sections = re.split("</h3>|<h3>", html) |
| 74 | + while '' in sections: |
| 75 | + sections.remove('') |
| 76 | + # print("------SECTIONS---------") |
| 77 | + for section in sections: |
| 78 | + # print(sections, section) |
| 79 | + section.strip() |
| 80 | + section = re.split("<p>|</p>", section) |
| 81 | + # Define regex pattern to match '\n', ':', and any html tags'<>' |
| 82 | + pattern = re.compile(r'[\n]|[:]|<(.*?)>') |
| 83 | + |
| 84 | + # Remove matching substrings from each string |
| 85 | + clean_sections = [re.sub(pattern, '', s) for s in sections] |
| 86 | + |
| 87 | + # Initialize dictionary |
| 88 | + markdown_dict = {} |
| 89 | + for i in range(0,len(clean_sections), 2): |
| 90 | + markdown_dict[clean_sections[i]] = clean_sections[i+1] |
| 91 | + return markdown_dict |
| 92 | + |
| 93 | + def markdownMetadataValidator(self, markdown_dict): |
| 94 | + required_headings = ["Project", "Organization Name", "Domain", "Tech Skills Needed", "Mentor(s)", "Complexity", "Category", "Sub Category"] |
| 95 | + missing_headings=[] |
| 96 | + for heading in required_headings: |
| 97 | + if heading not in markdown_dict.keys(): |
| 98 | + missing_headings.append(heading) |
| 99 | + |
| 100 | + return missing_headings |
| 101 | + |
| 102 | + |
0 commit comments