Skip to content

Commit 4eff308

Browse files
Gareth Aneurin TribelloGareth Aneurin Tribello
authored andcommitted
Renamed tooltips and modals in plumed input files to plumedtooltip and plumedmodal
This prevents clashes between tooltip instructions that might already be in css files and the ones that we use for our rendered inputs
1 parent 66be1a5 commit 4eff308

File tree

6 files changed

+77
-31
lines changed

6 files changed

+77
-31
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
55

66
[project]
77
name = "PlumedToHTML"
8-
version = "0.101"
8+
version = "0.102"
99
description = "A package for creating prettified HTML for PLUMED files"
1010
authors = [{ name = "Gareth Tribello", email = "[email protected]" }]
1111
maintainers = [{ name = "Daniele Rapetti", email = "[email protected]" }]

src/PlumedToHTML/PlumedFormatter.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def format(self, tokensource, outfile):
7070
outfile.write('<span style="background-color:yellow">__FILL__</span>')
7171
# This is for vim syntax expression
7272
elif "vim:" in value :
73-
outfile.write('<span class="tooltip" style="color:blue">' + value + '<span class="right">Enables syntax highlighting for PLUMED files in vim. See <a href="' + self.keyword_dict["vimlink"] + '">here for more details. </a><i></i></span></span>')
73+
outfile.write('<span class="plumedtooltip" style="color:blue">' + value + '<span class="right">Enables syntax highlighting for PLUMED files in vim. See <a href="' + self.keyword_dict["vimlink"] + '">here for more details. </a><i></i></span></span>')
7474
else : raise ValueError("found invalid Literal in input " + value)
7575
elif ttype==Comment.Hashbang :
7676
# This handles the mechanism for closing the expanding shortcut
@@ -157,14 +157,14 @@ def format(self, tokensource, outfile):
157157
for kk in range(start,end+1) :
158158
if kk<=len(allines) : shortversion += allines[kk-1] + "\n"
159159
fcontent = shortversion
160-
outfile.write('<div class="tooltip">' + inp + '<div class="right"> Click <a onclick=\'openModal("' + self.egname + inp + str(nfiles) + '")\'>here</a> to see an extract from this file.<i></i></div></div>')
161-
outfile.write('<div id="' + self.egname + inp + str(nfiles) + '" class="modal">')
162-
outfile.write(' <div class="modal-content">')
163-
outfile.write('<div class="modal-header">')
160+
outfile.write('<div class="plumedtooltip">' + inp + '<div class="right"> Click <a onclick=\'openModal("' + self.egname + inp + str(nfiles) + '")\'>here</a> to see an extract from this file.<i></i></div></div>')
161+
outfile.write('<div id="' + self.egname + inp + str(nfiles) + '" class="plumedmodal">')
162+
outfile.write(' <div class="plumedmodal-content">')
163+
outfile.write('<div class="plumedmodal-header">')
164164
outfile.write(' <span class="close" onclick=\'closeModal("' + self.egname + inp + str(nfiles) + '")\'>&times;</span>')
165165
outfile.write(' <h2>FILE: ' + inp + '</h2>')
166166
outfile.write('</div>')
167-
outfile.write('<div class="modal-body">')
167+
outfile.write('<div class="plumedmodal-body">')
168168
outfile.write(' <pre>' + fcontent + '</pre>')
169169
outfile.write('</div>')
170170
outfile.write(' </div>')
@@ -185,7 +185,7 @@ def format(self, tokensource, outfile):
185185
else :
186186
select = inp.strip()
187187
if select in self.keyword_dict["groups"] : tooltip, link = self.keyword_dict["groups"][select]["description"], self.keyword_dict["groups"][select]["link"]
188-
if len(tooltip)>0 : outfile.write('<span class="tooltip">' + inp + '<span class="right">' + tooltip + '. <a href="' + link + '">Click here</a> for more information. <i></i></span></span>')
188+
if len(tooltip)>0 : outfile.write('<span class="plumedtooltip">' + inp + '<span class="right">' + tooltip + '. <a href="' + link + '">Click here</a> for more information. <i></i></span></span>')
189189
else : outfile.write( html.escape(inp) )
190190
else : outfile.write( html.escape(inp) )
191191
nocomma = False
@@ -238,15 +238,15 @@ def format(self, tokensource, outfile):
238238
if "actionlink" in self.keyword_dict[action]["syntax"][mykey].keys() and self.keyword_dict[action]["syntax"][mykey]["actionlink"]!="none" :
239239
linkaction = self.keyword_dict[action]["syntax"][mykey]["actionlink"]
240240
desc = desc + ". Options for this keyword are explained in the documentation for <a href=\"" + self.keyword_dict[linkaction]["hyperlink"] + "\">" + linkaction + "</a>.";
241-
outfile.write('<span class="tooltip">' + value + '<span class="right">' + desc + '<i></i></span></span>')
241+
outfile.write('<span class="plumedtooltip">' + value + '<span class="right">' + desc + '<i></i></span></span>')
242242
elif ttype==Name.Constant :
243243
# @replicas in special replica syntax
244244
if value=="@replicas:" :
245-
outfile.write('<span class="tooltip">' + value + '<span class="right">This keyword specifies that different replicas have different values for this quantity. See <a href="' + self.keyword_dict["replicalink"] +'">here for more details.</a><i></i></span></span>')
245+
outfile.write('<span class="plumedtooltip">' + value + '<span class="right">This keyword specifies that different replicas have different values for this quantity. See <a href="' + self.keyword_dict["replicalink"] +'">here for more details.</a><i></i></span></span>')
246246
# Deal with external libraries doing atom selections
247247
else :
248248
if value not in self.keyword_dict["groups"] : raise Exception("special group " + value + " not in special group dictionary")
249-
outfile.write('<span class="tooltip">' + value + '<span class="right">' + self.keyword_dict["groups"][value]["description"] + '. <a href="' + self.keyword_dict["groups"][value]["link"] + '">Click here</a> for more information. <i></i></span></span>');
249+
outfile.write('<span class="plumedtooltip">' + value + '<span class="right">' + self.keyword_dict["groups"][value]["description"] + '. <a href="' + self.keyword_dict["groups"][value]["link"] + '">Click here</a> for more information. <i></i></span></span>');
250250
elif ttype==Keyword :
251251
# Name of action
252252
action, notooltips = value.strip().upper(), False
@@ -259,20 +259,20 @@ def format(self, tokensource, outfile):
259259
if default_state!=0 or shortcut_state==1 :
260260
if label!="" and label!=act_label : raise Exception("mismatched label and act_label for shortcut/default")
261261
if notooltips :
262-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">This action is not part of PLUMED and was included by using a LOAD command <a href="' + self.keyword_dict["LOAD"]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
262+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">This action is not part of PLUMED and was included by using a LOAD command <a href="' + self.keyword_dict["LOAD"]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
263263
elif shortcut_state==1 and default_state==1 :
264-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + label + '");\'>a shortcut</a> and it has <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>hidden defaults</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
264+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + label + '");\'>a shortcut</a> and it has <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>hidden defaults</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
265265
elif shortcut_state==1 and default_state==2 :
266-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>a shortcut</a> and uses the <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>defaults shown here</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
266+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>a shortcut</a> and uses the <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>defaults shown here</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
267267
elif default_state==1 :
268-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action has <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>hidden defaults</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
268+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action has <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>hidden defaults</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
269269
elif default_state==2 :
270-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action uses the <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>defaults shown here</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
270+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action uses the <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + "def" + act_label + '");\'>defaults shown here</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
271271
elif shortcut_state==1 :
272-
if action=="INCLUDE" : outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a>. Show <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>included file</a><i></i></span></span>')
273-
else : outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>a shortcut</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
272+
if action=="INCLUDE" : outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a>. Show <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>included file</a><i></i></span></span>')
273+
else : outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">' + self.keyword_dict[action]["description"] + ' This action is <a class="toggler" href=\'javascript:;\' onclick=\'toggleDisplay("' + self.egname + act_label + '");\'>a shortcut</a>. <a href="' + self.keyword_dict[action]["hyperlink"] + '">More details</a><i></i></span></span>')
274274
else :
275-
outfile.write('<span class="tooltip" style="color:green">' + value.strip() + '<span class="right">'+ self.keyword_dict[action]["description"] + ' <a href="' + self.keyword_dict[action]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
275+
outfile.write('<span class="plumedtooltip" style="color:green">' + value.strip() + '<span class="right">'+ self.keyword_dict[action]["description"] + ' <a href="' + self.keyword_dict[action]["hyperlink"] + '" style="color:green">More details</a><i></i></span></span>')
276276
# Check if there is stuff to output for the last action in the file
277277
if len(label)>0 and label not in all_labels and label not in self.valuedict.keys() :
278278
all_labels.add( label )

src/PlumedToHTML/PlumedToHTML.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,40 @@ def get_html_header() :
466466
hfile.close()
467467
return codes
468468

469+
def get_javascript() :
470+
"""
471+
Get the javascript from the header of the html file to make the interactive PLUMED inputs work
472+
"""
473+
inscript, fullheader, jscode = False, get_html_header().splitlines(), ""
474+
for line in fullheader :
475+
if "</script>" in line and inscript :
476+
inscript = False
477+
break
478+
elif "<script>" in line :
479+
inscript = True
480+
elif inscript :
481+
if ("<style>" in line) or ("</style>" in line) or ("<script>" in line) or ("</script>" in line) :
482+
raise Exception('found invalid html tag in javascript line ' + line)
483+
jscode += line + "\n"
484+
return jscode
485+
486+
def get_css() :
487+
"""
488+
Get the css from the header of the html file to make the interactive PLUMED inputs work
489+
"""
490+
inscript, fullheader, css = False, get_html_header().splitlines(), ""
491+
for line in fullheader :
492+
if "</style>" in line and inscript :
493+
inscript = False
494+
break
495+
elif "<style>" in line :
496+
inscript = True
497+
elif inscript :
498+
if ("<style>" in line) or ("</style>" in line) or ("<script>" in line) or ("</script>" in line) :
499+
raise Exception('found invalid html tag in css line ' + line)
500+
css += line + "\n"
501+
return css
502+
469503
def compare_to_reference( output, reference ) :
470504
"""
471505
Compare the html that is output by PlumedFormatter with the reference data. This function is used for
@@ -483,7 +517,7 @@ def compare_to_reference( output, reference ) :
483517
# Check that everything that should be rendered as a tooltip has been rendered as a tooltip
484518
# This is action names and keywords
485519
if "tooltips" in reference.keys() :
486-
soup_tooltips = soup.find_all(attrs={'class': 'tooltip'})
520+
soup_tooltips = soup.find_all(attrs={'class': 'plumedtooltip'})
487521
print("CHECK TOOLTIP", soup_tooltips )
488522
print("TOOLTIP NUMBER CORRECT", len(soup_tooltips), len(reference["tooltips"]))
489523
if len(soup_tooltips)!=len(reference["tooltips"]) : return False

src/PlumedToHTML/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .PlumedToHTML import test_plumed, test_and_get_html, get_html, get_html_header, compare_to_reference, get_mermaid, processMarkdown
1+
from .PlumedToHTML import test_plumed, test_and_get_html, get_html, get_html_header, compare_to_reference, get_mermaid, processMarkdown, get_javascript, get_css

src/PlumedToHTML/assets/header.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
font-family: monospace, fixed;
1212
font-size: 105%;
1313
}
14-
.tooltip {
14+
.plumedtooltip {
1515
display:inline-block;
1616
position:relative;
1717
border-bottom:1px dotted #666;
1818
text-align:left;
1919
}
20-
.tooltip .right {
20+
.plumedtooltip .right {
2121
min-width:400px;
2222
white-space: normal;
2323
top:50%;
@@ -36,10 +36,10 @@
3636
box-shadow:0 1px 8px rgba(0,0,0,0.5);
3737
display:none;
3838
}
39-
.tooltip:hover .right {
39+
.plumedtooltip:hover .right {
4040
display:block;
4141
}
42-
.tooltip .right i {
42+
.plumedtooltip .right i {
4343
position:absolute;
4444
top:50%;
4545
right:100%;
@@ -48,7 +48,7 @@
4848
height:24px;
4949
overflow:hidden;
5050
}
51-
.tooltip .right i::after {
51+
.plumedtooltip .right i::after {
5252
content:;
5353
position:absolute;
5454
width:12px;
@@ -59,7 +59,7 @@
5959
background-color:#EEEEEE;
6060
box-shadow:0 1px 8px rgba(0,0,0,0.5);
6161
}
62-
.modal {
62+
.plumedmodal {
6363
display: none; /* Hidden by default */
6464
position: fixed; /* Stay in place */
6565
z-index: 1; /* Sit on top */
@@ -71,13 +71,13 @@
7171
background-color: rgb(0,0,0); /* Fallback color */
7272
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
7373
}
74-
.modal-header {
74+
.plumedmodal-header {
7575
padding: 2px 16px;
7676
background-color: #5cb85c;
7777
color: white;
7878
}
79-
.modal-body {padding: 2px 16px;}
80-
.modal-content {
79+
.plumedmodal-body {padding: 2px 16px;}
80+
.plumedmodal-content {
8181
position: relative;
8282
background-color: #fefefe;
8383
margin: auto;
@@ -134,4 +134,3 @@
134134
}
135135
}
136136
</script>
137-

tests/test_markdown.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,16 @@ def testHeader(self) :
6767
codes = hfile.read()
6868
hfile.close()
6969
self.assertTrue( codes==PlumedToHTML.get_html_header() )
70+
71+
def testJavascriptAndCSS(self) :
72+
headerfilename = os.path.join(os.path.dirname(__file__),"../src/PlumedToHTML/assets/header.html")
73+
hfile = open( headerfilename )
74+
codes = hfile.read()
75+
hfile.close()
76+
reference = "<style>\n"
77+
reference += PlumedToHTML.get_css()
78+
reference += "</style>\n<script>\n"
79+
reference += PlumedToHTML.get_javascript()
80+
reference += "</script>\n"
81+
print( reference )
82+
self.assertTrue( codes==reference )

0 commit comments

Comments
 (0)