Is it possible to format the input from the serial monitor?

I'm sorry if I'm being obtuse, but the sketch works perfectly with the string as included in the sketch:

    String codeString = "import machine\nimport utime\n\ngpio0 = machine.Pin(0, machine.Pin.OUT)\ngpio45 = machine.Pin(45, machine.Pin.OUT)\nutime.sleep(1)\ngpio45.value(0)\ngpio0.value(1)";
    Serial.println(codeString);

This gives the following in the monitor:

import machine

import utime

gpio0 = machine.Pin(0, machine.Pin.OUT)

gpio45 = machine.Pin(45, machine.Pin.OUT)

utime.sleep(1)

gpio45.value(0)

gpio0.value(1)

Which is what I want from the input string "import machine\nimport utime\n\ngpio0 = machine.Pin(0, machine.Pin.OUT)\ngpio45 = machine.Pin(45, machine.Pin.OUT)\nutime.sleep(1)\ngpio45.value(0)\ngpio0.value(1)"