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;
}
Related
So I have a tibble. assume that I have this string in a cell : cases(>20yo), cases(<20yo) other
I try cases(>20yo), cases(<20yo) <br> other . but other does not go to the next line in html output. it only works if I replace < in <20yo.
is there any reason behind this? how can I fix this. I am not bring the code since it does not show the output anyways and I assume this is a general question rather an a code specific. Thanks
Hi I have a model variable "name", which is binded to a span like
<input type="text" ng-model="name">
<span ng-bind="name"></span>
What my requirement is that to show up the text that are entered in the input field without eliminating any spaces.
I find a way to achive that by writing a css property
.allow-spaces{
white-space:pre;
}
so now if I enter a value "hello ooo buddy" it will show up exactly same in the span as well, but it will not show spaces at the begining like " hello buddy" is shown as "hello buddy". Please suggest me a solution for this.
ngModel by default trims beginning and trailing white spaces in input[type=text]. To disable this behavior write ng-trim=false in the input element.
Reference
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
I use an html parser (Neko) in order to extract the free-text of an html document.
Since I'm interested in text's semantic I must give special attention to the distance between words as it appears in browser.
for example:
<H1>My
title</H1>
<P>Hello
World</P>
Is rendered as:
My title
Hello world
While containing the paragraph inside <pre> tags or with style:
<style>
p { white-space:pre; }
</style>
would result:
My title
Hello
World
which I would like to treat differently since "Hello" for that matter is not semantically tied to the word "World". As said in other posts - there's a difference between what parsing does and what rendering does. I'm interested in the connection between words as it appears after rendering since obviously parsing doesn't collapse white-spaces as would been shown on browser.
Is there any way to extract whitespace-collapsed text from html as it's read on browser?
I have not used Neko before, but you will need to access the styles of the elements and see if the white-space property is set to either pre, pre-wrap, or preline.
If it is either pre or pre-wrap, replace any whitespace group in the text with a single space.
Else if pre-line, only replace groups of spaces/tabs with a single space.
Else, do not modify the text.
Here's an example using JQuery: JSFiddle
JQuery
function getRenderedText(obj) {
var text = obj.text();
var renderedText;
switch (obj.css('white-space')) {
case 'pre':
case 'pre-wrap':
renderedText = text;
break;
case 'pre-line':
renderedText = text.replace(/[ \t]+/,' ');
break;
default:
renderedText = text.replace(/\s+/,' ');
}
return renderedText;
}
Just look at this basic info on w3schools
http://www.w3schools.com/cssref/pr_text_white-space.asp
and a bit better explained with examples:
http://css-tricks.com/almanac/properties/w/whitespace/
i also think that you have to put hello in 1 <p> and world in another for the effect to work.
otherwise they both go to the right.
I found some great javascript code(xpHTMLMail file) to be able to create an HTML e-mail that the users create on the fly from an xpage document that they write a review on a salesperson. However, there are some Multiline edit boxes on there and they have carriage returns, spaces, etc in them. These do not come over when they are added to the HTML. Anything I can do to keep the formatting for the e-mail that is created? Thanks in advance.
Here's the code that deals with this part of my question(inputClosing is a Multiline Edit Box):
mail.addHTML("<br /><br /><b>Closing</b><br />"+getComponent('inputClosing').getValue())
If inputClosing has...
"Dear Joe,
Great work. Keep it up!
Thanks,
Bill"
It comes into the email as...
Dear Joe, Great Work. Keep it up! Thanks, Bill
I wrote that library so thanks!
Since you're creating an HTML mail, you need to replace the line breaks in the value of the Multiline Edit Box by <br /> tags. Since you're dealing with Java in XPages, the line breaks are stored in the value using the \r\n sequence.
You can replace them using the the replaceAll() or (SSJS) #ReplaceSubstring() function.
Your code might then look like this:
var content:string = getComponent("inputClosing").getValue();
mail.addHTML("<b>Closing</b><br />" + content.replaceAll("\r\n", "<br />") );
Mark's suggestion definitely works, but it might be easier just to wrap the text fields with <pre></pre> then it will treat them as text instead of html, no matter what kind of formatting character is in it.