Last active
September 15, 2023 15:37
-
-
Save sdarwin/ef0964e135599b937dfde1de9c868dd2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
# Replaces indented code with fenced code blocks | |
import re | |
import glob | |
skiplist=['doc/src/concepts.md', 'doc/src/faq.md'] | |
def replfunction1(matchobj): | |
matchedstring=matchobj.group(0) | |
matchedstring=matchedstring.strip() | |
matchedstring=re.sub('^ ', '', matchedstring, flags=re.MULTILINE) | |
matchedstring="\n```cpp" + "\n" + matchedstring + "\n" + "```\n\n" | |
return(matchedstring) | |
def replfunction2(matchobj): | |
matchedstring=matchobj.group(0) | |
print("matched string is \n") | |
print(matchedstring) | |
matchedstring=matchedstring.strip() | |
matchedstring=matchedstring + " " | |
matchedstring = re.sub('^/// ', '', matchedstring, flags=re.MULTILINE) | |
matchedstring = re.sub('^\s*\n(\s{4}.*$)+\n*', replfunction1, matchedstring, flags=re.MULTILINE) | |
matchedstring=matchedstring.strip() | |
matchedstring=matchedstring + "\n" | |
matchedstring=re.sub('^', '/// ', matchedstring, flags=re.MULTILINE) | |
matchedstring=re.sub('^/// ///$', '/// ', matchedstring, flags=re.MULTILINE) | |
matchedstring="\n" + matchedstring + "\n\n" | |
return(matchedstring) | |
for filename in glob.glob('doc/**/*.md',recursive=True): | |
if filename not in skiplist: | |
print("Name is " + filename) | |
file = open(filename, 'r+') | |
Lines = file.read() | |
result = re.sub('^\s*\n(\s{4}.*$)+\n*',replfunction1,Lines,flags=re.MULTILINE) | |
file.seek(0) | |
file.truncate() | |
file.write(result) | |
file.close() | |
for filename in glob.glob('**/*.hpp',recursive=True): | |
print("Name is " + filename) | |
file = open(filename, 'r+') | |
Lines = file.read() | |
result = re.sub('^(\s*///.*$)+\n*',replfunction2,Lines,flags=re.MULTILINE) | |
file.seek(0) | |
file.truncate() | |
file.write(result) | |
file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment