Where is the HTML-handler part in the wpdb class?

wpdb->query() is just running the query. It doesn’t do anything special. And strip_invalid_text_from_query() based on the inline documentation is just stripping invalid characters in the query.

And, for your information, something like line-breaks doesn’t break the database. The database can accept any string data. You just have to make sure it correctly escaped when the query runs.

Hence there is a PHP function mysql_real_escape_string. Or better using a prepared query string (see wpdb::prepare()).