Use a terminal emulator which supports copying the text as HTML (or similar). You can paste it either directly to a .html file, or to LibreOffice which will import the formatting.
For example, GNOME Terminal has a "Copy as HTML" menu item as of v3.26 (libvte 0.50).