Skip to content

Commit 7d960ed

Browse files
Cleanup replace_special_variables
1 parent 2f66eb9 commit 7d960ed

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

web/scripts/builder.py

+1-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import http
66
import subprocess
77
import signal
8-
import re
98
from datetime import date
109
from pathlib import Path
1110

@@ -387,19 +386,6 @@ def create_element_page(self, element):
387386
html_file.write(html_content)
388387

389388
self.logger.info(f"Generated {output_path} for element {element['name']}")
390-
391-
def process_special_article_content(self, content):
392-
specials = re.findall(r'\{\{.*?\}\}', content)
393-
specials = [s[2:-2] for s in specials]
394-
for special in specials:
395-
if special == 'elements_list':
396-
html_list = "<ul>"
397-
for element in self.elements:
398-
html_list += f"<li><a href='{element['path_html']}'>{element['name'].capitalize()}</a></li>"
399-
html_list += "</ul>"
400-
content = content.replace(f"{{{{elements_list}}}}", html_list)
401-
402-
return content
403389

404390
def create_function_page(self, function):
405391
function_template = self.input_env.get_template('function.html')
@@ -417,7 +403,7 @@ def create_function_page(self, function):
417403

418404
def create_article_page(self, article):
419405
article_template = self.input_env.get_template('article.html')
420-
article["content_html"] = self.process_special_article_content(article["content_html"])
406+
article["content_html"] = utils.replace_special_variables(self, article["content_html"])
421407
html_content = self.render_page(article['title'], article_template.render(article=article))
422408

423409
article_folder = OUTPUT_HTML_PATH + article["path_html"]

web/scripts/utils.py

+18
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ def to_html(markdown_text, single_paragraph=False):
2424
if single_paragraph:
2525
html = re.sub(r'<p>(.*?)</p>', r'\1', html)
2626
return html
27+
28+
def replace_special_variables(wiki_builder, text):
29+
specials = re.findall(r'\{\{.*?\}\}', text)
30+
specials = [s[2:-2] for s in specials]
31+
for special in specials:
32+
r_text = None
33+
34+
# List of Element types
35+
if special == 'elements_list':
36+
r_text = "<ul>"
37+
for element in wiki_builder.elements:
38+
r_text += f"<li><a href='{element['path_html']}'>{element['name'].capitalize()}</a></li>"
39+
r_text += "</ul>"
40+
41+
if r_text:
42+
text = text.replace("{{" + special + "}}", r_text)
43+
44+
return text

0 commit comments

Comments
 (0)