Skip to content

Commit 61e6521

Browse files
author
Gareth Aneurin Tribello
committed
Added code to escape html characters in comments in input and also deleting so files after plumed has been run for testing
1 parent 7c53d32 commit 61e6521

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

PlumedToHTML/PlumedFormatter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pygments.formatter import Formatter
22
from pygments.token import Text, Comment, Literal, Keyword, Name, Generic, String
33
from requests.exceptions import InvalidJSONError
4+
import html
45
import json
56

67
class PlumedFormatter(Formatter):
@@ -156,7 +157,7 @@ def format(self, tokensource, outfile):
156157
outfile.write('<b name="' + self.egname + label + '" onclick=\'showPath("' + self.divname + '","' + self.egname + label + '","' + self.valcolors[valtype] + '")\'>' + value + '</b>')
157158
elif ttype==Comment :
158159
# Comments
159-
outfile.write('<span style="color:blue" class="comment">' + value + '</span>' )
160+
outfile.write('<span style="color:blue" class="comment">' + html.escape(value) + '</span>' )
160161
elif ttype==Name.Attribute :
161162
# KEYWORD in KEYWORD=whatever and FLAGS
162163
keywords.append( value.strip().upper() )

PlumedToHTML/PlumedToHTML.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ def test_plumed( executible, filename, header=[], shortcutfile=[], valuefile=[]
102102
with open(errtxtfile,"w") as stderr:
103103
with cd(run_folder):
104104
plumed_out = subprocess.run(cmd, text=True, stdout=stdout, stderr=stderr )
105+
# Remove *.so files from run folder to prevent clashes when we test with a different version of PLUMED
106+
for item in os.listdir( run_folder ) :
107+
if item.endswith(".so") : os.remove( os.path.join( run_folder, item ) )
105108
# write header and preamble to errfile
106109
with open(errfile,"w") as stderr:
107110
if len(header)>0 : print(header,file=stderr)
@@ -244,8 +247,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, actions=set({}) ) :
244247
try :
245248
etree.parse(StringIO(html), etree.HTMLParser(recover=False))
246249
except etree.XMLSyntaxError as e:
247-
pass
248-
#raise Exception("Generated html is invalid as " + str(e.error_log) ) from e
250+
raise Exception("Generated html is invalid as " + str(e.error_log) ) from e
249251

250252
# Check everything that is marked as a clickable value has something that will appear
251253
# when you click it

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setuptools.setup(
88
name='PlumedToHTML',
9-
version='0.58',
9+
version='0.59',
1010
author="Gareth Tribello",
1111
author_email="[email protected]",
1212
description="A package for creating pretified HTML for PLUMED files",

0 commit comments

Comments
 (0)