In JupyterLab extension, how to modify the code before it is execute

I want to implement some macros in python code in notebook. Before the code cell is executed, I want to replace the macro with the actual value.

For example, If I have the follow code.


When I run the code, I want to send the code I want to send the code print("Harry") to server. But I don’t want to change the display of the code.

I used the suggestion in this post. I am able to replace the CodeCell implementation with My class, but I am not able to change the code without changing the display.