INNER CODE UNIT · Python

count_leading_whitespaces

undergroundwires/Azure-in-bullet-points · tools/markdownlint-fixer.py:20

def count_leading_whitespaces(text):
    return len(text) - len(text.lstrip(' '))

with open(path, 'r', encoding = 'UTF-8') as file:
    lines = file.readlines()
    for line_index, line in enumerate(lines):
        # Ensure 2 whitespaces are used instead of tabs (MD007 - Unordered list indentation)
        if line.startswith('    '):
            total_white_spaces = count_leading_whitespaces(line)
            line = line.lstrip(' ')
            total_white_spaces = total_white_spaces / 2
            if int(total_white_spaces) != total_white_spaces:
                normalized = math.ceil(total_white_spaces)
                print(f'Bad total white spaces: {str(total_white_spaces)} normalized to {str(normalized)}. Line: "{line}"')
                total_white_spaces = normalized
            total_white_spaces = int(total_white_spaces)
            for i in range(total_white_spaces):
                line = ' ' + line

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…