Papyrix's XHTML5 "parser" (it does layout & styling too) is organized within its ePub support library.
There's several arrays of special tagnames, a util that checks for whitespace, a util which reformats styling properties from into a new struct, a util which performs an in-array operation, a helper which reformats styling properties & which flushes the current word (NFC-normalized) into the paragraph class, & a helper which splits a block between pages.
1/?