I would encourage you to produce more explicit output, particularly with the filenames. If I wanted to reverse the process and scrape the code into files on my machine, using a Python script such as the following…
import json
from lxml import html
import re
import requests
FILENAME_HINT_XPATH = "../preceding-sibling::p[1]/strong/text()"
def code_for_post(site, post):
r = requests.get('https://api.stackexchange.com/2.1/posts/{1}?site={0}&filter=withbody'.format(site, post))
j = json.loads(r.text)
body = j['items'][0]['body']
tree = html.fromstring(body)
code_elements = tree.xpath("//pre/code[%s]" % (FILENAME_HINT_XPATH))
return dict((c.xpath(FILENAME_HINT_XPATH)[0], c.findtext(".")) for c in code_elements)
def write_files(code):
extension = '.java' # <-- Yuck, due to @Simon.
for filename_hint, content in code.iteritems():
filename = re.sub(r'[^A-Za-z0-9]', '', filename_hint) + extension
with open(filename, 'w') as f:
print >>f, content
write_files(code_for_post('codereview', 41198))
… then I would have to make assumptions about the filename extension.