how to comment in sublime if the multiple lines already contain comments? - html

I have this problem that I want to comment a whole section of code in HTML, this section of code already have some comments inside. now if I want to comment the whole section, how can I do it. the ctrl + / dont work anymore.....
<div class="meta">
<hr>
<!-- some comments -->
<span class="meta_date"><i class="fa fa-calendar"></i> <strong>Date:</strong>
2016.05 - 2016.06</span>
<!-- some comments -->
<div class="clearfix"></div>
</div>

You can use
<?/* html code */?>
Or
<script>/* html code */</script>

Related

HTML comment each line separately, not block comments

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.

Jekyll: Markup Appearing in <p> Tag

I've got an issue where my some of my markup from a file in my _/includes folder, is being printed to my page inside <p> tags.
Here's what's inside my _includes/gallery.html file:
{% assign rows = page.gallery[include.gallery] %}
</section> <!-- close this -->
</div> <!-- and this -->
</div> <!-- this too -->
<section class="image-gallery">
...
</section>
<div class="container"> <!-- open this -->
<div> <!-- and this -->
<section> <!-- this too -->
I'm trying to close out some elements, and re-open them after my .image-gallery. But for some reason, my closing and opening tags are being printed inside <p> tags
Like this:
<pre><code></section>
</code></pre>
<p></div>
</div></p>
<section class="image-gallery">
...
Is there any way to stop this from happening? It seems to only affect non-closed tags, like the ones in my example. Everything inside .image-gallery displays correctly.
Anyone know why this is happening? Any help is appreciated. Thanks in advance!
Ok, I get it.
You including _includes/gallery.html from a .md file, so markdown first includes, then try to parse the code.
As you code has unopened tags at the beginning (</section></div></div>) they are treated as markdown, not html.
Edit:
The solution is to surround your code with :
{::nomarkdown}
your code here
{:/nomarkdown}
This avoid your html to be parsed by kramdown.

How to comment out a HTML block which contains comments

I try to comment out a block of HTML which contains comments, when the time I do so, the commenting terminated at the first comment tag ending. Is there any way to do so? I didn't find it anywhere.
Let see this HTML
<!-- START overview-section -->
<div class="overview gray">
<!-- Title section -->
<div class="row">
</div>
</div>
How to comment it as a whole.
Short of breaking up the pairs of -- inside the comment, you cannot achieve this in HTML.
If you were generating your HTML from some kind of template language, you could use the template language's comment syntax instead.
You can wrap it up in a script tag and use JavaScript's block comments
<script> /***
<!-- START overview-section -->
<div class="overview gray">
<!-- Title section -->
<div class="row">
</div>
</div>
***/ </script>
this can't be done with HTML. It can however be done if it were php
<?php
//<!-- START overview-section -->
//<div class="overview gray">
// <!-- Title section -->
// <div class="row">
// </div>
//</div>
?>

Sublime Text HTML Block Comment Containing Comments

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

How to comment/uncomment in HTML code

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>