def render_components_into_file()

in olddocs/gen_edot_col_components/tools.py [0:0]


def render_components_into_file(dir, data, template, tag):    
    output = render_markdown(data, template)
    start_tag = f'<!-- start:{tag} -->'
    end_tag = f'<!-- end:{tag} -->'
    
    filesPaths = find_files_with_substring(dir, start_tag)
    
    for filePath in filesPaths:
        with open(filePath, 'r', encoding='utf-8') as file:
            content = file.read()
            
        pattern = start_tag + r'.*?' + end_tag
        new_content = f'{start_tag}\n{output}\n{end_tag}'
        updated_content = re.sub(pattern, new_content, content, flags=re.DOTALL)

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