开发者

algorithm for auto-formatting html [closed]

开发者 https://www.devze.com 2023-02-26 00:21 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, 开发者_开发问答vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, 开发者_开发问答vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消