Add Bootstrap grid classes to images referenced in the HTML docs.
authorJonathan S. Katz <jonathan.katz@excoventures.com>
Mon, 1 Apr 2019 01:40:03 +0000 (21:40 -0400)
committerJonathan S. Katz <jonathan.katz@excoventures.com>
Thu, 25 Apr 2019 21:21:44 +0000 (17:21 -0400)
tools/docs/docload.py

index 1f363c8025c53fe35bbebc7c0a5574885c22cb72..094d965141cf0f5b96e8a4ab13842ff8ac7c16e8 100755 (executable)
@@ -14,6 +14,8 @@ from configparser import ConfigParser
 
 import psycopg2
 
+# the Bootstrap grid classes that are added onto any images that are rendered in the docs
+BOOTSTRAP_FIGURE_CLASS = r'<div\1class="figure col-xl-8 col-lg-10 col-md-12"'
 # a counter that keeps track of the total number of pages (HTML, SVG) that are loaded
 # into the database
 pagecount = 0
@@ -22,6 +24,9 @@ quiet = False
 # regular expression used to search and extract the title on a given piece of
 # documentation, for further use in the application
 re_titlematch = re.compile('<title\s*>([^<]+)</title\s*>', re.IGNORECASE)
+# regular expression used to find any images that are in the HTML and apply
+# additional bootstrap classes
+re_figure_match = re.compile('<div([^<>]+)class="figure"', re.IGNORECASE)
 
 
 # Load a single page
@@ -67,6 +72,10 @@ def load_doc_file(filename, f, c):
     else:
         title = ""
 
+    # find any images that are embedded in the HTML and add in the Bootstrap grid classes
+    # in order to ensure they are able to display responsively
+    contents = re_figure_match.sub(BOOTSTRAP_FIGURE_CLASS, contents)
+
     # if not in quiet mode, output the (filename, title) pair of the docpage that is being processed
     if not quiet:
         print("--- file: %s (%s) ---" % (filename, title))