Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# coding: utf-8
'''
Para rodar
python3 markdown_to_json.py file1 file2
'''
import json
import sys
def parse(text):
output = []
paragraphs = list(filter(lambda line: len(line.strip('\n\t')) > 0 , text.split('\n')))
output.append({
'room': {
'title': paragraphs[0],
'subtitle': paragraphs[1],
'excerpt': paragraphs[2],
'content': '\n'.join(paragraphs[3:])
}
})
return output
def main():
filenames = sys.argv[1:]
for filename in filenames:
with open(filename, encoding='utf8') as fp:
read = fp.read()
parsed = parse(read)
with open(filename + '.json', 'w', encoding='utf-8') as file_output:
json.dump(parsed, file_output, indent=4, ensure_ascii=False)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.