Skip to content

Commit

Permalink
Added code to escape html characters in comments in input and also de…
Browse files Browse the repository at this point in the history
…leting so files after plumed has been run for testing
  • Loading branch information
Gareth Aneurin Tribello committed May 9, 2024
1 parent 7c53d32 commit 61e6521
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion PlumedToHTML/PlumedFormatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pygments.formatter import Formatter
from pygments.token import Text, Comment, Literal, Keyword, Name, Generic, String
from requests.exceptions import InvalidJSONError
import html
import json

class PlumedFormatter(Formatter):
Expand Down Expand Up @@ -156,7 +157,7 @@ def format(self, tokensource, outfile):
outfile.write('<b name="' + self.egname + label + '" onclick=\'showPath("' + self.divname + '","' + self.egname + label + '","' + self.valcolors[valtype] + '")\'>' + value + '</b>')
elif ttype==Comment :
# Comments
outfile.write('<span style="color:blue" class="comment">' + value + '</span>' )
outfile.write('<span style="color:blue" class="comment">' + html.escape(value) + '</span>' )
elif ttype==Name.Attribute :
# KEYWORD in KEYWORD=whatever and FLAGS
keywords.append( value.strip().upper() )
Expand Down
6 changes: 4 additions & 2 deletions PlumedToHTML/PlumedToHTML.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def test_plumed( executible, filename, header=[], shortcutfile=[], valuefile=[]
with open(errtxtfile,"w") as stderr:
with cd(run_folder):
plumed_out = subprocess.run(cmd, text=True, stdout=stdout, stderr=stderr )
# Remove *.so files from run folder to prevent clashes when we test with a different version of PLUMED
for item in os.listdir( run_folder ) :
if item.endswith(".so") : os.remove( os.path.join( run_folder, item ) )
# write header and preamble to errfile
with open(errfile,"w") as stderr:
if len(header)>0 : print(header,file=stderr)
Expand Down Expand Up @@ -244,8 +247,7 @@ def get_html( inpt, name, outloc, tested, broken, plumedexe, actions=set({}) ) :
try :
etree.parse(StringIO(html), etree.HTMLParser(recover=False))
except etree.XMLSyntaxError as e:
pass
#raise Exception("Generated html is invalid as " + str(e.error_log) ) from e
raise Exception("Generated html is invalid as " + str(e.error_log) ) from e

# Check everything that is marked as a clickable value has something that will appear
# when you click it
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setuptools.setup(
name='PlumedToHTML',
version='0.58',
version='0.59',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down

0 comments on commit 61e6521

Please sign in to comment.