Base64, PyScript, and WordPress

In a recent post, I found that WordPress misinterpreted indents and returned errors when I tried to run PyScript codes on it.

Brief Review of PyScript on WordPress

Anaconda has introduced PyScript at PyCon US 2022. It enables client-side execution of Python codes in web browsers, and they say it is already compatible with…

It might be because WordPress detoxes the codes to turning them unfunctional for security reasons. So, I converted them into base64 to evade WordPress' watch.

Code with no indent

print("Hello, World")

First, a code with no indent. I converted the above code into base64 and pasted into the py-script tag as src. The first two lines urge the browser to import the PyScript program.

<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css">
<script defer="" src="https://pyscript.net/alpha/pyscript.js"></script>
<py-script src="data:text/html;base64,cHJpbnQoIkhlbGxvLCB3b3JsZCEiKQ==">
</py-script>

Results

↑No problem with hello world.

Code with indents

for i in range(5):
    print(i) 

Next, a code with indents. Its result is what I am interested in. The above code was converted into base64 and pasted below.

<py-script src="data:text/html;base64,Zm9yIGkgaW4gcmFuZ2UoNSk6CiAgICBwcmludChpKSA=">
</py-script>

Results

Indents didn't cause errors this time.

Leave a Reply

Your email address will not be published. Required fields are marked *