I cant find algorithm for auto-formatting HTML code.
If you want an algorithm in the strict sense of the word, then you might do something like:
int counter=0;
Look for html elements: if you find an opening element, indent it (counter) spaces and increase counter. otherwise, if you find the closing element decrease counter, and indent the element (counter) spaces. All other text is indented counter spaces. Loop...
At the end of the file, counter should be 0 again. You should never encounter a closing element without having opened that particular type of element, otherwise, you have a badly formatted file.
don´t exactly know what you mean but look at this page htmlagilitypack with it you can manage a lot of things with html :-)
There's Tidy which has a wrapper for .NET.
精彩评论