Jade: How to have an empty line in an output HTML? - html

I want to have an empty lines between sections, comments and tags. I'm using jade to output my html and can't output empty lines. Here is what I want.
<div>
<div class='another'>
</div>
</div>
<div>
I want a line just like above
</div>

These are couple of options that worked for me:
The = operator (which enters an evaluated piece of code) with the string for newline character '\n'
div
div.another
= '\n'
div I want a line...
The | pipe operator (which enters plain text) with a space. (had to be two of them for some reason..
div
div.another
| // < followed by blank spaces
|
div I want a line...

Use #{}-style interpolation to generate the empty string:
| foo
| #{''}
| bar
(tweaked lightly from a suggestion in https://github.com/jadejs/jade/issues/912)

The following should give you the HTML output you have asked for:
div
div.another
div
| I want a line just like above

Related

thymeleaf text mode string how to keep indent for each line

i have a string stored in database which contains line break, it should looks like following when displaying on page:
abc
def
hkg
now i need to add this string to an email dialog as email content and its format should be:
my thymeleaf text template to generate email content looks like:
Test: [# th:each="g : ${gList}"]
Description:
[(${g.descr})]
However, after i added the template content to a textarea, it is:
that is there is no indent from line 2, this is not what i want.
how can i get the format like following for one string which contains multiple lines?
Test:
Description:
abc
def
hkg
The html code to show the email content in dialog is :
<div class="row">
<label class="col-2 text-right">Content:</label>
<textarea id="emailContent" class="col-9" v-model="email.content" >
</textarea>
</div>
another question is : what if this string is long but no line break, it only has spaces between words. in this case, it still display the rest of this string from line 2 without indent.
The string stored in the database is abc\ndef\nhkg therefore when you print it out you are getting:
Test:\n
....Description:\n
........abc\n
def\n
hkg
Since this is plain text and you don't have any of the formatting capabilities of html, you're going to have to modify the string itself. Basically, you need to replace your newlines \n with 8 spaces and a new line. You want the string to look like:
abc\n........def\n........hkg
As for what that looks like in Thymeleaf. Kind of ugly, but I think this should work for you:
Test: [# th:each="g : ${gList}" th:with="newline=${T(System).getProperty('line.separator')}"]
Description:
[(${#strings.replace(g.descr, newline, newline + ' ')})]

Remove tabs or spaces from empty lines

I know PhpStorm allows the option to remove spaces at the end of a line.
Is it possible to configure it to remove tabs or spaces on empty lines?
Example: I type the following
if (1 == 1) {
Then I press enter twice, and I continue coding...
if (1 == 1) {
savePlanet();
The empty line in the middle now has spaces, but I want just an empty line.
You have 2 options here:
Settings | Editor | General, Strip trailing spaces on Save -
when it's set to All, all trailing spaces/tabs are removed on
Save, including the ones on empty lines
Settings | Editor | Code
Style | <Your language> | Tabs and Indents, Keep indents on empty
lines: when disabled, spaces/tabs on empty lines are removed on
code reformatting

How to convert spaces into tabs in ruby on rails correctly?

I'm converting linebreaks and extra spaces.
def simple_format_plus(string)
(h(string).gsub(/\n/, '<br/>').gsub(' ', "\t")).html_safe
end
In my views I'm calling:
<p><%= simple_format_plus(post.content) %></p>
However the html output doesn't show the "\t" part. I've even tried disabling the css, but the problem still persists. For some reason I can't display more than one space in succession.
There are 3 spaces instead of 1 in this line .
still displays as:
There are 3 spaces instead of 1 in this line .
If I inspect the <p> element the extra spaces show up in the developer console however, but not in the browser.
tab can't be interpreted in HTML. You can use &nbsp for three or the number of times you want. The helper method can be re-written like
def simple_format_plus(string)
(h(string).gsub(/\n/, '<br/>').gsub(' ', "&nbsp&nbsp&nbsp")).html_safe
end
Consecutive space characters are interpreted in HTML as a single space. If you want to display each space character as is in the source HTML file, then surround that part with <pre> ... </pre>.

Space in input = html line break?

A followup question to my previous thread:
Disable some html output in input box
I just noticed that everytime I add a space in my input, a line break is automatically added (basically the equivilant of <br> in html.
So if I typed Hello I am John in the input, the output would return:
Hello
I
Am
John
I just want the input to space the text and not add a <br>
So Hello I am John would be Hello I am John as it should be.
Hope I made things clear,
Thanks!
It was just a margin problem that was pushing my text.
write your code as follows
Hello I am John
You can had a space just type
So If u want to type whitespaces without the <br> problem you need to do a javascript function that replace spaces by
function removeSpaces() {
var str = document.getElementById("input").innerHTML;
var res = str.replace(/\s/gi, " ");
document.getElementById("input").innerHTML=res;
}

How to generate a line break in Django template

I want to give default value to a textarea. The code is something like this:
<textarea>{{userSetting.list | join:"NEWLINE"}}</textarea>
where userSetting.list is a string list, each item of whom is expected to show in one line.
textarea takes the content between the tags as the default value, preserving its line breaks and not interpreting any HTML tags (which means <br>,\n won't work).
I have found a solution: {{userSetting.list | join:" " | wordwrap:0}} (there is no whitespace in the list). But obviously it is NOT a good one. Any help would be appreciated.
Since Chris didn't come and collect the credit, I have to answer my question myself. (But still thanks him for pointing to the right direction)
The HTML entity
stands for a NEWLINE character, and won't be interpreted in Django template. So this will work:
<textarea>{{userSetting.list | join:"
"}}</textarea>
A textarea in HTML does respect newlines. Does this not escape the \n:
<textarea>{{userSetting.list | join:"\n"}}</textarea>
I'm thinking that it should turn the \n into a newline character, so your source looks like this:
<textarea>Setting 1
Setting 2
Setting 3</textarea>
This would work if it did, but it may not convert \n correctly.
Try using {{userSetting.list | join:"
"}} if and \n won't work. Let me know how you get on...
:P
For some reason the accepted answer did not work for me, but this did:
<div>{{ list|join:'<br>' }}</div>
Docs reference for join: https://docs.djangoproject.com/en/4.1/ref/templates/builtins/#join