Ok, I need a new thread for my HTML processing program

2 replies · 2K views · last reply
Jamin2112
Messages
973
Reaction score
12
My old thread was getting messy and I realized I needed to go back to square 1 and write up a plan. So here's an outline of the plan:
Left: HTML code in a dark editor with a div class container, row divs, an h1 titled Here's the title!, and a row footer paragraph. Arrow points right to CSS selector list: body > div.container > div.row > h1#main-title and similar, with labels HTML and CSS.


Numbered seven-step outline for converting an HTML file into a CSS file in C++, with a tree diagram of root and child nodes and a struct node definition.


I will add to this thread as I write the helper functions and encounter any problems. Criticism greatly appreciated.
 
And here's my self-explanatory procedure for writing the formatted CSS into a string:

C++ source code listing of the functions DocTree::_innerTree2Str, which recursively builds a CSS selector string from a node's element type, classes, id and children with tab indentation, and DocTree::_tree2Str, which calls it with depth 0.
 
Im not really sure if this is relevant for you or not, but in general you would probably not want to structure a CSS file like you do above. If you do, then it is similar to inserting style="" attributes on each elements (this is similar to the naive way of formatting a word document by applying style directly to each chunk of text).

CSS usually shines best when your style classes only depends on one or two levels of html structure context above the current element, although sometimes more is required when you need to adjust a specific frameworks use of CSS in one particular situation. Using CSS the "right way" is similar to formatting a word document by tagging paragraphs as body text, headlines, etc. and they style those tags instead.