Skip to content

Commit

Permalink
multiple links for fix in one line supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk Jatczak committed Apr 10, 2024
1 parent 96a51af commit c54f848
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion publish_docs.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set ENABLE_SEARCH=true
python -m mkdocs build
python tools/documentation/docs_modifier.py site
set ENABLE_SEARCH=
gsutil -m rsync -j html,txt,xml,png,js,css,json,svg,gif -r site gs://docs-dqo-ai/docs/
@REM gsutil -m rsync -j html,txt,xml,png,js,css,json,svg,gif -r site gs://docs-dqo-ai/docs/
5 changes: 4 additions & 1 deletion tools/documentation/docs_modifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from scripts.files_provider import get_all_files
from scripts.docs_file_modifier import modify_file
import sys

import time

def main():

Expand All @@ -21,6 +21,9 @@ def main():

print("Total modified files : " + str(number))

start = time.time()
main()
end = time.time()
print("time : " + end - start)

# python docs_modifier.py C:\dev\dqoado\site
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
tag_regex_string: str = "<(((a)|(link))[^<>]*href)|(((script)|(img))[^<>]*src)=[^<>]*>"
link_tag_pattern: re.Pattern = re.compile(tag_regex_string)

attribute_regex_string: str = """((?:(?:href)|(?:src))=\"([^<>]*)\")"""
attribute_regex_string: str = """((?:(?:href)|(?:src))=\"(?:([.]{2}[^<>]*)|([^<>]*/))\")"""
link_pattern: re.Pattern = re.compile(attribute_regex_string)

def modify_link(line: str, file_path: str) -> str:
Expand All @@ -26,6 +26,8 @@ def _apply_modification(line: str, file_path: str) -> str:
file_path_fixed = file_path.replace("\\", "/")

result = link_pattern.search(line)
if result is None:
return line
groups = result.groups()

for link in groups:
Expand Down
9 changes: 6 additions & 3 deletions tools/documentation/scripts/docs_file_modifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from scripts.file_handler import provide_file_content, save_lines_to_file
from scripts.content_modifiers.script_tag_modifier import modify_script_tag
from scripts.content_modifiers.link_modifier import modify_link
import scripts.content_modifiers.link_modifier as link_modifier
import scripts.content_modifiers.search_script_link_modifier as search_script_link_modifier


def modify_file(file_path: str):

Expand All @@ -9,8 +11,9 @@ def modify_file(file_path: str):

for line in lines:
script_tag_modified_line = modify_script_tag(line)
link_modified_line = modify_link(script_tag_modified_line, file_path)
link_modified_line = link_modifier.modify_link(script_tag_modified_line, file_path)
search_links_modified_line = search_script_link_modifier.modify_link(link_modified_line)

modified_lines.append(link_modified_line)
modified_lines.append(search_links_modified_line)

save_lines_to_file(file_path, modified_lines)
2 changes: 1 addition & 1 deletion tools/documentation/tests/link_modifier_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_modify_link__when_path_is_relative_and_end_wth_slash__then_expand_path_
def test_modify_link__when_two_in_one_line__then_modifies_both(self):
file_path: str = """site/checks/index.html"""
source: str = """<td style="text-align: left;">This<a href="../checks/column/numeric/valid-latitude-percent/index.html">valid_latitude_percent</a> and <a href="../checks/column/numeric/valid-longitude-percent/">valid_longitude_percent</a>checks.</td>"""
target: str = """<td style="text-align: left;">This<a href="/docs/checks/column/numeric/valid-latitude-percent/index.html">valid_latitude_percent</a> and <a href="/docs/checks/column/numeric/valid-longitude-percent/">valid_longitude_percent</a>checks.</td>"""
target: str = """<td style="text-align: left;">This<a href="/docs/checks/column/numeric/valid-latitude-percent/index.html">valid_latitude_percent</a> and <a href="/docs/checks/column/numeric/valid-longitude-percent/index.html">valid_longitude_percent</a>checks.</td>"""
self.maxDiff = None
output: str = modify_link(source, file_path)

Expand Down

0 comments on commit c54f848

Please sign in to comment.