Skip to content
Permalink
08355c6471
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 30 lines (19 sloc) 673 Bytes
#!/usr/bin/env python3
import sys
import re
includereg = re.compile( r"(?s)(```include)(.*?)(```)" )
filenamereg = re.compile( r"([\S]{1,})" )
def includeblocks( instream ):
outstream = ""
prev = 0
for i in includereg.finditer( instream ):
outstream += instream[prev:i.start()]
for f in filenamereg.finditer( i.group(2) ):
with open( f.group(1), "r" ) as file:
outstream += includeblocks( file.read() )
prev = i.end()
outstream += instream[prev:]
outstream += "\n\n"
return outstream
if __name__ == "__main__":
print( includeblocks( sys.stdin.read() ), file=sys.stdout, end="" )