Gossamer Forum
Home : Products : DBMan : Customization :

Keep original text formating in output

Quote Reply
Keep original text formating in output
Your last mod for putting the spaces back into my description field works 90%, it works on all paragraphs except the first line of the field. Hmmm

Quote:
Keeping the indenting is basically the same as keeping the carriage returns. Again, the spaces are there, but html doesn't show them.

After

$rec{'Description'} =~ s/\n/<BR>/g;

add

$rec{'Description'} =~ s/ /& nbsp;& nbsp;/g;

(In case it doesn't show up in the UBB page, that's 2 spaces after the s/ -- Also, take out the space between the & and the nbsp; I had to separate them so they would show up at all.)

What that will do is substitute two non-breaking spaces wherever there are two spaces in your field. If you wanted to indent by five spaces, you could put 5 spaces in the first part and 5 & nbsp; in the second part.

The structure for this is


code:
--------------------------------------------------------------------------------

$rec{'FieldName'} =~ s/[what you want replaced]/[what you want to replace it with/g;

--------------------------------------------------------------------------------

The s part means "substitute" and the g part means "global" -- replace all instances. If you don't use the g, it will only replace the first one it finds.

A bonus for me is that I use two spaces after sentences for better readability and this mod puts those back it too. I like that a lot. I usually indent five spaces so the mod converts those to four which is perfectly fine. Now I just need help figuring out why it doesn't work on the first line.

I was think about the a few possible catch 22's, I am going to experiment and see what the mod will do to non-standard paragraph formatting. Let's say I wanted to do a list or insert a Perl routine.

Here is an example of how it is working. Notice the first paragraph is not being indented.

http://www.makeitsimple.com/...sitenews/index.shtml
------------------
Larry "NgtCrwlr" Mingus
www.makeitsimple.com

[This message has been edited by NgtCrwlr (edited May 17, 1999).]
Quote Reply
Re: Keep original text formating in output In reply to
That's because of a line in db.cgi, sub join_encode

$tmp =~ s/^\s+//g; # Trim leading blanks...

You could take that out if you wanted to, but it could cause problems. (I can't think what they would be right now, but it could. Smile )

Probably the best solution would be to remember to add a & nbsp; (remember to take out the space!) at the beginning of your field. Then your formatting won't be lost.

If you're likely to forget, you could add the & nbsp; as a default value for the field. Be sure to put it in quotes though, like

'& nbsp;'

or DBMan will think it's a subroutine like &get_date.



------------------
JPD





Quote Reply
Re: Keep original text formating in output In reply to
I forgot about responding to some of your post.

You mentioned a list or a perl routine. You can put html coding right into the subroutine and it will work. The only thing you can't put in is an SSI. (Maybe you could even do that withint a text field.)



------------------
JPD