]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
better diagrams
authorKarim Hamidou <karim@MacBook.local>
Sun, 6 Mar 2016 04:08:25 +0000 (20:08 -0800)
committerKarim Hamidou <karim@MacBook.local>
Sun, 6 Mar 2016 04:08:25 +0000 (20:08 -0800)
src/render_rfc.py
templates/rfc.html

index 1cd20761fbafa7d4a6b6e5b9794591a973b542f1..7a4c51984670e1255e5434ef1789629f694f8eda 100644 (file)
@@ -23,10 +23,13 @@ def remove_page_breaks(data):
 def create_paragraphs(data):
     paragraph_regexp = re.compile(r"(^.+?(\.|\:|;))\n\n", re.MULTILINE | re.DOTALL)
 
-    # replace the \n inside those paragraphs by <br> tags.
     data = paragraph_regexp.sub(r'<p class="rfcparagraph">\1</p>', data)
 
     return data
+    # replace the \n inside those paragraphs by <br> tags.
+    paragraph_pattern = re.compile(r'(<p class="rfcparagraph">.*?<\/p>)', re.MULTILINE | re.DOTALL)
+    return paragraph_pattern.sub(lambda match: match.group(0).replace('\n','<br>'), data)
+
 
 def create_diagram_blocks(data):
     # A diagram always starts by +-- and ends by ---+.
@@ -34,6 +37,18 @@ def create_diagram_blocks(data):
     data = diagram_regexp.sub(r'<pre>\1\n</pre>\n', data)
     return data
 
+
+def add_line_breaks_legends(data):
+    # RFC diagrams also have legends, of the form:
+    # (1) ...comment...\n
+    # This function replace \n by <br> to make the code more readable.
+    legends_linebreak = re.compile(r'(\(\d+\).+$)\n', re.MULTILINE)
+    data = legends_linebreak.sub(r'\1<br>\n', data)
+    return data
+
+def line_breaks_indented_blocks(data):
+    pass
+
 def anchor_titles(data):
     # Reverse section order because lvl1_title_rx matches the beginning of lvl2_title_rx
     # and lvl3_title_rx.
@@ -55,7 +70,8 @@ def render_rfc(filename):
 
     out = data
     for fn in [remove_top_space, remove_page_breaks,
-               anchor_titles, create_paragraphs, create_diagram_blocks]:
+               anchor_titles, create_paragraphs, create_diagram_blocks,
+               add_line_breaks_legends]:
         out = fn(out)
 
     env = Environment(loader=FileSystemLoader('templates'))
@@ -64,17 +80,6 @@ def render_rfc(filename):
     dct = dict(rfc=out)
     rendered = template.render(**dct)
 
-    # A little post-processing.
-    soup = BeautifulSoup(rendered, 'html.parser')
-    for match in soup.findAll('p', class_='rfcparagraph'):
-        try:
-            match.contents = [s.replace('\n', '<br />')
-                              for s in match.contents if s is not None]
-        except:
-            continue
-
-    rendered = soup.prettify()
-
     return rendered
     # return out
 
index 857e7213206263038ec9b654899b62353a22d018..08724af51254a4090d3684b95c9ce71a2be26960 100644 (file)
       </td>
       <td class=code>
         <div class='highlight'>
+            <!--
             <b>Related Stack Overflow questions:</b>
             <ul>
                 {% for question in questions %}
                     <li><a href={{ question['url'] }}>{{ question['title'] }}</a></li>
                 {% endfor %}
             </ul>
+            -->
         </div>
       </td>
     </tr>