Check chapter 11.2 of the "Using Thymeleaf" tutorial for details.
In order to extend thymeleaf for use with non-XML files, you'd need to write your own "template mode".
A Template Mode is managed by a "handler" object, which has to be an implementation of the ITemplateModeHandler interface. A "TemplateEngine" object can register a set of different "template mode handlers", and these template modes are selected for application on the resolved templates by the "Template Resolvers", which as a result of their execution return the template mode to be applied along with the InputStream to the resolved template itself.
And what is a template mode? Basically, a combination of parser + writer. A "parser" is an implementation of the ITemplateParser interface, and is in charge of converting templates into a DOM tree. A "writer" (implementation of ITemplateWriter) is the opposite: turns a DOM tree into a text result. The parser is obviously applied to the template at the beginning of the template execution, and the writer at the end.
So you can use thymeleaf for processing non-XML templates *as long as they can be represented as a DOM tree*. And a "DOM tree" is a tree of objects of the classes living at the "org.thymeleaf.dom" package.