Markdown-Checker 0.0.9__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {markdown-checker-0.0.9/markdown_checker.egg-info → markdown-checker-0.1.1}/PKG-INFO +49 -1
  2. markdown-checker-0.1.1/README.md +64 -0
  3. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/check_markdown.py +41 -12
  4. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/generators/md_generator.py +26 -5
  5. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/inputs/input_arguments.py +38 -16
  6. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/links/link_operations.py +61 -19
  7. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/paths/files_paths_reader.py +1 -0
  8. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/validate_markdown.py +25 -9
  9. {markdown-checker-0.0.9 → markdown-checker-0.1.1/markdown_checker.egg-info}/PKG-INFO +49 -1
  10. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker.egg-info/SOURCES.txt +1 -0
  11. markdown-checker-0.1.1/markdown_checker.egg-info/requires.txt +1 -0
  12. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/setup.cfg +3 -1
  13. markdown-checker-0.1.1/tests/test_markdown_checker.py +127 -0
  14. markdown-checker-0.0.9/README.md +0 -17
  15. markdown-checker-0.0.9/tests/test_markdown_checker.py +0 -46
  16. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/LICENSE +0 -0
  17. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/MANIFEST.in +0 -0
  18. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/__init__.py +0 -0
  19. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/generators/__init__.py +0 -0
  20. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/inputs/__init__.py +0 -0
  21. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/links/__init__.py +0 -0
  22. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker/paths/__init__.py +0 -0
  23. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker.egg-info/dependency_links.txt +0 -0
  24. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker.egg-info/entry_points.txt +0 -0
  25. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/markdown_checker.egg-info/top_level.txt +0 -0
  26. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/pyproject.toml +0 -0
  27. {markdown-checker-0.0.9 → markdown-checker-0.1.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-checker
3
- Version: 0.0.9
3
+ Version: 0.1.1
4
4
  Summary: A markdown validation reporting tool
5
5
  Home-page: https://github.com/john0isaac/markdown-checker
6
6
  Author: John Aziz
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.8
20
20
  Requires-Python: >=3.8
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
+ Requires-Dist: requests
23
24
 
24
25
  [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
25
26
  [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
@@ -38,3 +39,50 @@ markdown-checker is a markdown validation reporting tool.
38
39
  # Using markdown-checker in GitHub Actions
39
40
 
40
41
  The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
42
+
43
+ # Supported Functions
44
+
45
+ ## Check broken relative paths
46
+ This function ensures that any relative path in your files is working.
47
+
48
+ Example:
49
+
50
+ ```bash
51
+ markdown-checker -d . -f check_broken_paths -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
52
+ ```
53
+
54
+ ## Check broken URLs
55
+ This function ensures that any web URL in your files is working and returning 200 status code.
56
+
57
+ Example:
58
+
59
+ ```bash
60
+ markdown-checker -d . -f check_broken_urls -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
61
+ ```
62
+
63
+ ## Check country locale present in URLs
64
+ This function ensures that any relative path in your files is working.
65
+
66
+ Example:
67
+
68
+ ```bash
69
+ markdown-checker -d . -f check_urls_locale -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
70
+ ```
71
+
72
+ ## Check Contributor ID missing from paths
73
+ This function ensures that any relative path has tracking in it.
74
+
75
+ Example:
76
+
77
+ ```bash
78
+ markdown-checker -d . -f check_paths_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
79
+ ```
80
+
81
+ ## Check Contributor ID missing from URLs
82
+ This function ensures that any URL has tracking in it.
83
+
84
+ Example:
85
+
86
+ ```bash
87
+ markdown-checker -d . -f check_urls_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
88
+ ```
@@ -0,0 +1,64 @@
1
+ [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
2
+ [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
3
+
4
+ [![GitHub issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/john0isaac/markdown-checker/issues)
5
+ [![Contributing](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://github.com/john0isaac/markdown-checker/pulls)
6
+
7
+ markdown-checker is a markdown validation reporting tool.
8
+
9
+ # How To
10
+
11
+ 1. Run `pip install markdown-checker`.
12
+ 2. Run `markdown-checker -d {src} -f {func} -gu {url}`. Replace `{src}` with the directory you want to analyze, {func} with the available functions like check_broken_paths, {gu} with your contribution guidance full URL.
13
+ 3. The output will be displayed in the terminal and in a `comments.md` file.
14
+
15
+ # Using markdown-checker in GitHub Actions
16
+
17
+ The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
18
+
19
+ # Supported Functions
20
+
21
+ ## Check broken relative paths
22
+ This function ensures that any relative path in your files is working.
23
+
24
+ Example:
25
+
26
+ ```bash
27
+ markdown-checker -d . -f check_broken_paths -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
28
+ ```
29
+
30
+ ## Check broken URLs
31
+ This function ensures that any web URL in your files is working and returning 200 status code.
32
+
33
+ Example:
34
+
35
+ ```bash
36
+ markdown-checker -d . -f check_broken_urls -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
37
+ ```
38
+
39
+ ## Check country locale present in URLs
40
+ This function ensures that any relative path in your files is working.
41
+
42
+ Example:
43
+
44
+ ```bash
45
+ markdown-checker -d . -f check_urls_locale -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
46
+ ```
47
+
48
+ ## Check Contributor ID missing from paths
49
+ This function ensures that any relative path has tracking in it.
50
+
51
+ Example:
52
+
53
+ ```bash
54
+ markdown-checker -d . -f check_paths_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
55
+ ```
56
+
57
+ ## Check Contributor ID missing from URLs
58
+ This function ensures that any URL has tracking in it.
59
+
60
+ Example:
61
+
62
+ ```bash
63
+ markdown-checker -d . -f check_urls_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
64
+ ```
@@ -1,20 +1,22 @@
1
1
  """
2
- Module providing automatic checks functionality to markdown files
2
+ Module providing automatic checks functionality to markdown files
3
3
  following some Guidelines
4
4
  """
5
+
5
6
  from markdown_checker.links.link_operations import (
7
+ check_paths_exists,
8
+ check_url_alive,
9
+ check_url_locale,
10
+ check_url_tracking,
6
11
  get_links_from_file,
7
12
  get_paths_from_links,
8
13
  get_urls_from_links,
9
- check_paths_exists,
10
- check_url_locale,
11
- check_url_tracking
12
14
  )
13
15
 
14
16
 
15
- def check_broken_links(file_path : str, link_type : str , check_type: str) -> str:
17
+ def check_broken_links(file_path: str, link_type: str, check_type: str) -> str:
16
18
  """function that checks if urls and hyperlinks are broken
17
-
19
+
18
20
  Keyword arguments:
19
21
  file_path -- a path to text file to check
20
22
  link_type -- path or url
@@ -25,28 +27,55 @@ def check_broken_links(file_path : str, link_type : str , check_type: str) -> st
25
27
 
26
28
  # check if file has links
27
29
  if len(all_links) > 0:
28
- formatted_output = f"|<code>{file_path}</code>|"
30
+ formatted_output = f"| `{file_path}` |"
29
31
  if link_type == "path":
30
32
  paths = get_paths_from_links(all_links)
31
33
  if check_type == "broken" and len(paths) > 0:
32
34
  broken_path = check_paths_exists(file_path, paths)
33
- if len (broken_path) > 0:
34
- formatted_output += f'<code>{broken_path}</code>|\n'
35
+ if len(broken_path) > 0:
36
+ formatted_output += format_links(broken_path)
35
37
  return formatted_output
36
38
  elif check_type == "tracking" and len(paths) > 0:
37
39
  tracking_id_paths = check_url_tracking(paths)
38
40
  if len(tracking_id_paths) > 0:
39
- formatted_output += f'<code>{tracking_id_paths}</code>|\n'
41
+ formatted_output += format_links(tracking_id_paths)
40
42
  return formatted_output
41
43
  elif link_type == "url":
42
44
  urls = get_urls_from_links(all_links)
43
45
  if check_type == "tracking" and len(urls) > 0:
44
46
  tracking_id_urls = check_url_tracking(urls)
45
47
  if len(tracking_id_urls) > 0:
46
- formatted_output += f'<code>{tracking_id_urls}</code>|\n'
48
+ formatted_output += format_links(tracking_id_urls)
47
49
  return formatted_output
48
50
  elif check_type == "locale" and len(urls) > 0:
49
51
  country_locale_urls = check_url_locale(urls)
50
52
  if len(country_locale_urls) > 0:
51
- formatted_output += f'<code>{country_locale_urls}</code>|\n'
53
+ formatted_output += format_links(country_locale_urls)
54
+ return formatted_output
55
+ elif check_type == "broken" and len(urls) > 0:
56
+ dead_urls = check_url_alive(urls)
57
+ if len(dead_urls) > 0:
58
+ formatted_output += format_links(dead_urls)
52
59
  return formatted_output
60
+
61
+
62
+ def format_links(links: list) -> str:
63
+ """
64
+ Formats a list of links into a string with numbered bullets.
65
+
66
+ Args:
67
+ links (list): A list of links.
68
+
69
+ Returns:
70
+ str: The formatted string with numbered bullets.
71
+ """
72
+ formatted_links = ""
73
+ i = 1
74
+ for link in links:
75
+ if i == len(links):
76
+ formatted_links += f" {i}. `{link}` |\n"
77
+ else:
78
+ formatted_links += f" {i}. `{link}` <br/>"
79
+ i += 1
80
+
81
+ return formatted_links
@@ -3,6 +3,11 @@ CHECK_BROKEN_PATHS = """# Check Broken Paths
3
3
  We have automatically detected the following broken relative paths in your lessons. Review and fix the paths to resolve this issue.
4
4
 
5
5
  Check the file paths and associated broken paths inside them."""
6
+ CHECK_BROKEN_URLS = """# Check Broken URLS
7
+
8
+ We have automatically detected the following broken URLS in your lessons. Review and fix the paths to resolve this issue.
9
+
10
+ Check the file paths and associated broken urls inside them."""
6
11
  CHECK_PATHS_TRACKING = """# Check Missing Tracking from Paths
7
12
 
8
13
  We have automatically detected missing tracking id from the following relative paths in your lessons. Review and add tracking to paths to resolve this issue.
@@ -19,12 +24,16 @@ We have automatically detected added country locale to URLs in your lessons. Rev
19
24
 
20
25
  Check the file paths and associated URLs inside them."""
21
26
 
27
+
22
28
  def write_md_file(generated_md: str) -> None:
23
29
  """Write the formatted output to a markdown file"""
24
30
  with open("comment.md", "w", encoding="utf-8") as file:
25
31
  file.write(generated_md)
26
32
 
27
- def generate_md(formatted_output: str, function_name: str, contributing_guide_url: str) -> None:
33
+
34
+ def generate_md(
35
+ formatted_output: str, function_name: str, contributing_guide_url: str
36
+ ) -> None:
28
37
  """Generate markdown file based on the formatted output, function name, and contributing guide URL.
29
38
 
30
39
  Args:
@@ -38,13 +47,25 @@ def generate_md(formatted_output: str, function_name: str, contributing_guide_ur
38
47
  """
39
48
  contributing_guide_line = f" For more details, check our [Contributing Guide]({contributing_guide_url}).\n\n"
40
49
  if function_name == "check_broken_paths":
41
- formatted_output = CHECK_BROKEN_PATHS + contributing_guide_line + formatted_output
50
+ formatted_output = (
51
+ CHECK_BROKEN_PATHS + contributing_guide_line + formatted_output
52
+ )
53
+ elif function_name == "check_broken_urls":
54
+ formatted_output = (
55
+ CHECK_BROKEN_URLS + contributing_guide_line + formatted_output
56
+ )
42
57
  elif function_name == "check_paths_tracking":
43
- formatted_output = CHECK_PATHS_TRACKING + contributing_guide_line + formatted_output
58
+ formatted_output = (
59
+ CHECK_PATHS_TRACKING + contributing_guide_line + formatted_output
60
+ )
44
61
  elif function_name == "check_urls_tracking":
45
- formatted_output = CHECK_URLS_TRACKING + contributing_guide_line + formatted_output
62
+ formatted_output = (
63
+ CHECK_URLS_TRACKING + contributing_guide_line + formatted_output
64
+ )
46
65
  elif function_name == "check_urls_locale":
47
- formatted_output = CHECK_URLS_LOCALE + contributing_guide_line + formatted_output
66
+ formatted_output = (
67
+ CHECK_URLS_LOCALE + contributing_guide_line + formatted_output
68
+ )
48
69
  else:
49
70
  raise ValueError("Invalid function name")
50
71
 
@@ -1,16 +1,18 @@
1
1
  """
2
- Module providing automatic checks functionality to markdown files
2
+ Module providing automatic checks functionality to markdown files
3
3
  following some Guidelines
4
4
  """
5
+
5
6
  import argparse
6
7
 
8
+
7
9
  def get_input_args() -> None:
8
10
  """
9
11
  Retrieves and parses the 2 command line arguments provided by the user when
10
- they run the program from a terminal window. This function uses Python's
11
- argparse module to created and defined these 2 command line arguments. If
12
- the user fails to provide some or all of the 2 arguments, then the default
13
- values are used for the missing arguments.
12
+ they run the program from a terminal window. This function uses Python's
13
+ argparse module to created and defined these 2 command line arguments. If
14
+ the user fails to provide some or all of the 2 arguments, then the default
15
+ values are used for the missing arguments.
14
16
  Command Line Arguments:
15
17
  1. Tutorials Path as --dir
16
18
  2. Function to be executed as --func
@@ -18,22 +20,42 @@ def get_input_args() -> None:
18
20
  Parameters:
19
21
  None - simply using argparse module to create & store command line arguments
20
22
  Returns:
21
- parse_args() -data structure that stores the command line arguments object
23
+ parse_args() -data structure that stores the command line arguments object
22
24
  """
23
25
  # Parse using ArgumentParser
24
26
  parser = argparse.ArgumentParser()
25
27
 
26
- parser.add_argument('-d', '--dir', type = str, default = './',
27
- help = 'path to the root directory', required=True)
28
+ parser.add_argument(
29
+ "-d",
30
+ "--dir",
31
+ type=str,
32
+ default="./",
33
+ help="path to the root directory",
34
+ required=True,
35
+ )
28
36
 
29
- parser.add_argument('-f', '--func', type = str, required = True,
30
- help = 'function to be executed',
31
- choices=['check_broken_paths',
32
- 'check_paths_tracking',
33
- 'check_urls_tracking',
34
- 'check_urls_locale'])
37
+ parser.add_argument(
38
+ "-f",
39
+ "--func",
40
+ type=str,
41
+ required=True,
42
+ help="function to be executed",
43
+ choices=[
44
+ "check_broken_paths",
45
+ "check_broken_urls",
46
+ "check_paths_tracking",
47
+ "check_urls_tracking",
48
+ "check_urls_locale",
49
+ ],
50
+ )
35
51
 
36
- parser.add_argument('-gu', '--guide-url', type = str, default = 'https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md',
37
- help = 'full url of your contributing guide', required=True)
52
+ parser.add_argument(
53
+ "-gu",
54
+ "--guide-url",
55
+ type=str,
56
+ default="https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
57
+ help="full url of your contributing guide",
58
+ required=True,
59
+ )
38
60
 
39
61
  return parser.parse_args()
@@ -1,38 +1,49 @@
1
- import re
2
1
  import os
2
+ import re
3
+
3
4
 
4
5
  def get_links_from_file(file_path: str) -> list:
5
6
  """function to get an array of markdown links from a file
6
7
  flags markdown links captures the part inside () that comes right after []
7
8
  """
8
9
  all_links = []
9
- with open(file_path, 'r', encoding="utf-8") as file:
10
+ with open(file_path, "r", encoding="utf-8") as file:
10
11
  data = file.read()
11
- link_pattern = re.compile(r'\]\((.*?)\)| \)')
12
+ link_pattern = re.compile(r"\]\((.*?)\)| \)")
12
13
  matches = re.finditer(link_pattern, data)
13
14
  for matched_group in matches:
14
15
  if matched_group.group(1):
15
16
  all_links.append(matched_group.group(1))
16
17
  return all_links
17
18
 
19
+
18
20
  def get_urls_from_links(all_links: list) -> list:
19
21
  """function to get an array of urls from a list"""
20
22
  urls = []
21
- url_pattern = re.compile(r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)')
22
- allowed_list = ['github.com', 'microsoft.com', 'visualstudio.com', 'aka.ms', 'azure.com']
23
+ url_pattern = re.compile(
24
+ r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)"
25
+ )
26
+ allowed_list = [
27
+ "github.com",
28
+ "microsoft.com",
29
+ "visualstudio.com",
30
+ "aka.ms",
31
+ "azure.com",
32
+ ]
23
33
  for link in all_links:
24
34
  matches = re.findall(url_pattern, link)
25
-
35
+
26
36
  if matches and any(allowed in link.lower() for allowed in allowed_list):
27
37
  urls.append(link)
28
38
  return urls
29
39
 
40
+
30
41
  def get_paths_from_links(all_links: list) -> list:
31
42
  """function to get relative paths from a list
32
43
  flags paths that start with ./ or ../
33
44
  """
34
45
  paths = []
35
- path_pattern = re.compile(r'(\.{1,2}\/)+([A-Za-z0-9-]+\/)*(.+\.[A-Za-z]+)')
46
+ path_pattern = re.compile(r"(\.{1,2}\/)+([A-Za-z0-9-]+\/)*(.+\.[A-Za-z]+)")
36
47
 
37
48
  for link in all_links:
38
49
  link = link.split(" ")[0]
@@ -41,59 +52,90 @@ def get_paths_from_links(all_links: list) -> list:
41
52
  paths.append(link)
42
53
  return paths
43
54
 
44
- def check_paths_exists(file_path : str, paths : list) -> list:
55
+
56
+ def check_paths_exists(file_path: str, paths: list) -> list:
45
57
  """function checks if a path exist if not return non existent paths
46
58
  flags any relative path that can't be accessed
47
59
  """
48
60
  broken_path = []
49
61
  for path in paths:
50
- path = re.sub(r'(\?|\&)(WT|wt)\.mc_id=.*', '', path)
51
- if not os.path.exists(os.path.normpath(os.path.join(os.path.dirname(file_path), path))):
62
+ path = re.sub(r"(\?|\&)(WT|wt)\.mc_id=.*", "", path)
63
+ if not os.path.exists(
64
+ os.path.normpath(os.path.join(os.path.dirname(file_path), path))
65
+ ):
52
66
  broken_path.append(path)
53
67
  return broken_path
54
68
 
55
- def check_url_locale(urls : list) -> list:
69
+
70
+ def check_url_locale(urls: list) -> list:
56
71
  """function checks if a url has country locale
57
72
  flags urls that have ==> /en-us/
58
73
  """
59
74
  country_locale = []
60
75
  for url in urls:
61
- locale_pattern = re.compile(r'\/[a-z]{2}-[a-z]{2}\/')
76
+ if (
77
+ "video-embed.html" in url
78
+ or "https://www.microsoft.com/en-us/security/blog" in url
79
+ ):
80
+ continue
81
+ locale_pattern = re.compile(r"\/[a-z]{2}-[a-z]{2}\/")
62
82
  matches = re.findall(locale_pattern, url)
63
- if matches and "video-embed.html" not in url:
83
+ if matches:
64
84
  country_locale.append(url)
65
85
  return country_locale
66
86
 
67
- def check_url_tracking(urls : list) -> list:
87
+
88
+ def check_url_tracking(urls: list) -> list:
68
89
  """function checks if a url has tracking id
69
90
  flags urls missing ==> (? or &) plus WT.mc_id= or wt.mc_id=
70
91
  """
71
92
  tracking_id = []
72
93
  for url in urls:
73
- tracking_pattern = re.compile(r'(\?|\&)(WT|wt)\.mc_id=')
94
+ tracking_pattern = re.compile(r"(\?|\&)(WT|wt)\.mc_id=")
74
95
  matches = re.findall(tracking_pattern, url)
75
96
  if not matches:
76
97
  tracking_id.append(url)
77
98
  return tracking_id
78
99
 
100
+
101
+ def check_url_alive(urls: list) -> list:
102
+ import requests
103
+
104
+ broken_urls = []
105
+ for url in urls:
106
+ try:
107
+ response = requests.get(url, timeout=10)
108
+ if response.status_code != 200:
109
+ broken_urls.append(url)
110
+ except requests.exceptions.RequestException:
111
+ broken_urls.append(url)
112
+ continue
113
+ return broken_urls
114
+
115
+
79
116
  # DEPRECATED
80
117
  def get_urls_from_file(file_path: str) -> list:
81
118
  """function to get an array of urls from a file"""
82
119
  urls = []
83
- with open(file_path, 'r', encoding="utf-8") as file:
120
+ with open(file_path, "r", encoding="utf-8") as file:
84
121
  data = file.read()
85
- url_pattern = re.compile(r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)')
122
+ url_pattern = re.compile(
123
+ r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9]{1,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)"
124
+ )
86
125
  matches = re.finditer(url_pattern, data)
87
126
  for matched_group in matches:
88
127
  urls.append(matched_group.group())
89
128
  return urls
90
129
 
130
+
91
131
  def get_paths_from_file(file_path: str) -> list:
92
132
  """function to get relative paths from a file"""
93
133
  paths = []
94
- with open(file_path, 'r', encoding="utf-8") as file:
134
+ with open(file_path, "r", encoding="utf-8") as file:
95
135
  data = file.read()
96
- path_pattern = re.compile(r'(\.{1,2}\/)+([A-Za-z0-9-]+\/)*([A-Za-z0-9]+\.[A-Za-z]+)')
136
+ path_pattern = re.compile(
137
+ r"(\.{1,2}\/)+([A-Za-z0-9-]+\/)*([A-Za-z0-9]+\.[A-Za-z]+)"
138
+ )
97
139
  matches = re.finditer(path_pattern, data)
98
140
  for matched_group in matches:
99
141
  paths.append(matched_group.group())
@@ -10,6 +10,7 @@ Functions:
10
10
 
11
11
  import os
12
12
 
13
+
13
14
  def get_files_paths_list(root_path: str, extensions: list = None) -> list:
14
15
  """
15
16
  function returns a list of files in a directory and its subdirectories,
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- Module providing automatic checks functionality to markdown files
3
+ Module providing automatic checks functionality to markdown files
4
4
  following some Guidelines
5
5
  """
6
- from markdown_checker.inputs.input_arguments import get_input_args
6
+
7
7
  from markdown_checker.check_markdown import check_broken_links
8
- from markdown_checker.paths.files_paths_reader import get_files_paths_list
9
8
  from markdown_checker.generators.md_generator import generate_md
9
+ from markdown_checker.inputs.input_arguments import get_input_args
10
+ from markdown_checker.paths.files_paths_reader import get_files_paths_list
11
+
10
12
 
11
13
  def main() -> None:
12
14
  """Main program get inputs and run checks"""
@@ -16,7 +18,14 @@ def main() -> None:
16
18
 
17
19
  _, files_paths = get_files_paths_list(in_arg.dir)
18
20
 
19
- pass_list = ['./CODE_OF_CONDUCT.md', './CONTRIBUTING.md', './SECURITY.md', '.\CODE_OF_CONDUCT.md', '.\CONTRIBUTING.md', '.\SECURITY.md']
21
+ pass_list = [
22
+ "./CODE_OF_CONDUCT.md",
23
+ "./CONTRIBUTING.md",
24
+ "./SECURITY.md",
25
+ ".\CODE_OF_CONDUCT.md",
26
+ ".\CONTRIBUTING.md",
27
+ ".\SECURITY.md",
28
+ ]
20
29
  files_paths = [file_path for file_path in files_paths if file_path not in pass_list]
21
30
 
22
31
  formatted_output = ""
@@ -24,25 +33,32 @@ def main() -> None:
24
33
  # iterate over the files to validate the content
25
34
  for file_path in files_paths:
26
35
  if "check_broken_paths" in in_arg.func:
27
- broken_paths = check_broken_links(file_path, "path" , "broken")
36
+ broken_paths = check_broken_links(file_path, "path", "broken")
28
37
  if broken_paths:
29
38
  formatted_output += broken_paths
30
39
  if "check_paths_tracking" in in_arg.func:
31
- paths_tracking = check_broken_links(file_path, "path" , "tracking")
40
+ paths_tracking = check_broken_links(file_path, "path", "tracking")
32
41
  if paths_tracking:
33
42
  formatted_output += paths_tracking
34
43
  if "check_urls_tracking" in in_arg.func:
35
- urls_tracking = check_broken_links(file_path, "url" , "tracking")
44
+ urls_tracking = check_broken_links(file_path, "url", "tracking")
36
45
  if urls_tracking:
37
46
  formatted_output += urls_tracking
38
47
  if "check_urls_locale" in in_arg.func:
39
- urls_locale = check_broken_links(file_path, "url" , "locale")
48
+ urls_locale = check_broken_links(file_path, "url", "locale")
40
49
  if urls_locale:
41
50
  formatted_output += urls_locale
51
+ if "check_broken_urls" in in_arg.func:
52
+ broken_urls = check_broken_links(file_path, "url", "broken")
53
+ if broken_urls:
54
+ formatted_output += broken_urls
42
55
  if formatted_output != "":
43
- formatted_output = "| File Full Path | Issues |\n|--------|--------|\n" + formatted_output
56
+ formatted_output = (
57
+ "| File Full Path | Issues |\n|--------|--------|\n" + formatted_output
58
+ )
44
59
  print(formatted_output)
45
60
  generate_md(formatted_output, in_arg.func, in_arg.guide_url)
46
61
 
62
+
47
63
  if __name__ == "__main__":
48
64
  main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: markdown-checker
3
- Version: 0.0.9
3
+ Version: 0.1.1
4
4
  Summary: A markdown validation reporting tool
5
5
  Home-page: https://github.com/john0isaac/markdown-checker
6
6
  Author: John Aziz
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.8
20
20
  Requires-Python: >=3.8
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
+ Requires-Dist: requests
23
24
 
24
25
  [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
25
26
  [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
@@ -38,3 +39,50 @@ markdown-checker is a markdown validation reporting tool.
38
39
  # Using markdown-checker in GitHub Actions
39
40
 
40
41
  The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
42
+
43
+ # Supported Functions
44
+
45
+ ## Check broken relative paths
46
+ This function ensures that any relative path in your files is working.
47
+
48
+ Example:
49
+
50
+ ```bash
51
+ markdown-checker -d . -f check_broken_paths -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
52
+ ```
53
+
54
+ ## Check broken URLs
55
+ This function ensures that any web URL in your files is working and returning 200 status code.
56
+
57
+ Example:
58
+
59
+ ```bash
60
+ markdown-checker -d . -f check_broken_urls -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
61
+ ```
62
+
63
+ ## Check country locale present in URLs
64
+ This function ensures that any relative path in your files is working.
65
+
66
+ Example:
67
+
68
+ ```bash
69
+ markdown-checker -d . -f check_urls_locale -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
70
+ ```
71
+
72
+ ## Check Contributor ID missing from paths
73
+ This function ensures that any relative path has tracking in it.
74
+
75
+ Example:
76
+
77
+ ```bash
78
+ markdown-checker -d . -f check_paths_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
79
+ ```
80
+
81
+ ## Check Contributor ID missing from URLs
82
+ This function ensures that any URL has tracking in it.
83
+
84
+ Example:
85
+
86
+ ```bash
87
+ markdown-checker -d . -f check_urls_tracking -gu https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md
88
+ ```
@@ -11,6 +11,7 @@ markdown_checker.egg-info/PKG-INFO
11
11
  markdown_checker.egg-info/SOURCES.txt
12
12
  markdown_checker.egg-info/dependency_links.txt
13
13
  markdown_checker.egg-info/entry_points.txt
14
+ markdown_checker.egg-info/requires.txt
14
15
  markdown_checker.egg-info/top_level.txt
15
16
  markdown_checker/generators/__init__.py
16
17
  markdown_checker/generators/md_generator.py
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = markdown-checker
3
- version = 0.0.9
3
+ version = 0.1.1
4
4
  author = John Aziz
5
5
  author_email = johnaziz269@gmail.com
6
6
  maintainer = John Aziz
@@ -24,6 +24,8 @@ classifiers =
24
24
  Programming Language :: Python :: 3.8
25
25
 
26
26
  [options]
27
+ install_requires =
28
+ requests
27
29
  include_package_data = True
28
30
  packages = find:
29
31
  python_requires = >=3.8
@@ -0,0 +1,127 @@
1
+ """
2
+ Module to check paths in markdown files.
3
+ """
4
+
5
+ import subprocess
6
+
7
+
8
+ def check_broken_paths():
9
+ """
10
+ Function to check for broken paths.
11
+ """
12
+ print("check_broken_paths was called")
13
+ subprocess.run(
14
+ [
15
+ "markdown-checker",
16
+ "-d",
17
+ "./tests/resources/",
18
+ "-f",
19
+ "check_broken_paths",
20
+ "-gu",
21
+ "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
22
+ ],
23
+ check=False,
24
+ )
25
+
26
+
27
+ def check_broken_urls():
28
+ """
29
+ Function to check for broken paths.
30
+ """
31
+ print("check_broken_urls was called")
32
+ subprocess.run(
33
+ [
34
+ "markdown-checker",
35
+ "-d",
36
+ "./tests/resources/",
37
+ "-f",
38
+ "check_broken_urls",
39
+ "-gu",
40
+ "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
41
+ ],
42
+ check=False,
43
+ )
44
+
45
+
46
+ def check_paths_tracking():
47
+ """
48
+ Function to check paths tracking.
49
+ """
50
+ print("check_paths_tracking was called")
51
+ subprocess.run(
52
+ [
53
+ "markdown-checker",
54
+ "-d",
55
+ "./tests/resources/",
56
+ "-f",
57
+ "check_paths_tracking",
58
+ "-gu",
59
+ "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
60
+ ],
61
+ check=False,
62
+ )
63
+
64
+
65
+ def check_urls_tracking():
66
+ """
67
+ Function to check URLs tracking.
68
+ """
69
+ print("check_urls_tracking was called")
70
+ subprocess.run(
71
+ [
72
+ "markdown-checker",
73
+ "-d",
74
+ "./tests/resources/",
75
+ "-f",
76
+ "check_urls_tracking",
77
+ "-gu",
78
+ "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
79
+ ],
80
+ check=False,
81
+ )
82
+
83
+
84
+ def check_urls_locale():
85
+ """
86
+ Function to check URLs locale.
87
+ """
88
+ print("check_urls_locale was called")
89
+ subprocess.run(
90
+ [
91
+ "markdown-checker",
92
+ "-d",
93
+ "./tests/resources/",
94
+ "-f",
95
+ "check_urls_locale",
96
+ "-gu",
97
+ "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md",
98
+ ],
99
+ check=False,
100
+ )
101
+
102
+
103
+ mydict = {
104
+ 1: check_broken_paths,
105
+ 2: check_broken_urls,
106
+ 3: check_paths_tracking,
107
+ 4: check_urls_tracking,
108
+ 5: check_urls_locale,
109
+ }
110
+
111
+ try:
112
+ choices = list(
113
+ map(
114
+ int,
115
+ input(
116
+ "Do you want to: \n(1) Run check_broken_paths \n(2) Run check_broken_urls \n(3) Run check_paths_tracking \n(4) Run check_urls_tracking \n(5) Run check_urls_locale \n"
117
+ ).split(),
118
+ )
119
+ )
120
+ except ValueError:
121
+ print("Please input number")
122
+
123
+ for choice in choices:
124
+ if 0 < choice and choice < 6:
125
+ mydict[choice]()
126
+ else:
127
+ print("That is not between 1 and 5! Try again:")
@@ -1,17 +0,0 @@
1
- [![PyPi](https://img.shields.io/pypi/v/markdown-checker)](https://pypi.org/project/markdown-checker/)
2
- [![Downloads](https://img.shields.io/pypi/dm/markdown-checker)](https://pypi.org/project/markdown-checker/)
3
-
4
- [![GitHub issues](https://img.shields.io/badge/issue_tracking-github-blue.svg)](https://github.com/john0isaac/markdown-checker/issues)
5
- [![Contributing](https://img.shields.io/badge/PR-Welcome-%23FF8300.svg?)](https://github.com/john0isaac/markdown-checker/pulls)
6
-
7
- markdown-checker is a markdown validation reporting tool.
8
-
9
- # How To
10
-
11
- 1. Run `pip install markdown-checker`.
12
- 2. Run `markdown-checker -d {src} -f {func} -gu {url}`. Replace `{src}` with the directory you want to analyze, {func} with the available functions like check_broken_paths, {gu} with your contribution guidance full URL.
13
- 3. The output will be displayed in the terminal and in a `comments.md` file.
14
-
15
- # Using markdown-checker in GitHub Actions
16
-
17
- The tool has been designed to be run within a GitHub workflow using the [action-check-markdown](https://github.com/marketplace/actions/check-markdown) GitHub action. The action will automatically post the output of the tool to your GitHub pull request as a comment.
@@ -1,46 +0,0 @@
1
- """
2
- Module to check paths in markdown files.
3
- """
4
-
5
- import subprocess
6
-
7
- def check_broken_paths():
8
- """
9
- Function to check for broken paths.
10
- """
11
- print("check_broken_paths was called")
12
- subprocess.run(["markdown-checker", "-d", "./tests/resources/", "-f", "check_broken_paths", "-gu", "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md"], check=False)
13
-
14
- def check_paths_tracking():
15
- """
16
- Function to check paths tracking.
17
- """
18
- print("check_paths_tracking was called")
19
- subprocess.run(["markdown-checker", "-d", "./tests/resources/", "-f", "check_paths_tracking", "-gu", "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md"], check=False)
20
-
21
- def check_urls_tracking():
22
- """
23
- Function to check URLs tracking.
24
- """
25
- print("check_urls_tracking was called")
26
- subprocess.run(["markdown-checker", "-d", "./tests/resources/", "-f", "check_urls_tracking", "-gu", "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md"], check=False)
27
-
28
- def check_urls_locale():
29
- """
30
- Function to check URLs locale.
31
- """
32
- print("check_urls_locale was called")
33
- subprocess.run(["markdown-checker", "-d", "./tests/resources/", "-f", "check_urls_locale", "-gu", "https://github.com/john0isaac/markdown-checker/blob/main/CONTRIBUTING.md"], check=False)
34
-
35
- mydict = {1:check_broken_paths, 2:check_paths_tracking, 3:check_urls_tracking, 4:check_urls_locale}
36
-
37
- try:
38
- choices = list(map(int,input("Do you want to: \n(1) Run check_broken_paths \n(2) Run check_paths_tracking \n(3) Run check_urls_tracking \n(4) Run check_urls_locale \n").split()))
39
- except ValueError:
40
- print("Please input number")
41
-
42
- for choice in choices:
43
- if 0 < choice and choice < 5:
44
- mydict[choice]()
45
- else:
46
- print("That is not between 1 and 4! Try again:")