From 29bf513fb097e12f71008554ac7c0298aaa3e0a6 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Sat, 30 Jan 2016 22:39:34 -0800 Subject: [PATCH] rendering looks prettier now. --- rfc.css | 10 +++++----- src/format-rfc.py | 23 +++++++++++++++++++++-- src/template.py | 3 --- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/rfc.css b/rfc.css index d0156945..388a9fc3 100644 --- a/rfc.css +++ b/rfc.css @@ -27,8 +27,6 @@ h1, h2, h3, h4, h5, h6 { #background { position: fixed; top: 0; left: 580px; right: 0; bottom: 0; - background: #f5f5ff; - border-left: 1px solid #e5e5ee; z-index: -1; } #jump_to, #jump_page { @@ -72,8 +70,8 @@ table td { outline: 0; } td.docs, th.docs { - max-width: 500px; - min-width: 500px; + max-width: 600px; + min-width: 600px; min-height: 5px; padding: 10px 25px 1px 50px; vertical-align: top; @@ -81,7 +79,9 @@ table td { } .docs pre { margin: 15px 0 15px; - padding-left: 15px; + font-size: 16px; + line-height: 24px; + font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; } .docs p tt, .docs p code { background: #f8f8ff; diff --git a/src/format-rfc.py b/src/format-rfc.py index 0a174e65..13c33a7b 100644 --- a/src/format-rfc.py +++ b/src/format-rfc.py @@ -2,9 +2,10 @@ # -*- coding: utf-8 -*- # This script takes an HTML RFC as input and formats it in a prettier # format. +import re import sys import pystache -from bs4 import BeautifulSoup +from bs4 import BeautifulSoup, Tag from template import html_template class ProcessingException(Exception): @@ -20,8 +21,25 @@ def process_file(infile, outfile): title = soup.head.title.text # Remove useless formatting: [node.extract() for node in soup('span', class_='grey')] - # [node.extract() for node in soup('hr', class_='noprint')] + [node.extract() for node in soup('style')] + [node.extract() for node in soup('script')] + # Remove the first

tag --- we're already showing the title + node = soup.find('h1') + if node is not None: + node.extract() + + # Remove
tags: + for match in soup.findAll('hr'): + match.replaceWithChildren() + + # Once we've got rid of everything, remove consecutive blank lines: + new_lines = re.compile('(\w*\n){3,99}') + re_serialized = soup.prettify() + contents = re.sub(new_lines, '\n\n', re_serialized) + soup = BeautifulSoup(contents, 'html.parser') + + # Find the first pre tag and extract # Finally, extract the body: body_contents = soup.body.find('div', class_='content') @@ -30,6 +48,7 @@ def process_file(infile, outfile): dct = dict(rfc=body_contents.prettify(), title=title) rendered = pystache.render(html_template, dct) + with open(outfile, 'w+') as fd: fd.write(rendered.encode('utf-8')) diff --git a/src/template.py b/src/template.py index 4a7a9fdb..3ca912d3 100644 --- a/src/template.py +++ b/src/template.py @@ -19,9 +19,6 @@ html_template = """\ -
- # -
{{{ rfc }}} -- 2.43.0