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

General doc fixes #35

Closed
wants to merge 4 commits into from
Closed

General doc fixes #35

wants to merge 4 commits into from

Conversation

jeffclay
Copy link
Contributor

@jeffclay jeffclay commented Jan 28, 2024

Some general fixes done while resolving #25

Found that files, while being UTF-8 encoded had many instances of [NBSP]. These instances were replaced with a regular
UTF-8 space.

Also fixed a lot of the block/code formatting for broken blocks and modified line blocks to match the same format/pattern for code consistency.

…SP]. These instances were replaced with a regular UTF-8 space.
Copy link

github-actions bot commented Jan 28, 2024

🪓 PR closed, deleted preview at https://github.com/freeipa/freeipa.github.io/tree/gh-pages/pull/35/

…ed line blocks to match the same format/pattern for code consistency.
The command '# getcert list -c IPA' was updated to remove a leading space, ensuring it is displayed correctly.
@jeffclay jeffclay marked this pull request as ready for review January 28, 2024 06:10
@jeffclay
Copy link
Contributor Author

There are a LOT of changes here. I scripted with a bit of help from good 'ol chatgpt. Below is the very quick and dirty python that's responsible for the changes. I'm not proud of it, but it worked. :)

import os


def process_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()

    new_lines = []
    i = 0
    while i < len(lines):
        line = lines[i]

        # Check for code block start
        if line.startswith('| ``') and (i == 0 or lines[i - 1].strip() == ''):
            new_lines.append('.. code-block:: text\n\n')
            while i < len(lines) and not lines[i].strip() == '':
                # Check if line starts with "| ``" or "| :literal:"
                if lines[i].startswith('| ``') or lines[i].startswith('| :literal:'):
                    # Determine the start index for content extraction (4 for "| ``" and 12 for "| :literal:")
                    start_index = 4 if lines[i].startswith('| ``') else 12
                    content = lines[i][start_index:]

                    # Remove trailing "``" if present
                    if content.rstrip().endswith('``'):
                        content = content.rstrip()[:-2]

                    new_line = '    ' + content + '\n'
                    new_lines.append(new_line)
                else:
                    new_lines.append(lines[i])
                i += 1
            continue

        new_lines.append(line)
        i += 1

    with open(file_path, 'w') as file:
        file.writelines(new_lines)


def process_file2(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()

    with open(file_path, 'w') as file:
        for line in lines:
            if line.strip() == '::':
                line = '.. code-block:: text\n'
            elif line.startswith("   | ``") and line.endswith('``\n'):
                line = line.replace("   | ``", "    ", 1)
            elif line.startswith("| :literal:"):
                line = line.replace("| :literal:", "    ", 1)
            elif line.startswith("   | :literal:"):
                line = line.replace("| :literal:", " ", 1)
            elif line.startswith("   ``") and line.endswith("``\n"):
                line = "   " + line[5:-3] + "\n"
            file.write(line)


def process_directory(directory):
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.rst'):
                process_file(os.path.join(root, file))
                process_file2(os.path.join(root, file))


process_directory('/my/path')
print(f'Done')

@jeffclay
Copy link
Contributor Author

I'm cancelling this PR for now. I'm finding more straggler issues and I want to be more confident random lines aren't disappearing.

@jeffclay jeffclay closed this Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant