Papyrix finds it easier to render XHTML5 not HTML5, so it has a support library which (alongside another task I'll study later) can perform this conversion!
This includes an array of tags as self-closing with a wrapper around this array, some limits as hardcoded numbers, a state enum, lowercasing helper, & some charset tests.
So the conversion routine can open the input & output files on the SD card, clears some state, allocate some buffers or propagate failures, ...
1/2
... prepares some closures to the outfile via buffer, enters a mainloop, flushes based on the current state while repairing syntax, & cleans up.
Each iteration of this mainloop attempts to read a bufferful in & branches over each character (or pair thereof) it read according to the state machine.
In the "normal" state it echoes everything until it reaches "<" upon which it transitions to the in-tag-start state. Where it checks for "/" for closing tags, tagnames, or whether it should bail out.