From a3a50fde8aa88826d3ba2b008548b258211d79bc Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Sat, 5 Mar 2016 20:08:25 -0800 Subject: [PATCH] better diagrams --- src/render_rfc.py | 31 ++++++++++++++++++------------- templates/rfc.html | 2 ++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/render_rfc.py b/src/render_rfc.py index 1cd20761..7a4c5198 100644 --- a/src/render_rfc.py +++ b/src/render_rfc.py @@ -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
tags. data = paragraph_regexp.sub(r'

\1

', data) return data + # replace the \n inside those paragraphs by
tags. + paragraph_pattern = re.compile(r'(

.*?<\/p>)', re.MULTILINE | re.DOTALL) + return paragraph_pattern.sub(lambda match: match.group(0).replace('\n','
'), 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'

\1\n
\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
to make the code more readable. + legends_linebreak = re.compile(r'(\(\d+\).+$)\n', re.MULTILINE) + data = legends_linebreak.sub(r'\1
\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', '
') - for s in match.contents if s is not None] - except: - continue - - rendered = soup.prettify() - return rendered # return out diff --git a/templates/rfc.html b/templates/rfc.html index 857e7213..08724af5 100644 --- a/templates/rfc.html +++ b/templates/rfc.html @@ -22,12 +22,14 @@
+
-- 2.43.0