LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-19-2006, 05:52 AM   #1
saltire
Member
 
Registered: Feb 2005
Location: Christchurch, NZ
Distribution: Kubuntu Dapper 6.06
Posts: 43

Rep: Reputation: 15
Formatting code for display in XHTML


I am trying to format some Javascript for display in my blog, so that users can copy and paste it into their own blog templates. However, as the <div> is not wide enough to display the longest line of code, line-breaks get inserted when the page is rendered, breaking the code.

I have tried using <textarea>s but the problem there is that < br /> tags get inserted automatically for every carriage-return/line-feed, again breaking the code.

Does anyone out there know of a way in which the code can be displayed without either resizing the <div>, making the font tiny, or having to add multiple calls to string output functions in order to shorten the lines of code?

I need some sort of joining entity which permits line-breaking the code when it is displayed but which keeps the original formatting intact when copied and pasted.

I'm totally stumped - there is probably a really simple solution, but I'm too glazed to see it right now.

Thanks in advance,

Saltire
 
Old 09-19-2006, 06:58 AM   #2
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
Have you tried using <pre> ... </pre> tags?
 
Old 09-19-2006, 07:47 AM   #3
saltire
Member
 
Registered: Feb 2005
Location: Christchurch, NZ
Distribution: Kubuntu Dapper 6.06
Posts: 43

Original Poster
Rep: Reputation: 15
Hey Spudley,

Genius!

Yes, I just gave it a go. While it works in preserving the formatting, it looks terrible, as the text is no longer confined to the <div>, and gets rendered on top of and behind other stuff.

Thanks for the reminder about <pre></pre>, though.

My blog is at http://theincomer.blogspot.com/ if you want to take a look at what I mean.
 
Old 09-19-2006, 08:04 AM   #4
lorebett
Member
 
Registered: May 2004
Location: Italy
Distribution: Ubuntu, Gentoo
Posts: 57

Rep: Reputation: 16
let me advertise http://www.gnu.org/software/src-highlite/

 
Old 09-19-2006, 08:35 AM   #5
saltire
Member
 
Registered: Feb 2005
Location: Christchurch, NZ
Distribution: Kubuntu Dapper 6.06
Posts: 43

Original Poster
Rep: Reputation: 15
Ah well. Don't worry about it folks. I have removed the post containing the offending code.

I thinks this is a feature lacking in XHTML, and surely must affect coders and scripters the world over...
 
Old 09-19-2006, 03:02 PM   #6
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
Perhaps something like this?

Code:
<pre stlye="width: 100px; overflow:hidden;">
A really really really really really really really really long line of text.
</pre>
You can also use "overflow: scroll" to get a scroll bar if you want to still get to the end of the line somehow.
 
Old 09-20-2006, 09:08 AM   #7
saltire
Member
 
Registered: Feb 2005
Location: Christchurch, NZ
Distribution: Kubuntu Dapper 6.06
Posts: 43

Original Poster
Rep: Reputation: 15
I think you've cracked it! Excellent: much thanks. Have you had the same issue?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Display Unicode Code from a String in Java? rusty_turkey Programming 3 08-10-2006 05:36 PM
Cell formatting code in KSpread/OpenOffice montylee Linux - General 0 01-28-2006 11:21 AM
getting vb code to display correctly paul62 LQ Suggestions & Feedback 1 12-11-2005 11:19 PM
2 Problems, one with CODE, and one with DISPLAY... Ausar Linux - Newbie 7 08-10-2004 04:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration