Last active
June 7, 2021 09:06
-
-
Save Sansui233/072a4fadffb8e258cf5caf05965041b9 to your computer and use it in GitHub Desktop.
fix indentation destroyed by logseq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import os | |
| one = re.compile(r'(\t )+') | |
| two = re.compile(r'(\t\t )+') | |
| three = re.compile(r'(\t\t\t )+') | |
| four = re.compile(r'(\t\t\t\t )+') | |
| five = re.compile(r'(\t\t\t\t\t )+') | |
| six = re.compile(r'(\t\t\t\t\t\t\t )+') | |
| def replaceFile(f): | |
| lines = f.readlines() | |
| f.seek(0,0) | |
| for line in lines: | |
| line = re.sub(one, "\t ",line) | |
| line = re.sub(two, "\t\t ",line) | |
| line = re.sub(three, "\t\t\t ",line) | |
| line = re.sub(four, "\t\t\t\t ",line) | |
| line = re.sub(five, "\t\t\t\t\t ",line) | |
| line = re.sub(six, "\t\t\t\t\t\t ",line) | |
| f.write(line) | |
| f.truncate() | |
| # ====================== | |
| # ======== MAIN ======== | |
| # ====================== | |
| exclude = [".DS_Store"] | |
| page_dir = os.walk(r"./pages") | |
| for path,dir_list,file_list in page_dir: | |
| for file_name in file_list: | |
| if file_name not in exclude: | |
| print(os.path.join(path, file_name)) | |
| f = open(os.path.join(path, file_name), 'r+') | |
| replaceFile(f) | |
| f.close() | |
| page_dir = os.walk(r"./journals") | |
| for path,dir_list,file_list in page_dir: | |
| for file_name in file_list: | |
| if file_name not in exclude: | |
| print(os.path.join(path, file_name)) | |
| f = open(os.path.join(path, file_name), 'r+') | |
| replaceFile(f) | |
| f.close() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue details HERE