Where is the formal ICAO flight plan text format specified?
You will want to look in PANS-ATM (ICAO Document 4444), specifically, Appendix 2. (reproducing the entire appendix in this answer is not practical; it is 10 pages long). SKYbrary is also a nice resource.

Note that the ICAO model flight plan form actually contains the text format embedded in the form. Where slashes, hyphens, prefix letters etc. are required, they are printed directly on the form. I have highlited a few in the below screenshot for clarification:



&lt;&lt;≡ denotes start/end of message and newline.

➝ denotes a space.