Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 883969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:40:48+00:00 2026-05-15T12:40:48+00:00

When i populate a textarea with text using \r\n (carriage return – newline) the

  • 0

When i populate a textarea with text using \r\n (carriage return – newline) the text is formatted improperly [UPDATE: \r\n is what is generated when filling out a textarea, i’m simply pulling from a database what was previously filled in. Also to note, in the production environment i don’t seem to have this problem. END UPDATE] For example:

%textarea  
  = "hello\r\nHow are you?"

comes out like this:

hello  
        How are you?

I’m thinking this might have something to do with HAML. Can anyone help me out?
Note: if i use \n\r it works fine, but thats technically incorrect and id have to do some gsubs to reverse them for proper display.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:40:49+00:00Added an answer on May 15, 2026 at 12:40 pm

    Because Haml automatically indents the HTML source code, the contents of whitespace-sensitive tags like pre and textarea can get screwed up. The solution is to replace the newlines inside these tags with HTML newline entities 
, which Haml does using the Haml::Helpers#preserve and Haml::Helpers#find_and_preserve helpers.

    Normally, Haml will do this for you automatically when you’re using a tag that needs it (this can be customized using the :preserve option). For example,

    %p
      %textarea= "Foo\nBar"
    

    will be compiled to

    <p>
      <textarea>
    Foo&#x000A;Bar</textarea>
    </p>
    

    However, if a helper is generating the tag, Haml can’t detect that and so you’ll have to call Haml::Helpers#find_and_preserve yourself. You can also use ~, which is the same as = except that it automatically runs find_and_preserve on its input. For example:

    %p= find_and_preserve "<textarea>Foo\nBar</textarea>"
    

    is the same as

    %p~ "<textarea>Foo\nBar</textarea>"
    

    and renders

    <p><textarea>Foo&#x000A;Bar</textarea></p>
    

    Source: this Haml FAQ.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to populate an array with the text value of a json
I have a drop-down list which causes a text-area to populate with different text
I'm wondering how I can populate a text box in my view from a
I have this function that successfully populates a textarea with text from a select,
I have a field in MySQL of type text, using the following collation: utf8_general_ci
I have this following string that I am trying to populate a textarea with
How do I auto-populate the text area below with two PHP variables, $submission and
I have 3 tinymce textarea, in my page. And I want to populate these
I know how to populate a textarea, but how to populate it so that
I populate my tabs contents using AJAX calls with the tabs widget from jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.