Remove Less // Comments on Compile

Remove LESS // comments on compile

Less' single-line comments // are supposed to be silent, as per documentation states:

Single-line comments are also valid in LESS, but they are ‘silent’, they don’t show up in the compiled CSS output:

// Hi, I'm a silent comment, I won't show up in your CSS
.class { color: white }

See at LESS' website: http://lesscss.org/#-comments

-x flag works on command line to output minified CSS (which will strip CSS comments), but in any way, double slash shouldn't appear on css. See http://lesscss.org/#usage at 'Command-line usage' topic.

It is possible to compress LESS files without removing comments using lessc?

If you want to keep comments in compiled LESS files, you should be using block comments for non-minified code:

site.css
/* this is a keeper */
.foo {
...
}

And for minified code you should use --yui-compress with /*! to start your comments:

site.min.css
/*! this is a keeper */
.foo{...}

This is because the lessc command with the --yui-compress flag pipes the CSS through YUI Compressor, and YUI Compressor allows comments when they begin with /*!.

Remove '#' comments from a string (the comment may start from in-between ta line of the string)

You can use regex101.com to debug your regex and see what it's actually matching.

(?m) changes the matching rules so that ^ matches the beginning of a line, rather than the beginning of the entire string

^ * is matching the start of a line, followed by any number of space characters. (So hopefully there aren't any tabs!)

In plain English, your regex is matching only Python comments that come at the beginning of the line or after any number of spaces.

Other answers have already provided regexes to do what you want, so I won't repeat it here.

How can I delete multiline comments in C file to using Python?

I'm not looking too much in the details, but you are using pattern3 for both start and end of comments. I guess it should be something like

    if pattern3.search(line) and cmnt_e == True:
cmnt_s = True
cmnt_e = False
if pattern4.search(line) and cmnt_s == True:
cmnt_e = True
cmnt_s = False

I would also be wary of strange patterns like this one (yes, I use this sometime for experimental stuffs, you just flip the first slash to flip the active code) :

//*
ACTIVE_CODE
/*/
INACTIVE_CODE
//*/

remove comments in generated mainjs from angular's build

It seems that in the angular.json file the optimization is false on my end.

I was able to minify and remove all the comments on the production build.

"production": {
"optimization": true
}

Remove comments from a source code in java

To make it work, you need to "skip" string literals. You can do that by matching string literals, capturing them so they can be retained.

The following regex will do that, using $1 as the substitution string:

//.*|/\*(?s:.*?)\*/|("(?:(?<!\\)(?:\\\\)*\\"|[^\r\n"])*")

See regex101 for demo.

Java code is then:

str1.replaceAll("//.*|/\\*(?s:.*?)\\*/|(\"(?:(?<!\\\\)(?:\\\\\\\\)*\\\\\"|[^\r\n\"])*\")", "$1")

Explanation

//.*                      Match // and rest of line
| or
/\*(?s:.*?)\*/ Match /* and */, with any characters in-between, incl. linebreaks
| or
(" Start capture group and match "
(?: Start repeating group:
(?<!\\)(?:\\\\)*\\" Match escaped " optionally prefixed by escaped \'s
| or
[^\r\n"] Match any character except " and linebreak
)* End of repeating group
") Match terminating ", and end of capture group
$1                        Keep captured string literal

How can I delete all /* */ comments from a C source file?

Why not just use the c preprocessor to do this? Why are you confining yourself to a home-grown regex?

[Edit] This approach also handles Barts printf(".../*...") scenario cleanly

Example:

[File: t.c]
/* This is a comment */
int main () {
/*
* This
* is
* a
* multiline
* comment
*/
int f = 42;
/*
* More comments
*/
return 0;
}

.

$ cpp -P t.c
int main () {

int f = 42;

return 0;
}

Or you can remove the whitespace and condense everything

$ cpp -P t.c | egrep -v "^[ \t]*$"
int main () {
int f = 42;
return 0;
}

No use re-inventing the wheel, is there?

[Edit]
If you want to not expand included files and macroa by this approach, cpp provides flags for this. Consider:

[File: t.c]

#include <stdio.h>
int main () {
int f = 42;
printf(" /* ");
printf(" */ ");
return 0;
}

.

$ cpp -P -fpreprocessed t.c | grep -v "^[ \t]*$"
#include <stdio.h>
int main () {
int f = 42;
printf(" /* ");
printf(" */ ");
return 0;
}

There is a slight caveat in that macro expansion can be avoided, but the original definition of the macro is stripped from the source.

Show specific comment in LESS file when compiled to CSS while keeping all other comments hidden

So instead of single line less comment

// DO NOT EDIT THIS FILE

use block css-style less comment

/* DO NOT EDIT THIS FILE */

Less variables in comments

There is no straight-forward (non-hacky) way to achieve this in Less. Less compiler does not evaluate any variable that is present within comments and so it would continue to be printed as @{var} instead of the evaluated value.

However, that doesn't mean there is no way at all. There is a way of achieving something close. That would be to put the entire comment text into a temporary variable and print it before the selector using selector interpolation technique.

The comment would not cause any impact to how the compiled CSS works (because the UA will just ignore the comments, refer the snippet at the end - it uses the compiled CSS produced by this code) but it doesn't have a line-break.

Note: I would definitely not recommend implementing such hacky solutions. I have given it here just to show that it can be done in a different way.

Less Code:

.rte_element(@name, @rules) {
@className: e(replace(@name, " ", ""));
@comment: ~"/* @{name} */"; /* store the comment structure as a variable */
@{comment} .@{className} { /* print it before the selector */
@rules();
}
}

.rte_element("Header 2", {
font-size: 1.5em;
color: red;
});
.rte_element("Header 3", {
font-size: 1.75em;
color: blue;
});

Demo with compiled CSS:

/* Header 2 */ .Header2 {  font-size: 1.5em;  color: red;}/* Header 3 */ .Header3 {  font-size: 1.75em;  color: blue;}
<div class="Header2">Header 2 text</div><div class="Header3">Header 3 text</div>


Related Topics



Leave a reply



Submit