Has anyone here ever tried converting a large text content into Consistent HTML CSS document layouts?

I’m working on a hobby project where I input large blocks of unformatted text and aim to convert them into properly styled documents with elements like headings, subheadings, and paragraphs. My goal is to apply visually appealing and consistent styling before converting the content into a PDF. However, LLMs often produce inconsistent formatting, so I am considering using a consistent CSS based styling system for the web preview. The final objective is to generate a well-styled PDF. If anyone has tried something similar or has suggestions or tools I could try, I would really appreciate it!

It would be easier if there was some sample text for this discussion.

Does the text come with the headings, are they numbered? If so, it may be easy to just write (by you or by LLM) a (Python) program to detect the headings. Once they are detected, and you already have a CSS file which styles all those levels of headings, it should be pretty straightforward to apply them. I guess you may even ask LLM to write a full program for you?