-
-
Save orisano/95b0d59bed94234762d77be808c752a8 to your computer and use it in GitHub Desktop.
This file contains 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 glob | |
import re | |
import subprocess | |
def main(): | |
for md_path in glob.glob("./docs/**/*.md"): | |
md = open(md_path).read() | |
begin = 0 | |
while True: | |
p = md.find("```go\n", begin) | |
if p == -1: | |
break | |
code = md[p + 6 :] | |
code = code[: code.find("```")] | |
proc = subprocess.run(["gofmt"], input=code.encode(), capture_output=True) | |
md = md[: p + 6] + proc.stdout.decode() + md[p + 6 + len(code) :] | |
begin = p + len(proc.stdout.decode()) + 3 | |
open(md_path, "w").write(md) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment