Saturday, February 15, 2014

Hide arbitrary text contents in HTML document.

Sometimes we encounter this situation where there are double-minus inside the paragraph of a HTML document that we want to temporarily make invisible. The problem mainly is that the double-minus has special meaning to HTML. We can't just use <!-- and --> to enclose it so as to hide it. We need to convert it into something that doesn't have double-minus inside, before we comment it out. In this case, the utility named openssl comes in handy. For example,

A dummy double-minus -- is here.

If we throw it into the stdin of the pipe xz -9 | openssl enc -base64 -e, it will return

/Td6WFoAAATm1rRGAgAhARwAAAAQz1jMAQAgYSBkdW1teSBkb3VibGUtbWludXMg
LS0gaXMgaGVyZS4KAAAAABTizwrgs6ttAAE5Ic8oa2IftvN9AQAAAAAEWVo=

Now, the double-minus is gone. It's safe to comment it out to make it invisible.

<!--
/Td6WFoAAATm1rRGAgAhARwAAAAQz1jMAQAgYSBkdW1teSBkb3VibGUtbWludXMg
LS0gaXMgaGVyZS4KAAAAABTizwrgs6ttAAE5Ic8oa2IftvN9AQAAAAAEWVo=
//-->

How to restore it back? openssl enc -base64 -d | xz -d will do.

In actual case, the replacement usually is smaller in size than the original contents, because of the compression.

No comments:

Post a Comment