Noob question but I want to be able to quickly comment HTML code using keyboard shortcuts in VS code. Problem is I get this:-
<!-- <div class="whatever">
<h1>Hellow World!</h1>
<p>this is code I wrote in HTML</p>
</div> -->
instead of this:-
<!-- <div class="whatever"> -->
<!-- <h1>Hellow World!</h1> -->
<!-- <p>this is code I wrote in HTML</p> -->
<!-- </div> -->
Anyone know a good extension for this in VS Code? Thanks
Julien
See this extension written by me, Toggle Line Comments, that will do what you want.
-- or older answer --
Select through your text - i.e., from some part of the first line to some part of the last line you want separately commented. I.e., highlight your block of html to comment.
Shift-Alt-I will put a cursor at the end of each line.
Ctrl-/ will comment each line separately.
This only seems necessary for html, not js or scss for example.
I suppose if you wanted to reduce keystrokes you could make a macro for steps 2 and 3 combined.
I want to know if is possible to add comments to existing html closing tags, for example:
<div class="container">
Content
</div>
And I want to format it to be like this:
<div class="container">
Content
</div> <!-- /.container -->
With emmet (.container>{Content}) I will have to rewrite all my code to get the comments, so it's possible to add closing comment with sublime text 3 to an existing html code instead to rewrite it again using emmet?
I'm not sure I understand the end of your post regarding emmet, but adding a comment after the HTML closing tag should be fine as any comments in an HTML file are ignored by the browser regardless of where they are placed.
Hope this helps.
Is there a plugin to help with HTML commenting a block of code that may already contain other comments?
<div class="wrapper">
<div class="container"></div>
<!-- /.container -->
</div>
<!-- /.wrapper -->
BBEdit has a built in feature where if you select all of this code and apply a block comment, it will change the existing comments temporarily so that the main block comment can be applied. The output in the editor would look like:
<!--
<div class="wrapper">
<div class="container"></div>
<!~~ /.container ~~>
</div>
<!~~ /.wrapper ~~>
-->
Uncommenting the block would set the ~ characters back to dashes - so the individual comments would still be in place.
I am not looking for this specific functionality, but something that allows for block commenting content that already contains HTML comments without having to manually remove/edit the existing comments.
I could not find a plugin that does this, so I wrote one.
Installation instructions are available at https://github.com/philsinatra/HTMLNestedComments
Not sure how to tag this question. I have a database of XHTML documents that are converted by LaTeXMLpost; however, saying that they have validation issues is an understatement. I need to show them inside a browser. However, tag autoclosing due to invalid markup messes up my structure.
A minimal example:
<!doctype html>
<html>
<head>
<title>test</title>
</head>
<body>
<div id="content" style="background-color:pink">
<!-- yield -->
<section >
<ul>
<li>
<div>
<p>
First
<li>
<div>
<p>
Second
</p>
</div>
</li>
</p>
</div>
</li>
</ul>
</section>
<section>
Next
</section>
<!-- end yield -->
</div><!-- end content -->
</body>
</html>
jsfiddle
Everything outside comments is layout; inside it is the loaded document. If things were taken at face value, everything should be pink, right?
The problem is, "Next" gets booted outside the #content. Even though it is valid XML, it does not conform to HTML/XHTML DTD (or whatever passes for DTD in HTML5), so it gets mangled.
The question is: How can I protect my layout against invalid markup inside it? Can I do something to the content to normalise it? I'm loading it into Nokogiri before displaying, but I still end up in this mess anyway (since the XML isn't malformed, I suppose, Nokogiri doesn't do anything about it).
I don't care if it's displayed nicely or not, all I care now is that it remains safely contained (otherwise I have trouble with manipulating it, attaching events, styling, and pretty much everything else).
You can try Nokogiri it has some built-in functionality for fixing invalid mark-up.
Related question : Repairing invalid HTML with Nokogiri (removing invalid tags)
Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing.
Consider this code...
<!-- Here starts the sidebar -->
<div id="sidebar">
....
</div>
<!-- Here starts the main contents pane -->
<div id="main-contents">
...
</div>
<!-- Here starts the footer -->
<div id="footer">
...
</div>
Now, if I have to hide out some portion of the view template, in case of php I would just select the desired code and put single-line comments (using a shortcut key most of the times).
However, in html code, where only the block comments work, I end-up removing all the closing comment tags (-->) till the position I want the commenting to occur - something like this...
<!-- Here starts the sidebar
<div id="sidebar">
....
</div>
<!-- Here starts the main contents pane
<div id="main-contents">
...
</div>
<!-- Here starts the footer
<div id="footer">
...
</div>-->
Then when I'm done testing I have to go through the agony of putting back those closing tags.
Is there a better and time saving way of block commenting in HTML?
Yes, to comment structural metadata out,
Using <script>/* ... */</script> in .html
Comment out large sections of HTML (Comment Out Block)
my personal way in a .html file is opening: <script>/* and close it with */</script>
<script>/* hiding code go here */</script>
Is a workaround to the problem since is not HTML.
Considering your code in .html...
<!-- Here starts the sidebar -->
<div id="sidebar">
....
</div>
<script>/*
<!-- Here starts the main contents pane -->
<div id="main-contents">
...
</div>
<!-- Here starts the footer -->
<div id="footer">
...
</div>
*/</script>
And in a case is HTML inside PHP file using comment tag <?/* or <?php /* and close it with */?> . Remember that the file must be .php extension and don't work in .html.
<?/* hiding code go here */?>
Considering your code in .php...
<!-- Here starts the sidebar -->
<div id="sidebar">
....
</div>
<?/*
<!-- Here starts the main contents pane -->
<div id="main-contents">
...
</div>
<!-- Here starts the footer -->
<div id="footer">
...
</div>
*/?>
Is worth nothing that is not HTML but a common developer practice is to comment out parts of metadata so that it will not be rendered and/or executed in the browser. In HTML, commenting out multiple lines can be time-consuming. It is useful to exclude pieces of template structural metadata containing comments, CSS or code and systematically commenting out to find the source of an error.
It is considered a bad practice to comment blocks out and it is recommended to use a version control system.
The attribute "type" is required in HTML4 and optional in HTML5.
Depends on the extension. If it's .html, you can use <? to start and ?> to end a comment. That's really the only alternative that I can think of. http://jsfiddle.net/SuEAW/
you can try to replace --> with a different string say, #END# and do search and replace with your editor when you wish to return the closing tags.
I find this to be the bane of XML style document commenting too. There are XML editors like eclipse that can perform block commenting. Basically automatically add extra per line and remove them. May be they made it purposefully hard to comment that style of document it was supposed to be self explanatory with the tags after all.
Put a space between the "-->" of your header comments. e.g. "- ->"
My view templates are generally .php files. This is what I would be using for now.
<?php // Some comment here ?>
The solution is quite similar to what #Robert suggested, works for me. Is not very clean I guess.
Eclipse Juno has a good way for it. You just do the cmd+/
The following works well in a .php file.
<php? /*your block you want commented out*/ ?>
No. Unless you find a tool that does what you described for you.
Depending on your editor, this should be a fairly easy macro to write.
Go to beginning of line or highlighted area
Insert <!--
Go to end of line or highlighted area
Insert -->
Another macro to reverse these steps, and you are done.
Edit: this simplistic approach does not handle nested comment tags, but should make the commenting/uncommenting easier in the general case.
/* (opener)
*/ (closer)
for example,
<html>
/*<p>Commented P Tag </p>*/
<html>