Skip to content

Instantly share code, notes, and snippets.

@andrew-serrano
Last active April 7, 2020 02:00
Show Gist options
  • Save andrew-serrano/be5610b9d89b099615c4b581af7ef082 to your computer and use it in GitHub Desktop.
Save andrew-serrano/be5610b9d89b099615c4b581af7ef082 to your computer and use it in GitHub Desktop.
Miva Remove HTML comments
<mvt:comment>
I/O
</mvt:comment>
<mvt:assign name="l.input_string" value="'Place value here'" />
<mvt:assign name="l.output_string" value="''" />
<mvt:comment>
Tokens
</mvt:comment>
<mvt:assign name="l.start_comment" value="'<!--'" />
<mvt:assign name="l.start_comment_len" value="len_var(l.start_comment)" />
<mvt:assign name="l.end_comment" value="'-->'" />
<mvt:assign name="l.end_comment_len" value="len_var(l.end_comment)" />
<mvt:comment>
Helpers
</mvt:comment>
<mvt:assign name="l.input_string_len" value="len(l.input_string)" />
<mvt:assign name="l.pointer" value="1" />
<mvt:comment>
Flags
</mvt:comment>
<mvt:assign name="l.COMMENT_MODE" value="0" />
<mvt:assign name="l.COMMENT_START" value="0" />
<mvt:assign name="l.COMMENT_END" value="0" />
<mvt:comment>
Iterate over each character
</mvt:comment>
<mvt:while expr="l.pointer LE l.input_string_len">
<mvt:comment>
Defaults
</mvt:comment>
<mvt:assign name="l.sub_pointer" value="1" />
<mvt:assign name="l.write_char" value="substring_var(l.input_string, l.pointer, 1)" />
<mvt:assign name="l.current_char" value="l.write_char" />
<mvt:assign name="l.next_char" value="substring_var(l.input_string, l.pointer + 1, 1)" />
<mvt:comment>
Start of the comment of this iteration. Prevent
the script to write
</mvt:comment>
<mvt:if expr="l.COMMENT_START">
<mvt:assign name="l.COMMENT_START" value="0" />
<mvt:assign name="l.COMMENT_MODE" value="1" />
</mvt:if>
<mvt:comment>
Reached the end of the comment in this iteration. Allow
the script to write
</mvt:comment>
<mvt:if expr="l.COMMENT_END">
<mvt:assign name="l.COMMENT_END" value="0" />
<mvt:assign name="l.COMMENT_MODE" value="0" />
</mvt:if>
<mvt:comment>
HTML Comment Start
</mvt:comment>
<mvt:while expr="l.next_char EQ substring_var(l.start_comment, l.sub_pointer, 1)">
<mvt:if expr="l.sub_pointer EQ l.start_comment_len">
<mvt:assign name="l.pointer" value="l.pointer + l.start_comment_len" />
<mvt:assign name="l.COMMENT_START" value="1" />
<mvt:whilestop />
</mvt:if>
<mvt:assign name="l.sub_pointer" value="l.sub_pointer + 1" />
<mvt:assign name="l.next_char" value="substring_var(l.input_string, l.pointer + l.sub_pointer, 1)" />
</mvt:while>
<mvt:comment>
HTML Comment End
</mvt:comment>
<mvt:while expr="l.next_char EQ substring_var(l.end_comment, l.sub_pointer, 1)">
<mvt:if expr="l.sub_pointer EQ l.end_comment_len">
<mvt:assign name="l.pointer" value="l.pointer + l.end_comment_len" />
<mvt:assign name="l.COMMENT_END" value="1" />
<mvt:whilestop />
</mvt:if>
<mvt:assign name="l.sub_pointer" value="l.sub_pointer + 1" />
<mvt:assign name="l.next_char" value="substring_var(l.input_string, l.pointer + l.sub_pointer, 1)" />
</mvt:while>
<mvt:comment>
Remove unwanted control characters
</mvt:comment>
<mvt:if expr="
l.COMMENT_START OR
l.COMMENT_END
">
<mvt:if expr="
(l.write_char EQ asciichar( 10 ) OR
l.write_char EQ asciichar( 11 ) OR
l.write_char EQ asciichar( 12 ) OR
l.write_char EQ asciichar( 13 ) OR
l.write_char EQ asciichar( 14 ) OR
l.write_char EQ asciichar( 15 ))
">
<mvt:assign name="l.write_char" value="asciichar(0)" />
</mvt:if>
</mvt:if>
<mvt:comment>
Write out the results
</mvt:comment>
<mvt:if expr="NOT l.COMMENT_MODE">
<mvt:assign name="l.output_string" value="l.output_string $ l.write_char" />
</mvt:if>
<mvt:comment>
Increment pointer
</mvt:comment>
<mvt:assign name="l.pointer" value="l.pointer + 1" />
</mvt:while>
<mvt:eval expr="l.output_string" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment