line-breaks

display line breaks asp.net mvc razor

烂漫一生 提交于 2019-11-28 22:55:53
I'm using the following to make the text output the line breaks entered in a <textarea> HTML element. MvcHtmlString.Create(Model.Post.Description.Replace(Environment.NewLine, "<br />")) Is there a nicer way to do this? Your code is vulnerable to XSS attacks as it doesn't HTML encode the text. I would recommend you the following: var result = string.Join( "<br/>", Model.Post.Description .Split(new[] { Environment.NewLine }, StringSplitOptions.None) .Select(x => HttpUtility.HtmlEncode(x)) ); return MvcHtmlString.Create(result); and then in your view you can safely: @Html.SomeHelper() There's an

use xsl to output plain text

二次信任 提交于 2019-11-28 18:15:29
I needed to use XSL to generate simple plain text output from XML. Since I didn't find any good, concise example online, I decided to post my solution here. Any links referring to a better example would of course be appreciated: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" > <xsl:output method="text" omit-xml-declaration="yes" indent="no"/> <xsl:template match="/"> <xsl:for-each select="script/command" xml:space="preserve">at -f <xsl:value-of select="username"/> <xsl:value-of

Remove extra line breaks after Html.fromHtml()

痞子三分冷 提交于 2019-11-28 17:28:01
I am trying to place html into a TextView. Everything works perfectly, this is my code. String htmlTxt = "<p>Hellllo</p>"; // the html is form an API Spanned html = Html.fromHtml(htmlTxt); myTextView.setText(html); This sets my TextView with the correct html. But my problem is, having a tag in the html, the result text that goes into the TextView has a "\n" at the end, so it pushes my TextView's height higher than it should be. Since its a Spanned variable, I can't apply regex replace to remove the "\n", and if I was to convert it into a string, then apply regex, I lose the functionality of

PHP nl2br() basic function

[亡魂溺海] 提交于 2019-11-28 10:38:06
Can somebody please help me with this mail script. I'm simply trying to send an html email and part of the message is from a user textarea, which puts in \r\n. I seem to be unable to use nl2br or any other similar function. The code below isn't what I'm using but still produces the error. The code: $to = 'example@gmail.com'; $subject = 'Test Subject'; $message_var_1 = 'test1 \r\n test2 \r\n test3'; $message = nl2br(" <div> <div>$message_var_1</div> </div> "); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'X-Mailer: PHP/

How to make JTextPane line break [duplicate]

只谈情不闲聊 提交于 2019-11-28 09:35:36
问题 This question already has an answer here: JTextPane does not go to a new line? 3 answers In Java Swing , The JTextPane do have word wrap when text exceeded width , but it does NOT line break for if there was a very long non-space string How can I making line break for long non-space string in JTextPane ? Any ideas would be much appreciated, thanks. 回答1: To allow letter wrap LabelView should be modified to override min width java-sl.com/tip_letter_wrap_java7.html you have to define min width

Smarter word-wrap in PHP for long words?

眉间皱痕 提交于 2019-11-28 09:10:25
I'm looking for a way to make word-wrap in PHP a bit smarter. So it doesn't pre-break long words leaving any prior small words alone on one line. Let's say I have this (the real text is always completely dynamic, this is just to show): wordwrap('hello! heeeeeeeeeeeeeeereisaverylongword', 25, '<br />', true); This outputs: hello! heeeeeeeeeeeeeeereisavery longword See, it leaves the small word alone on the first line. How can I get it to ouput something more like this: hello! heeeeeeeeeeee eeereisaverylongword So it utilizes any available space on each line. I have tried several custom

Alternatives to illegal <br> or <p> within <li> tags on a hover?

久未见 提交于 2019-11-28 07:32:40
问题 Does anyone have a suggestion for creating paragraph-type line spaces within a <li> tag that includes a hovered pop-up pseudo-class? I have a <span> that pops up on a:hover and I want the text that pops up to be broken into 2 paragraphs. It works with <br> in FF but I want to do the right thing (now that I've discovered it's wrong!)... html: <div id="rightlist"> <ul> <li><a href="">List item <span> words words words that are "paragraph" 1 of List item <br><br> different words that make up

Finding line break and carriage return (\\r\\n) in MySQL

守給你的承諾、 提交于 2019-11-28 07:17:10
I can't seem to find any info about this on the internet (or I'm just not looking in the right direction). I have a few fields in my MySQL database containing a carriage return and line break \r\n . Is there somebody who can tell me how to find them by using a query?? SELECT * FROM mytable WHERE mycolumn REGEXP "\r\n"; finds all records in mytable where mycolumn contains a \r\n sequence. 来源: https://stackoverflow.com/questions/10997159/finding-line-break-and-carriage-return-r-n-in-mysql

Elegant solution for line-breaks (PHP)

蹲街弑〆低调 提交于 2019-11-28 06:20:05
$var = "Hi there"."<br/>"."Welcome to my website"."<br/>;" echo $var; Is there an elegant way to handle line-breaks in PHP? I'm not sure about other languages, but C++ has eol so something thats more readable and elegant to use? Thanks Pascal MARTIN For linebreaks, PHP as "\n" (see double quote strings ) and PHP_EOL . Here, you are using <br /> , which is not a PHP line-break : it's an HTML linebreak. Here, you can simplify what you posted (with HTML linebreaks) : no need for the strings concatenations : you can put everything in just one string, like this : $var = "Hi there<br/>Welcome to my

Carriage Return/Line Feed in .Net Resource File (App_GlobalResources)

独自空忆成欢 提交于 2019-11-28 06:07:30
I'm keeping several texts in an App_GlobalResources.resx file. The texts have to be multi-line and I need to have them contain line feeds. However, when I read the contents, all line feeds are gone ( \r\n is printed, not as CRLF 10 13 control character). I know that I could work around this by re-replacing \r\n (or anything else for that matter) back to CRLF when I read the contents, but I wondered why these clearly text-targeted resx files ignore control characters - and CRLF is kind of important - and if anybody knows if there's a setting or something that would enable this to work naturally