Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Keep carriage returns from Notepad in HTML


  • Please log in to reply
3 replies to this topic

#1 usasma

usasma

    Still visually handicapped (avatar is memory developed by my Dad


  • BSOD Kernel Dump Expert
  • 25,089 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Southeastern CT, USA
  • Local time:10:15 AM

Posted 20 October 2015 - 04:00 PM

I'm trying to create a new html page for my website.

It's from a notepad file - but when I paste it into the html document the carriage returns are all removed and the page is a jumble of text.

This is a very large page, so it's not feasible to manually replace the CR with a BR tag

I've done this in the past, but cannot recall how.

Any suggestions?

 

Here's what the output should look like:  http://www.carrona.org/ntstatus-8-1.html

FYI - this is the W8.1 version, I'm trying to make the W10 version.


My browser caused a flood of traffic, sio my IP address was banned. Hope to fix it soon. Will get back to posting as soon as Im able.

- John  (my website: http://www.carrona.org/ )**If you need a more detailed explanation, please ask for it. I have the Knack. **  If I haven't replied in 48 hours, please send me a message. My eye problems have recently increased and I'm having difficult reading posts. (23 Nov 2017)FYI - I am completely blind in the right eye and ~30% blind in the left eye.<p>If the eye problems get worse suddenly, I may not be able to respond.If that's the case and help is needed, please PM a staff member for assistance.

BC AdBot (Login to Remove)

 


#2 packetanalyzer

packetanalyzer

  • Members
  • 954 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Local time:10:15 AM

Posted 20 October 2015 - 04:58 PM

If you are using Notepad, can't you use find and replace to change "CR" to "BR"?

 

If you are going to write a website in a text editor (you might want to consider a full web editor if you are going to do professional web development) maybe Notepad++ would be a better solution.



#3 Guest_hollowface_*

Guest_hollowface_*

  • Guests
  • OFFLINE
  •  

Posted 21 October 2015 - 01:29 AM

Packetanalyzer has already answered your question, but here are a couple other options just in case :).

The simple solution would be to use a <pre> tag around the pasted content (eg: <pre>content</pre>).

Demo Code (save as demo.html):

<!DOCTYPE html>
<html>
<head>
<title>Pre tag demo</title>
</head>
<body>
<pre>
This is a demo of a pre tag. Pre standing for pre-formatted.
As you can see there isn't a single br tag in use, but the
text isn't all appearing on a single line. :)
</pre>
</body>
</html>

A more advanced solution would be to use a text-substitution tool to replace newlines with <br> tags. I'm assuming you're using Windows, for which I'm unfamilair with the available tools, but on the off chance you're using GNU/Linux, you can use the below example (provided Sed, Tr, and Cat are installed on your distro). You'll need to substitute the correct file path and name for
both the input and the output text files, substitute the "~" in the tr command for a character that isn't used in the document anywhere (you can keep it as a "~" if that fits the bill), and lastly copy the outputted content from the output text file into your html page.

 

Example Substitution Command Using Tr & Sed:

cat ~/input.txt | tr "\n" "~" | sed 's/~/<br>/g' > ~/output.txt

(This can be done directly with Sed, no need for Tr, making it much easier, but that's beyond my skillz.)

Demo Code (save as demo.html):

<!DOCTYPE html>
<html>
<head>
<title>Br tag demo</title>
</head>
<body>
This is a demo of a pre tag. Pre standing for pre-formatted.<br>As you can see there isn't a single br tag in use, but the<br>text isn't all appearing on a single line. :)<br>
</body>
</html>

Edited by hollowface, 21 October 2015 - 01:29 AM.


#4 usasma

usasma

    Still visually handicapped (avatar is memory developed by my Dad

  • Topic Starter

  • BSOD Kernel Dump Expert
  • 25,089 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Southeastern CT, USA

Posted 22 October 2015 - 04:41 PM

I can't see the CR's in Notepad, so I can't do a search/replace.

I looked in WordPad and Notepad++ also.

 

Fortunately, the <pre></pre> tag worked like a charm.

Here's the page:  http://www.carrona.org/ntstatus-10.html


My browser caused a flood of traffic, sio my IP address was banned. Hope to fix it soon. Will get back to posting as soon as Im able.

- John  (my website: http://www.carrona.org/ )**If you need a more detailed explanation, please ask for it. I have the Knack. **  If I haven't replied in 48 hours, please send me a message. My eye problems have recently increased and I'm having difficult reading posts. (23 Nov 2017)FYI - I am completely blind in the right eye and ~30% blind in the left eye.<p>If the eye problems get worse suddenly, I may not be able to respond.If that's the case and help is needed, please PM a staff member for assistance.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users