This question already has answers here:
Line break in HTML with '\n'
(10 answers)
Closed 5 years ago.
I know I am revisiting an old problem but I hope there are new answers. I am using angular/Modal to display a paragraph from a .json file. I need to insert a newline for each paragraph when displayed in the browser. I have tried \n ,\r, This is a sample of an entry:
"termsAndServiceContent": "1. TERMS OF USE: \n These Terms of Use (Terms) govern your access or use, from within the United States and its territories and possessions ...........\r <br/> By accessing or using the Services, you confirm your agreement to be bound by these Terms........",
I expected to get a new line for the \n and \r but nothing happens. How can I get the browser to recognize the escape characters?
I guess the question is quite similar and I did mentioned that its an old issue. I really didn't see this
https://stackoverflow.com/questions/39325414/line-break-in-html-with-n
question before but I still don't believe the answers address my issue. I am not using plain HTML I am using Angular and my render code looks like this:
<a (click)="showTermAndServicesWindow($event)">{{LOCALIZATION.tos}}</a>
where .tos is my .json file and that's all the HTML I want in the view....also I don't want to do any HTML templating in the .ts modules.
Use the HTML code <br> for new lines, and make sure you use <div [innerHTML]="theHtmlString"></div> to insert it as HTML.
Related
This question already has answers here:
Proper way to restrict text input values (e.g. only numbers)
(18 answers)
Closed 2 years ago.
User is allowed to enter all the alphabets and numbers but when the special-characters are entered then it shouldn't be entered in the the text box.
I tried doing this using (ng-pattern-restrict) but it's not working as expected, I think it might be possible that it needs to be imported in
app-module.ts but not working.
HTML FILE
#Shashank has a valid point of view. What you want to do is disable the entry of special characters from the backend, as well as render the field invalid from the frontend. A hacker knowing what they're doing would easily manipulate the HTTP Request itself rather than the field, making it pretty vulnerable.
However, if you insist on your solution, I would recommend using RegEx. This sample expression might come in handy. That way, whenever the input field detects one of these special characters, it would replace that character with a ''
This question already has answers here:
String attribute values in multiple lines, HTML
(6 answers)
Adding a linebreak in some attribute string(like src or href ) in HTML / XML source
(1 answer)
Closed 3 years ago.
I have an HTML element that looks something like,
<element src="http://lsdjflksjdfkjewiojeriowjekwjekfljsdkfjisdjrsekjfijsiejisjojfsjlfejeileldjfsleisldkjfsiejljefijeljslefifjfsleif">
</element>
See how long that is?
I want to break up the src link into multiple lines.
In Python you would just use \ to break a long string into multiple lines. In JavaScript, you just use + "rest of string" to break it into multiple lines. What is the case for HTML? The browser wants to interpret my attempt as white space...
So when I did:
<element
src="http://lsdjflksjdfkjewiojeriowjekwjekfljsdkf
jisdjrsekjfijsiejisjojfsjlfejeileldjfsleisldkjfsiejljefi
jeljslefifjfsleif">
</element>
It inserted a bunch of %20 where the line breaks were. What else should I try?
On a similar post on Stack Overflow that addresses this issue, it suggests using JavaScript to split the lines up, which seems like overkill, and the answer that suggested splitting after '/'s in the URL seems not to work unless you cram the entire element on the left side of the page which would cause horrible formatting issues... Otherwise, it still put spaces in the link.
Google URL Shortener has been retired and has transitioned to Firebase Dynamic Links.
But in general, using a link shortener for external resources is a pretty terrible idea. There will inevitably be some overhead in using an external link shortener, you'll be at their mercy in the event of an outage or EOL, and there may be the possibility of redirect/poison attacks as well.
This question already has answers here:
How do I display PHP code in HTML?
(4 answers)
Closed 8 years ago.
I want to post a sample of some code I've written. I'm aware of the <code></code> tags, but the problem is that the PHP inside will actually get interpreted and executed when the page loads. What is the way around this?
You should be encoding your entities anyway, which will prevent PHP from parsing them.
Instead of <?php, use <php.
See also: What Are The Reserved Characters In (X)HTML?
If you want to display the source of an entire PHP script, you can use the show_source() function. For example,
show_source("sample.php");
If you want to display the code of the current page, you can do something like
show_source(__FILE__);
You can also use hightlight_file() in place of show_source().
If you were looking to display just a random line of code, you can use htmlspecialchars() or htmlentities(). For example,
htmlspecialchars(" <b> This will be a bold text </b> ");
A tip on the aside: Please look around, and google atleast once before asking. :)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I use a carriage return in a HTML tooltip?
Currently if I want to insert a new line in title=, I would do this:
<span id="dummy" title="Hello
World!">Dummy</span>
Live demo: http://jsfiddle.net/DerekL/XFMfx/
But this looks really weird to me, and it just messes up my HTML file. Just imagine all those new lines in it.
So I'm wondering if there is a better way to achieve this, so that it won't mess it up.
Thanks.
This is not possible. There are no cross-browser solutions. If you want a line break in your title attribute, you'll have to use JavaScript.
As of Firefox 12 (which is the current Aurora version), this is (finally) supported. See the related bug.
This question already has answers here:
RegEx match open tags except XHTML self-contained tags
(35 answers)
Closed 8 years ago.
I am trying to build a regular expression to extract the text inside the HTML tag as shown below. However I have limited skills in regular expressions, and I'm having trouble building the string.
How can I extract the text from this tag:
text
That is just a sample of the HTML source of the page. Basically, I need a regex string to match the "text" inside of the <a> tag. Can anyone assist me with this? Thank you. I hope my question wasn't phrased too horribly.
UPDATE: Just for clarification, report_drilldown is absolute, but I don't really care if it's present in the regex as absolute or not.
145817 is a random 6 digit number that is actually a database id. "text" is just simple plain text, so it shouldn't be invalid HTML. Also, most people are saying that it's best to not use regex in this situation, so what would be best to use? Thanks so much!
The answer is... DON'T!
Use a library, such as this one
([^<]*)
This won't really solve the problem, but it may just barely scrape by. In particular, it's very brittle, the slightest change to the markup and it won't match. If report_drilldown isn't meant to be absolute, replace it with [^']*, and/or capture both it and the number if you need.
If you need something that parses HTML, then it's a bit of a nightmare if you have to deal with tag soup. If you were using Python, I'd suggest BeautifulSoup, but I don't know something similar for C#. (Anyone know of a similar tag soup parsing library for C#?)
I agree regex might not be the best way to parse this, but using backreference it's easily done:
<(?<tag>\w*)(?:.*)>(?<text>.*)</\k<tag>>
Where tag and text are named capture groups.
hat-tip: expresso library
<a href\=\"[^\x00]*?\">
should get you the opening tag.
<\/a>
will give you the closing tag. Just extract out what is in between. Untested though.