From ccb11d4f2a5de2580848f5c46f113c31e401eb93 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 14 Mar 2017 19:57:13 +0000 Subject: [PATCH] Format output code --- .gitignore | 2 ++ requirements.txt | 1 + ymd/main.py | 9 +++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 72364f9..5462163 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,5 @@ ENV/ # Rope project settings .ropeproject + +test.html diff --git a/requirements.txt b/requirements.txt index 449a103..afba7a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +beautifulsoup4==4.5.3 Jinja2==2.9.5 Markdown==2.6.8 PyYAML==3.12 diff --git a/ymd/main.py b/ymd/main.py index 58252d9..50b9332 100644 --- a/ymd/main.py +++ b/ymd/main.py @@ -2,6 +2,8 @@ from jinja2 import Template import yaml import markdown from io import StringIO +import os +from bs4 import BeautifulSoup def parse_item(item, h): @@ -41,6 +43,9 @@ with open('test.yml') as f: with StringIO() as rendered: output(parse_item(formatted[1], 1), rendered) - with open('test.html', 'w') as f: - f.write(rendered.getvalue()) + + soup = BeautifulSoup(rendered.getvalue(), 'html.parser') + os.remove('test.html') + with open('test.html', 'w') as f: + f.write(soup.prettify())