]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
better rendering.
authorKarim Hamidou <karim@MacBook.local>
Mon, 1 Feb 2016 04:42:33 +0000 (20:42 -0800)
committerKarim Hamidou <karim@MacBook.local>
Mon, 1 Feb 2016 04:42:33 +0000 (20:42 -0800)
rfc.css
src/format-rfc.py

diff --git a/rfc.css b/rfc.css
index 388a9fc3c22aa68a619b5d970933f336a9a0aa75..4542b2e3509cbfe411f398a1c534860c8ede8172 100644 (file)
--- 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;
index 13c33a7bae0d5e0b20004154326e36c100c75007..b0f676250059cb098932c84925c2deac90aeee92 100644 (file)
@@ -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('<br>', '')
     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 <h1> 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 <span class='h4'></span> 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 <hr> tags:
     for match in soup.findAll('hr'):
-        match.replaceWithChildren()
+        if match is not None:
+            match.replaceWithChildren()
+
+    # Merge the <pre class="newpage"> 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')