]> khamidou — GitHub mirrors - rfcspot.git/commitdiff
turn rfc references to links
authorKarim Hamidou <khamidou@gmail.com>
Sun, 20 Mar 2016 01:29:05 +0000 (18:29 -0700)
committerKarim Hamidou <khamidou@gmail.com>
Sun, 20 Mar 2016 01:29:05 +0000 (18:29 -0700)
app.py
src/render_rfc.py
templates/index.html

diff --git a/app.py b/app.py
index 76cedb96a7d0c0689ba3c22db3381be3da5ccc08..2e5826cfbe09c6d12dc1f995ceb46e3b7d2f31f9 100644 (file)
--- a/app.py
+++ b/app.py
@@ -31,7 +31,7 @@ def home():
 @app.route('/rfc<int:rfc_number>.html')
 def render_text_rfc(rfc_number):
     filename = 'text/rfc{}.txt'.format(rfc_number)
-    rendered = render_html_rfc(filename)
+    rendered = render_html_rfc(filename, metadata)
     return render_template('rfc.html', **rendered)
 
 @app.route('/browse')
index 6378f4b845b2f20c674fc5c43dd48805162d5feb..a18d3b606fb39573de8e7be7f43de37c17a1b77a 100644 (file)
@@ -86,7 +86,6 @@ def create_paragraphs(data, **kwargs):
 
         return """<p class="rfcparagraph">{}</p>""".format(paragraph)
 
-
     data = paragraph_regexp.sub(format_match, data)
 
     return data
@@ -138,16 +137,34 @@ def anchor_titles(data, **kwargs):
     return data
 
 
-def render_html_rfc(filename):
+def replace_rfc_by_link(data, **kwargs):
+    rfc_metadata = kwargs['rfcs']
+
+    def format_match(match):
+        rfc_num = match.group(1)
+        title = ""
+        if rfc_num in rfc_metadata:
+            title = rfc_metadata[rfc_num].get('subject', '')
+
+        return """<a href="/rfc{num}.html" title="{subject}">RFC {num}</a>""".format(num=rfc_num,
+                                                                                     subject=title)
+
+    rfc_regexp = re.compile(r'RFC\s*(\d+)', re.MULTILINE | re.IGNORECASE)
+    data = rfc_regexp.sub(format_match, data)
+    return data
+
+
+def render_html_rfc(filename, rfc_metadata):
     with open(filename) as fd:
         data = fd.read()
 
     out = data
-    opts = dict(filename=filename)
+    opts = dict(filename=filename, rfcs=rfc_metadata)
 
     for fn in [remove_top_space, cleanup_author_header, remove_page_breaks,
                anchor_titles, create_paragraphs,
-               add_line_breaks_legends, cleanup_toc, create_diagram_blocks]:
+               add_line_breaks_legends, cleanup_toc, create_diagram_blocks,
+               replace_rfc_by_link]:
         out = fn(out, **opts)
 
     dct = dict(rfc=out)
index 14739b4ea1fe8510358a4f5aab8e5ec6d7ec3442..5ceb396754d543c0fa5ed0cfd7999a4aa3a24ea1 100644 (file)
@@ -41,7 +41,7 @@
 
         <hr>
         <h5>Who is behind this?</h5>
-        <p><a href="http://khamidou.com">Karim Hamidou</a>. I'm a backend engineer and have to spend a lot of time reading RFCs. Unfortunately, most of them are really ugly and hard to understand without proper context.</p>
+        <p>Hi, I'm <a href="http://khamidou.com">Karim</a>! I'm a backend engineer and have to spend a lot of time reading RFCs. Unfortunately, most of them are really ugly and hard to understand without proper context.</p>
 
         <h5>Special thanks:</h5>