Commit aa04230c0edf5e95f65e9f387a8b1ee73790fa3a

Authored by Antoine Goutenoir
1 parent d230f8b1
Exists in master

feat: add support for icons, _the right way_©

You may now use any icon from
https://icons.getbootstrap.com/#icons

in the markdown, with the syntax: `<icon globe>`
Replace `globe` by the icon you want.
flaskr/__init__.py
@@ -34,6 +34,7 @@ from flaskr.extensions import ( @@ -34,6 +34,7 @@ from flaskr.extensions import (
34 mail, 34 mail,
35 session, 35 session,
36 captcha, 36 captcha,
  37 + icon2html,
37 ) 38 )
38 from flaskr.content import content 39 from flaskr.content import content
39 from flaskr.core import increment_hit_counter, get_hit_counter 40 from flaskr.core import increment_hit_counter, get_hit_counter
@@ -109,6 +110,7 @@ def create_app(object_name): @@ -109,6 +110,7 @@ def create_app(object_name):
109 # Markdown jinja2 filter 110 # Markdown jinja2 filter
110 @app.template_filter('markdown') 111 @app.template_filter('markdown')
111 def markdown_filter(text): 112 def markdown_filter(text):
  113 + text = icon2html(text)
112 return markdown(text, extensions=['extra']) 114 return markdown(text, extensions=['extra'])
113 115
114 # Authentication Gate for the Admin 116 # Authentication Gate for the Admin
flaskr/content.py
@@ -33,6 +33,7 @@ class Struct(object): @@ -33,6 +33,7 @@ class Struct(object):
33 33
34 content = Struct(content_dict) 34 content = Struct(content_dict)
35 35
  36 +# Move this to ENV, perhaps
36 base_url = "https://travel-footprint-calculator.irap.omp.eu" 37 base_url = "https://travel-footprint-calculator.irap.omp.eu"
37 38
38 39
flaskr/extensions.py
@@ -50,7 +50,6 @@ def load_user(userid): @@ -50,7 +50,6 @@ def load_user(userid):
50 50
51 51
52 def send_email(to_recipient, subject, message): 52 def send_email(to_recipient, subject, message):
53 -  
54 if 'production' != getenv('FLASK_ENV', 'production'): 53 if 'production' != getenv('FLASK_ENV', 'production'):
55 print("Skipping sending email because we are not in production.") 54 print("Skipping sending email because we are not in production.")
56 return 55 return
@@ -70,3 +69,12 @@ def send_email(to_recipient, subject, message): @@ -70,3 +69,12 @@ def send_email(to_recipient, subject, message):
70 print("ERROR Sending email:\n%s" % str(e)) 69 print("ERROR Sending email:\n%s" % str(e))
71 traceback.print_exc(file=sys.stderr) 70 traceback.print_exc(file=sys.stderr)
72 71
  72 +
  73 +def icon2html(text):
  74 + import re
  75 + icon_html = r"""<svg class="bi" width="16" height="16" fill="currentColor"><use xlink:href="/static/bootstrap-icons-1.0.0/bootstrap-icons.svg#\1"/></svg>"""
  76 + return re.sub(
  77 + "<icon +([^ ]+)>",
  78 + icon_html,
  79 + text
  80 + )
flaskr/static/css/common/main.css
@@ -160,4 +160,13 @@ span[title] { @@ -160,4 +160,13 @@ span[title] {
160 160
161 opacity: 0; 161 opacity: 0;
162 } 162 }
  163 +}
  164 +
  165 +
  166 +/** BOOTSTRAP ICONS **********************************************************/
  167 +
  168 +svg.bi {
  169 + /* vertical alignment is … sketchy, let's do this the old way */
  170 + position: relative;
  171 + top: 2px;
163 } 172 }
164 \ No newline at end of file 173 \ No newline at end of file