Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change baseline .md's to use reference links (#494) #1444

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

boring-jpg
Copy link

@boring-jpg boring-jpg commented Nov 27, 2024

Converts baseline inline links to point of reference links

🗣 Description

This pull request resolves issue #494 by changing every .md file in a baseline folder to use reference instead of inline links.

💭 Motivation and context

I did not change anything that was not in a baseline folder per the issue template. However this python script can change other markdown files easily:

import os
import re

def convert_inline_to_reference(md_content):
    inline_link_pattern = r'\[([^\]]+)\]\(([^)]+)\)'
    link_definitions = {}

    def replace_inline_with_reference(match):
        link_text = match.group(1)
        url = match.group(2)
        if link_text not in link_definitions:
            link_definitions[link_text] = url
        return f'[{link_text}][]'

    updated_content = re.sub(inline_link_pattern, replace_inline_with_reference, md_content)

    if link_definitions:
        updated_content += '\n' + '\n'.join(f'[{link_text}]: {url}' for link_text, url in link_definitions.items())

    return updated_content 

def convert_file(file_path):
    try:
        with open(file_path, 'r', encoding='utf-8') as file:
            md_content = file.read()

        updated_content = convert_inline_to_reference(md_content)

        if updated_content is None:
            print(f"Warning: No changes made to {file_path}")
            return  

        with open(file_path, 'w', encoding='utf-8') as file:
            file.write(updated_content)

        print(f"Successfully processed and saved: {file_path}")

    except Exception as e:
        print(f"Error processing {file_path}: {e}")

directory = "ANY_DIR_HERE"
for filename in os.listdir(directory):
    if filename.endswith(".md"):
        file_path = os.path.join(directory, filename)
        convert_file(file_path)

Closes #494

🧪 Testing

image

✅ Pre-approval checklist

  • This PR has an informative and human-readable title.
  • PR targets the correct parent branch (e.g., main or release-name) for merge.
  • Changes are limited to a single goal - eschew scope creep!
  • Changes are sized such that they do not touch excessive number of files.
  • All future TODOs are captured in issues, which are referenced in code comments.
  • These code changes follow the ScubaGear content style guide.
  • Related issues these changes resolve are linked preferably via closing keywords.
  • All relevant type-of-change labels added.
  • All relevant project fields are set.
  • All relevant repo and/or project documentation updated to reflect these changes.
  • Unit tests added/updated to cover PowerShell and Rego changes.
  • Functional tests added/updated to cover PowerShell and Rego changes.
  • All relevant functional tests passed.
  • All automated checks (e.g., linting, static analysis, unit/smoke tests) passed.

✅ Pre-merge checklist

  • PR passed smoke test check.

  • Feature branch has been rebased against changes from parent branch, as needed

    Use Rebase branch button below or use this reference to rebase from the command line.

  • Resolved all merge conflicts on branch

  • Notified merge coordinator that PR is ready for merge via comment mention

  • Demonstrate changes to the team for questions and comments.
    (Note: Only required for issues of size Medium or larger)

✅ Post-merge checklist

  • Feature branch deleted after merge to clean up repository.
  • Verified that all checks pass on parent branch (e.g., main or release-name) after merge.

@buidav buidav added the public-reported This issue is reported by the public users of the tool. label Nov 27, 2024
@buidav buidav added this to the Kraken milestone Nov 27, 2024
@buidav
Copy link
Collaborator

buidav commented Nov 27, 2024

@boring-jpg Thanks for opening a PR on this!
Letting you know our review will be delayed because of the Thanksgiving holiday.

@boring-jpg
Copy link
Author

@buidav no worries, Happy Holidays!

@schrolla schrolla modified the milestones: Kraken, Marlin Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
public-reported This issue is reported by the public users of the tool.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert baseline inline links to point of reference links
3 participants