Skip to content

Commit

Permalink
Now able to deal with special characters in labels for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gareth Aneurin Tribello authored and Gareth Aneurin Tribello committed May 11, 2024
1 parent b31a978 commit 6579103
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions PlumedToHTML/PlumedFormatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ def format(self, tokensource, outfile):
act_label=""
if "#NODEFAULT" in value :
if default_state!=0 : raise ValueError("Found rogue #NODEFAULT")
default_state, act_label = 1, value.replace("#NODEFAULT","").strip()
default_state, act_label = 1, html.escape( value.replace("#NODEFAULT","").strip() )
outfile.write('<span id="' + self.egname + "def" + act_label + '_short">')
elif "#ENDDEFAULT" in value :
if default_state!=2 : raise ValueError("Found rogue #ENDDEFAULT")
default_state = 0
outfile.write('</span>')
elif "#DEFAULT" in value :
if default_state!=1 : raise ValueError("Found rogue #DEFAULT")
act_label, default_state = value.replace("#DEFAULT","").strip(), 2
act_label, default_state = html.escape( value.replace("#DEFAULT","").strip() ), 2
outfile.write('</span><span id="' + self.egname + "def" + act_label + '_long" style="display:none;">')
elif "#SHORTCUT" in value :
if shortcut_depth==0 and shortcut_state!=0 : raise ValueError("Found rogue #SHORTCUT")
shortcut_state, shortcut_depth = 1, shortcut_depth + 1
act_label = value.replace("#SHORTCUT","").strip()
act_label = html.escape( value.replace("#SHORTCUT","").strip() )
outfile.write('<span id="' + self.egname + act_label + '_short">')
elif "#ENDEXPANSION" in value :
if shortcut_state!=2 : raise ValueError("Should only find #ENDEXPANSION tag after #EXPANSION tag")
shortcut_depth = shortcut_depth - 1
if shortcut_depth==0 : shortcut_state=0
act_label = value.replace("#ENDEXPANSION","").strip()
act_label = html.escape( value.replace("#ENDEXPANSION","").strip() )
# Now output the end of the expansion
outfile.write('<span style="color:blue"># --- End of included input --- </span></span>')
elif "#EXPANSION" in value :
if shortcut_state!=1 : raise ValueError("Should only find #EXPANSION tag after #SHORTCUT tag")
shortcut_state = 2
act_label, expansion_label = value.replace("#EXPANSION","").strip(), value.replace("#EXPANSION","").strip()
act_label, expansion_label = html.escape( value.replace("#EXPANSION","").strip() ), value.replace("#EXPANSION","").strip()
outfile.write('</span><span id="' + self.egname + act_label + '_long" style="display:none;">')
else : raise ValueError("Comment.Special should only catch string that are #SHORTCUT, #EXPANSION or #ENDEXPANSION")
# This sets up the label at the start of a new block with NODEFAULT or SHORTCUT
Expand Down Expand Up @@ -147,7 +147,7 @@ def format(self, tokensource, outfile):
elif ttype==String or ttype==String.Double :
# Labels of actions
if not self.broken and action!="" and label!="" and label!=value.strip() : raise Exception("label for " + action + " is not what is expected. Is " + label + " should be " + value.strip() )
elif label=="" : label = value.strip()
elif label=="" : label = html.escape( value.strip() )
valtype = "mix"
if label in self.valuedict.keys() :
valtype = "unset"
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.64',
version='0.65',
author="Gareth Tribello",
author_email="[email protected]",
description="A package for creating pretified HTML for PLUMED files",
Expand Down

0 comments on commit 6579103

Please sign in to comment.