doc: Simply use dom parser to insert head section
[charm.git] / doc / markupSanitizer.py
index d46e95adb0673aa615896ccb9b35abfef5ee0acb..247f81c1dfee7f387d81f36b561069c5d6bb645b 100755 (executable)
@@ -33,10 +33,11 @@ navmenu = soup.find('div', 'navigation')
 if navmenu:
     navmenu.extract()
 
-# Wrap the remaining contents with a div
-soup.body['class'] = 'maincontainer'
-soup.body.name = 'div'
-soup.find('div','maincontainer').wrap( soup.new_tag('body') )
+# Wrap the remaining contents within a div
+if not soup.find('div', id='maincontainer'):
+    soup.body['id'] = 'maincontainer'
+    soup.body.name = 'div'
+    soup.find('div', id='maincontainer').wrap( soup.new_tag('body') )
 
 if navmenu:
     # If this navmenu doesn't already have a TOC, insert one
@@ -48,6 +49,15 @@ if navmenu:
     # Reinsert the navigation bar at the end
     soup.body.append(navmenu)
 
+# Extract the title
+titl = soup.find('title')
+
+# Replace the head section with the user-supplied head markup
+soup.find('head').extract()
+newhead = BeautifulSoup(open("../assets/head.html"), "lxml")
+newhead = newhead.find('head').extract()
+soup.html.body.insert_before(newhead)
+
 # Print cleaned up markup to stdout
 print( soup.prettify(formatter="html") )