3 ms·
Who uses a text editor that inserts whitespace into HTML? I am aware that some editors like to show indentation levels in HTML code, for various reasons, but fo
by tokenadult 14y ago
Who uses a text editor that inserts whitespace into HTML? I am aware that some editors like to show indentation levels in HTML code, for various reasons, but for me HTML code is always more readable if it has no extra whitespace at all. Whitespace is not meaningful in HTML, and I always set my text editor (I have used various brands of text editor over the years) so that my HTML output has no extra whitespace. Why use an editor that adds whitespace in the first place?
AFTER EDIT: TazeTSchnitzel asks a fair question. I put each new major element on a new line. In general, I try to make paragraphs look like paragraphs, headings look like headings, and so on, with just newline whitespace but without leading whitespace before elements (which has annoyed me for the last few weeks in a website updating project I was working on). Thanks for asking the clarifying question.
FURTHER EDIT: Yes, thanks for the statement that indentation shows nested structure (which is what I guessed is the usual rationale for extra whitespace in HTML code). Despite that obviously sensible practice (which, after all, leads to the MEANINGFUL white space in Python code), I have seen plenty of examples of HTML pages that have unmatched tags even though they have so much whitespace that the "view source" view of the page is mostly off to the right of my screen. Agreeing that being able to view source code structure is important, may I suggest that as one reason to like Notepad++ as one of the many editor choices available to persons who write code? In the recent project I worked on updating, the original programmers had left many unmatched tags and inconsistent structures in the code, and I was able to strip out all the extraneous code AND fix the structure by using Notepad++ to find (for example) the beginning and ending div elements surrounding big, complicated blocks of code. Notepad++ shows code structure with structure lines overlaid on the raw source code view.
- TazeTSchnitzel 14y agoYou write you code like this? <!doctype html><html><head><meta charset=utf-8><title>super-readable HTML</title></head><body><div id=container><h1>Title</h1><p>Lorem ipsum dolar sit amet.</p><hr><ul><li>List item</li><li>List item</li></ul><div id=main><div id=sidebar><ul><li>Sidebar item</li><li>Item 2</li></div><div id=main><div id=top><img src=file.png alt=""> This is some text</div><div id=form><form action=/><input type=text name=something><input type=submit></form></div><div id=content><div class=widget><div class=widgettop>thing</div><button class=widgetbtn>button</button></div></div></div></div></body></html>
- mistercow 14y ago>Who uses a text editor that inserts whitespace into HTML? I do as does anyone else who uses Zen Coding (or emmet). >Why use an editor that adds whitespace in the first place? Because it makes the code way, way more readable. Indentation allows you to easily see the structure of the HTML, so that you can see what is a descendant of what. Look at this and tell me whether "Man Made" is part of "Debris" or if it's a separate sublist: <ul> <li>Debris: <ul> <li>Sand</li> <li>Dirt</li> <li>Man Made: <ol> <li>Broken glass</li> <li>Pennies</li> </ol> </li> </ul> </li> <li>Animals: <ul> <li>Cats</li> <li>Dogs</li> <li>Chimps</li> </ul> </li> </ul> Now look at it with indentation: <ul> <li>Debris: <ul> <li>Sand</li> <li>Dirt</li> <li>Man Made: <ol> <li>Broken glass</li> <li>Pennies</li> </ol> </li> </ul> </li> <li>Animals: <ul> <li>Cats</li> <li>Dogs</li> <li>Chimps</li> </ul> </li> </ul>
- mcrider 14y agoObviously (to me anyway) you're right, and I'm surprised there are people who don't indent their HTML like that. But a thought just occurred to me -- why don't editors do this automatically and without creating actual whitespace (tabs/spaces)? If you look at XML in your web browser it will automatically be formatted with indents based on tag hierarchy .
- ramblerman 14y agoI see your point, but I think there are a few solid reasons it would be a bad idea. The basic text file (at least in unix) is king, and the medium by which we transport all sorts of code around. Adding a layer of asbtraction to an editor like that, where it shows you one thing but saves the file differently, breaks this premise and means your new editor now doesn't play well with others. - Unless you source control is in on it, you are going to suddenly see a different file than you were working with before when resolving conflicts. - Your whole team is now forced to use your editor to get the same view of the code as you are. - grepping, line counts, most third party text mapulation/wrangling services become moot unless savvy to the context of your editor