From: Karim Hamidou Date: Mon, 1 Feb 2016 04:42:33 +0000 (-0800) Subject: better rendering. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=47e0974797bed4fb584413dcab35ae27779af7fa;p=rfcspot.git better rendering. --- diff --git a/rfc.css b/rfc.css index 388a9fc3..4542b2e3 100644 --- a/rfc.css +++ b/rfc.css @@ -20,6 +20,7 @@ h1, h2, h3, h4, h5, h6 { } h3, h4, h5, h6 { margin-top: 20px; + font-size: 100%; } #container { position: relative; @@ -78,7 +79,6 @@ table td { text-align: left; } .docs pre { - margin: 15px 0 15px; font-size: 16px; line-height: 24px; font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif; diff --git a/src/format-rfc.py b/src/format-rfc.py index 13c33a7b..b0f67625 100644 --- a/src/format-rfc.py +++ b/src/format-rfc.py @@ -5,7 +5,7 @@ import re import sys import pystache -from bs4 import BeautifulSoup, Tag +from bs4 import BeautifulSoup, Tag, Comment from template import html_template class ProcessingException(Exception): @@ -16,6 +16,7 @@ def process_file(infile, outfile): with open(infile) as fd: data = fd.read() + data = data.replace('
', '') soup = BeautifulSoup(data, 'html.parser') title = soup.head.title.text @@ -24,22 +25,54 @@ def process_file(infile, outfile): [node.extract() for node in soup('style')] [node.extract() for node in soup('script')] + # Remove comments: + for comment in soup.find_all(): + if isinstance(comment, Comment): + comment.extract() + # Remove the first

tag --- we're already showing the title - node = soup.find('h1') - if node is not None: - node.extract() + match = soup.find('h1') + if match is not None: + match.extract() + + # Remove invisible anchors + for match in soup.findAll('a', class_='invisible'): + match.extract() + + # Remove those weird tags: + for tag in ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8', 'h9', 'h10']: + for match in soup.findAll('span', class_=tag): + match.replaceWithChildren() + + # Strip the blocks following this span. + for match in soup.findAll(tag): + sibling = match.next_sibling + + if sibling is not None: + sibling.string.replaceWith(sibling.string.strip('\n').rstrip('\n')) # Remove
tags: for match in soup.findAll('hr'): - match.replaceWithChildren() + if match is not None: + match.replaceWithChildren() + + # Merge the
 tags together.
+    first_tag = None
+    for match in soup.findAll('pre', class_='newpage'):
+        if first_tag is not None:
+            match.replaceWithChildren()
+            match.extract()
+            first_tag.append(match)
+
+        if first_tag is None:
+            first_tag = match
 
     # 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')
+    #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')