@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')
return """<p class="rfcparagraph">{}</p>""".format(paragraph)
-
data = paragraph_regexp.sub(format_match, data)
return data
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)
<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>