Leading space in a WebStorm block comment - webstorm

WebStorm produces single line style comments the way I like it with a space after the //: // comment here. How do I add a space after the leading comment literal and before the closing one when commenting out blocks of code?
Here's what I have:
/*<line of code>
<line of code>
<line of code>*/
Here's what I'd like to have:
/* <line of code>
<line of code>
<line of code> */
Add a space at comment start won't do it.

there is no way to control this, please feel free to file a request for this feature to youtrack. Related ticket: IDEA-166872

Related

Delete tags that do not contain a certain child

I got a file full of tags like this:
<Header>
...
<UserData>
<UserID></UserID>
...
</UserData>
...
</Header>
I need to clean the file deleting every <UserData> that doesn't contain a <UserID> with a specific value (say DE123 just for the sake of the example) and maintaining everything else.
For example if I have something like this:
<Header>
...
<UserData>
<UserID>DE123</UserID>
...
</UserData>
<UserData>
<UserID>JJ456</UserID>
...
</UserData>
...
</Header>
I need to make it like this:
<Header>
...
<UserData>
<UserID>DE123</UserID>
...
</UserData>
...
</Header>
How can I achieve this? Tried regex but the only thing I accomplished was inverted bookmarking EVERY line except that specific <UserID>...
You can try this regex:
<UserData>(?:(?!<\/UserData>|<UserID>DE123<\/UserID>)[\s\S])*<\/UserData>
Substitution: empty
<UserData> starting with <UserData>
(?:...)* non-capture group, with any occurrances
(?!<\/UserData>|<UserID>DE123<\/UserID>)[\s\S] negative lookahead, make sure while testing a [\s\S](any character including a new line), neither <\/UserData> nor <UserID>DE123<\/UserID> is consumed.
<\/UserData> ends with <\/UserData>
When this regex matches anything, means its a complete <UserData>...</UserData> enclosure, with no <UserID>DE123<\/UserID> found inside.
You can replace <UserID>DE123<\/UserID> part to anything you want.
See the proof

Closing tags formatting in IntelliJ IDEA

Help needed to set-up a macro/code-formatting/code-style/reformat code where in the code I write (Coldfusion), is tag based and the ending of a tag needs to be formatted.
The CFML code formatter is not doing this. All I want is when I format my code, any tag that is closed or ends with /> without a space from its previous character(any character), needs to be spaced and closed.
Example: any code line that ends with )/> or "/> or character/> capital-letter/> or digit/> or anything/> needs to be changed to ) /> or " /> or character /> capital letter /> or digit /> or anything /> respectively.
How do I get this done?
If you are looking for an automatic conversion for <empty-tag/> to <empty-tag />, you can do that in IntelliJ preferences: Editor->Code Style->XML. Open "Other" and under "Spaces" section on the left check "In empty tag".
I don't think it's possible to configure the IntelliJ formatter to do this. You need to use Find | Replace in Path... with a regular expression.

Prevent whitespace around XML comments in QDomDocument::toString()

I process an XML (XHTML) document using QDomDocument, as easy as this example:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html>
<html>
<body>
<p><i>foo</i><!-- comment --><b>bar</b></p>
</body>
</html>
As an (X)HTML document, the text should be rendered without a whitespace in between "foo" and "bar", since a comment in (X)HTML will not produce a whitespace (unless surrounded by some):
foobar
However, when parsed by QDomDocument and then stringified using .toString(), I get the following source back:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html>
<html>
<body>
<p>
<i>foo</i>
<!-- comment -->
<b>bar</b>
</p>
</body>
</html>
This is then rendered with a whitespace:
foo
bar
As I understand it, the output of QDomDocument seems to be a different XML document than the original one. I checked by inspection of the document tree that the parsed document does not contain the whitespace: The <i> element is immediately followed by a comment node which is followed by the <b> element; i.e. no text node in between.
The fact that the multi-whitespaces don't match (i.e. the indentation width) is not a problem (IIRC, the XML spec doesn't distinguish between multiple whitespaces and a single one, so does HTML). But for two tags with no whitespace in between originally, I require the output to also have no whitespace.
Is this a bug in QDomDocument::toString()? How can I work around this problem? Can I prevent QDomDocument::toString() to produce whitespace here? I already tried to pass -1 as the optional parameter indent, which is documented as: "no whitespace at all is added". It will however still add a line break after the comment (but not before). I could imagine implementing a custom serializer, but I don't know if it is as easy as I imagine.

Search & replace regex - filtering files

little bit of background:
I work at a multilingual communication company, where we’re working with a CMS system. Since its last update, all the files I export out of the system are ‘polluted’ with metadata, which I don't want to see, use or replace. To filter and change a heap of xml files, I use Powergrep, which operates with regexes.
I want my regex to find, e.g. "there is no spoon", "oracle", "I know kung-fu" and "bending method" (all straight quotation marks) and replace it with “there is no spoon”, “oracle”, “I know kung-fu” and “bending method” (all with curly quotation marks).
I don’t want it to find the metadata "concept.dtd" and "map.dtd"
The following lines are the first lines of my xml file. It's this "concept.dtd" that I would like to ignore.
<?xml version="1.0" encoding="UTF-16" standalone="no"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"[
]>
<?ish ishref="GUID-6B84EF92-DA99-4C54-BA91-FD0A113D4A96" version="1" lang="sv" srclng="en"?>
This is somewhere in the middle of the xml file
<row>
<entry colname="col1" valign="middle" align="left">"Bending method" </entry>
<entry colname="col2" valign="middle" align="left">another word</entry>
</row>
So.. this is the original regex:
(?<!=)”\b(.+?)\b”(?! \[)
Replacement:
“1”
Problem:
As the metadata “concept.dtd” and “map.dtd” are part of the file, I don’t want to replace their quotation marks in order not to change anything crucial. So I tried rewriting the regex:
(?<!=)”\b(.+?[\.d])\b”(?! \[)
It almost works: “concept.dtd” and “map.dtd” are skipped, most of the terms between quotation marks are found, but not all: “Bending method” is not found, for example.
What am I missing? Any help or opinions would be greatly appreciated!
Based on your last answers, here is a regexp that can help you:
(?<=<entry)[^>]+>[^<>]*?(".+?")[^<>]*?(?=<\x2Fentry>)
Description
Demo
http://regex101.com/r/lX2cU3
Discussion
I assume that you have one serie of words between straight quotations and that there are no carriage returns ou line feeds inside an <entry> node.

XSL disable-output-escaping removes whitespaces

Part of the XML:
<text><b>Title</b> <b>Happy</b></text>
In my XSL I have:
<xsl:value-of select="text" disable-output-escaping="yes" />
My output becomes
**TitleHappy**
My spacing went missing - there's supposed to be a space between </b> and <b>.
I tried normalize-space(), it doesn't work.
Any suggestions? Thanks!
if you want whitespace from an xsl, use:
<xsl:text> </xsl:text>
whitespace is only preserved if its recognized as a text node (ie: " a " both spaces will be recognized)
whitespace from the orignal source xml has to be preserved by telling the parser (for example)
parser.setPreserveWhitespace(true);
As your outputting HTML you could substitute your space with a non-breaking space
Do you have any control over the generation of the original XML? If so, you could try adding xml:space="preserve" to the text element which should tell the processor to keep the whitespace.
<text xml:space="preserve"><b>Title</b> <b>Happy</b></text>
Alternatively, try looking at the "xsl:preserve-space" element in XSLT.
<xsl:preserve-space elements="text"/>
Although I have never used this personally, it might of some help. See W3Schools for more information.
thank you for everyone's input.
Currently I am using MattH suggestion which is to test for space and substitue to non-breaking space. Another method I thought of is to test for "</b> <b>" and substitue with " </b><b>". The space contain within a bold tags are actually output. Both methods worked. Don't know what the implications are though. And I still can't figure out why the spacing is removed when it is found between 2 seperate bold tags.