Add a whitespace at the end of the line in Jade - node.js

I have this jade code:
p
| Avatar hosted by
a(href='http://www.gravatar.com/', target='_blank') Gravatar
The problem is, it's rendered to
<p>Avatar hosted byGravatar</p>
Which looks like: "Avatar hosted byGravatar".
No matter how many spaces I added at the end of the text line, it still looks like this. The Docs couldn't help me, and I can't imagine this to be such an uncommon problem.

If you don't want inline HTML or HTML entities in your code this is what you can do:
p
| Avatar hosted by
= ' '
a(href='http://www.gravatar.com/', target='_blank') Gravatar
or this is is shorter
p= 'Avatar hosted by '
a(href='http://www.gravatar.com/', target='_blank') Gravatar
The cleanest is probably this
p Avatar hosted by #{''}
a(href='http://www.gravatar.com/', target='_blank') Gravatar

Which version of jade are you using? I just tested (with 0.25.0) with a single space following 'by', and it worked correctly.
Other options are:
p
| Avatar hosted by
a(href='http://www.gravatar.com/', target='_blank') Gravatar
or
p
| Avatar hosted by
| <a href='http://www.gravatar.com/' target='_blank'>Gravatar</a>

Jade now supports interpolation of inline tags.
p this is #[strong test] of how jade will treat #[i #[u inline tags]]... like #[a(href="/") anchor tags] and #[+a() mixins].
http://jade-lang.com/reference/interpolation/

Are you sure it's not your editor? I use Komodo and it was set to strip trailing whitespace on save. It was stripping the space at the end of my text line when I saved the file. The lack of a space between my text and links was driving me nuts until I figured that out. I changed Komodo's settings (Preferences->Editor->Save Options) to uncheck strip trailing white space, and the problem went away.

I use the space variable at new line. This:
p
| You must follow
=space
a(href=default_url) this link

edit:
As jmar777 pointed out, recent versions of jade should honor trailing whitespace see here. That's awesome, and I may try jade again on future projects.
edit:
Updated link to jade parser. Original link was for jade 1.11.

A quick and clean solution is to use this syntax:
p
| Avatar hosted by
|
a(href='http://www.gravatar.com/', target='_blank') Gravatar
Note the space after | on the second text line. This will add a blank space after the previous line's text (and also spit out a nasty error if you forget to add it!).
So far this is the cleanest option, in my opinion.

I'm using Harp, and the solution with two pipes by Óscar Gómez throws an error, although it looks very elegant.
Thanks to Даниил Пронин and Sean Gravener, I found these solutions working for me:
#{' '}
!{' '}
and
= " "
p
| Avatar hosted by #{' '}
a(href='http://www.gravatar.com/', target='_blank') Gravatar
and
p
| Avatar hosted by
= ' '
a(href='http://www.gravatar.com/', target='_blank') Gravatar
Also, if you're having kind of a reverse situation:
span text #{ ref + [' '] }
Here's more on syntax interpolation in Pug (Jade):
https://pugjs.org/language/interpolation.html

Related

NodeJS simple horizontal line on console.log

I'm making a simple Node JS app.
It logs a lots of informations on console. I would like to know if it's possible to add a horizontal lines in Node JS command line without using any extra packages or dependencies.
If command prompt supports HTML elements, then I could use something like console.log("<hr>"); for adding a horizontal line but it does not support HTML.
Is there any way ?
To create the string for the horizontal line:
const line = '-'.repeat(process.stdout.columns)
.repeat() method repeats the string.
process.stdout.columns returns the number of columns.
To use it:
console.log(line)
The console does not support rendering HTML elements.
That does not prevent you from making a custom line however!
const lineBreak = '----------------------'
console.log(lineBreak)
Of course, customize the linebreak however you'd like:
______ //Underscores!
----- //Hyphens!
====== //Equals!
For grouping related data, refer to the docs here: console reference
Example:
function name(obj) {
console.group('name');
console.log('first: ', obj.first);
console.log('middle: ', obj.middle);
console.log('last: ', obj.last);
console.groupEnd();
}
name({"first":"Wile","middle":"E","last":"Coyote"});
Will output grouped data to the console, visually giving it a line break & arrow to collapse the group. I think this would work well for your use case.
Working off on the same vane as #sergey above:
If your output has a header of a determinable length you can use the .length method.
const header="This is my header";
console.log(header);
console.log('-'.repeat(header.length);

How do I edit the footer in Magento 2.2.4?

My footer consists of
"Name | Address | Phone | Twitterlink | Facebooklink"
I cannot find where to edit this info.
I looked under static blocks under "Footer Links", but that has nothing to do with it. I have looked at:
app\design\frontend\base\default\template\page\template\links.phtml
but there is nothing there.
The location of your footer template depends on the theme you are using.
If it is not defined in backend static blocks, you can check somewhere under:
app/design/frontend/<vendor_name>/<vendor_theme/templates/html/footer.phtml
As a last chance, make a search for the string '
grep -RlFin "string_to_search" app

input is self closing and should not have content

When I load my Express webpage I'm getting the following error:
Express
500 Error: /app/views/index.jade:114 112| td 2 113| td 4 years > 114| input is self closing and should not have content.
112| td 2
113| td 4 years
> 114|
input is self closing and should not have content.
at Object.Compiler.visitTag (/app/node_modules/jade/lib/compiler.js:434:15)
at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:210:37)
at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:197:10)
at Object.Compiler.visitBlock (/app/node_modules/jade/lib/compiler.js:278:12)
at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:210:37)
at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:197:10)
at Object.Compiler.visitTag (/app/node_modules/jade/lib/compiler.js:443:12)
at Object.Compiler.visitNode (/app/node_modules/jade/lib/compiler.js:210:37)
at Object.Compiler.visit (/app/node_modules/jade/lib/compiler.js:197:10)
at Object.Compiler.visitBlock (/app/node_modules/jade/lib/compiler.js:278:12)
This doesn't show up when run locally with foreman start, only when its on the server.
Looks like you've got content inside your input tags. In HTML, input tags can't have content, therefore you should delete any whitespace or characters following input tags in your jade file.
Ex:
input(type="text",name="whatever") something
should be input(type="text",name="whatever",value="something")
Sometimes the answer is a little tricker than just some content after the tag on the same line (such as a few spaces). Watch out for the line following the input tag being indented by mistake!
After running into the same error I was checking the line of jade template marked in error report. It was actually containing input definition, but that definition was fine for there wasn't any whitespace and printable content succeeding it. The following line was even less indented (two levels up for starting another row of form) and thus there was definitely no content to input element defined in marked line.
However there was another input succeeding this marked one a few lines down the template. And that input element indeed was having some subordinated content. Removing content there was fixing somewhat false positive "here".
I had a similar problem I solved with this:
div
+inputWithTextContent('whatever', 'something')
mixin inputWithTextContent(name, message)
!='<input type="text" name="'+name+'">'+message+'</input>'
Another solution is to create a label after the input and then display it inline. This will sit the label along side the control. This is how I solved the issue with a checkbox input in jade.
JADE (Bootstrap):
.checkbox
label
input(type='checkbox', value='remember-me',)
label.inlineLabel Remember me
SASS:
label.inlineLabel
display: inline

Groovy string replace add new line

Got a groovy script that is pulling some text from a soap connection and I am trying to add a bullet point before any bullet points. Here is the code I have but it does not work and it may never work, but thought I would ask.
td (it.#detail.toString().replaceAll('>', '>').replaceAll("•", "\n •"))
That should work.
ie, try:
println it.#detail.toString().replaceAll('>', '>').replaceAll("•", "\n •")
To see it working in the console output.
I guess you're viewing this in HTML with a browser?
Newlines don't appear in HTML normally, so you'd need to wrap the text in a <pre> tag.
Assuming this is with StreamingMarkupBuilder or similar, try:
td {
pre( it.#detail.toString().replaceAll('>', '>').replaceAll("•", "\n •") )
}

%2B decoding to a space instead of a plus

We have a problem in a specific server. All plus signs posted to the application are replaced with spaces - that's in POST and GET, and on all pages on that site.
As a test case I have this little page (it's an ASP server):
<html>
<body>
<form method="post">
<input type="text" name="Plus" id="Plus" />
<input type="submit" />
</form>
Previous Value: <%= request("Plus") %><br />
Query String: <%= request.querystring %>
</body>
</html>
On every other server this works well, but on one server pluses are replaced with spaces.
Example: for the input "1 2+3" - request("Plus") is "1 2 3", and the Query String is "1+2+3". No good. Other characters seem to be decoding correctly.
It should be said someone had tried to 'harden' this server against attacks, so obscure IIS options may be turned on (though we did remove the ISAPI filter).
Thanks.
UPDATE:
It turns out there's another filter installed, the SQL Injection Filter ISAPIClipSQLInjection.dll from http://www.codeplex.com/IIS6SQLInjection .
The filter is buggy - it replaces valid characters from POST and GET:
Plus signs are replaced with spaces: "1%2B2" -> "1+2", same as "1 2"
Semicolons are replaced with Commas: "hello;" -> "hello,"
A newer version of the filter (2.0b) does not fix this, but allows to exclude certain pages. Since it is installed in production we decided not to remove the filter, we used javascript to change all pluses to "&#43 " (with space and not a semicolon).
Not the optimal solution, but that's what the boss wanted.
Consider Ascii Code. In the place of a plus sign use its ascii code.It would be chr(43). Both asp and sql would understand this.
here is a table with all ascii codes.
http://www.asciitable.com/
Well, this also confused me. till I saw this post: Server.URLEncode started to replace blank with plus ("+") instead of percent-20 ("%20")
in short:
RFC-1866 (around 1995), declared that blank " " should be parsed to "+" in request body.
RFC-3986 (2005, Jan) declared that blank " "should be parsed to "%20"
and in ASP framework, it supports the RFC-1866, and sometimes mixed RFC-3986(seems) , so the parameter %2b firstly converted to + (normal ascii/urldecode rule , then it converted to ( RFC-1866 rule )
This is my guess, I don't care old-dead tech, for more details, see

Resources