Skip to content

Instantly share code, notes, and snippets.

@Sansui233
Last active June 7, 2021 09:06
Show Gist options
  • Select an option

  • Save Sansui233/072a4fadffb8e258cf5caf05965041b9 to your computer and use it in GitHub Desktop.

Select an option

Save Sansui233/072a4fadffb8e258cf5caf05965041b9 to your computer and use it in GitHub Desktop.
fix indentation destroyed by logseq
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()
@Sansui233
Copy link
Author

Issue details HERE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment