Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Replacing - and not Replacing...

Reply
Thread Tools

Replacing - and not Replacing...

 
 
Rob Meade
Guest
Posts: n/a
 
      04-05-2005
Hi all,

Been a long time since I've been here...

/me waves to all..

Ok - my conundrum..

I have a form where a user can enter text and BB codes...for example:

bold text

I then parse the form when submitted with something like this:

strContent = Replace(strContent, "", "<b>")
strContent = Replace(strContent, "
", "</b>")

Content is then written to the database, when displayed out comes the html.
If they want to edit the content again it goes through the parser again but
in reverse affectively and puts all the square brackets back in...

My problem is around the carriage returns...

At the moment I am replacing a vbCRLF with <br> - the problem is when they
have something like this:

[table]
[tr]
[td]my cell[/td][td]my second cell[/td]
[/tr]
[/table]

I get a load of <br>'s that I don't really want, and of course because the
table stuff in this case is replaced with the html for the table the <br>'s
appear above it pushing it down the page - nightmare...

What I am after I suppose is a way of being able to say - change a vbCRLF
for a <br> but only if it's not proceeding any of the following....

My initial thoughts were parse again - and remove and <br>'s if they are
joined to say any of the above tags...

strContent = Replace(strContent, "</tr><br>", "</tr>")

for example...but it's not pretty, it doesn't feel "clever" and would
require a load of additional parsing where mistakes could easily be made...

The square bracketting tags etc will remain regardless of how this is
resolved, so please no suggestions for css etc, but if anyone has any
'compatible' ideas please let me know.

Regards

Rob



 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      04-05-2005
"Curt_C [MVP]" wrote ...

>I dont know RegEx that well but maybe only do your replace if the <br> is
>after a ] and before a [/


Hi Curt, thanks for the reply.

I am not overly familar with RegEx myself, but will take a look...I'm not
sure where I'll need to do the replaces anyway, as they could have this:

Hello Curt,

Welcome to our website.

Enjoy your visit.


So, that would look something like this:

Hello <b>Curt</b>,<br><br>Welcome to our website.<br><br>Enjoy <i>your</i>
visit.

In this case I'd want the vbCRLF's changed to <br>'s are the end of each
line, and on the blank lines, and obviously that wouldn't be between a ] and
a [/ etc...

Another difficulty are the tags that they can still enter html attributes
in...for example:

I enable them to have

[table] or [table ...]

with ... being whatever they want to enter, perhaps [table width="100"] when
I parse this its more difficult because you dont have a predetermined piece
of text, they could enter 300, 300%, 30000 for example...

Regards

Rob


 
Reply With Quote
 
 
 
 
Chris Hohmann
Guest
Posts: n/a
 
      04-06-2005
"Rob Meade" <(E-Mail Removed)> wrote in message
news:53B4e.4572$(E-Mail Removed) ...
> Hi all,
>
> Been a long time since I've been here...
>
> /me waves to all..
>
> Ok - my conundrum..
>
> I have a form where a user can enter text and BB codes...for example:
>
> bold text
>
> I then parse the form when submitted with something like this:
>
> strContent = Replace(strContent, "", "<b>")
> strContent = Replace(strContent, "
", "</b>")
>
> Content is then written to the database, when displayed out comes the
> html. If they want to edit the content again it goes through the parser
> again but in reverse affectively and puts all the square brackets back
> in...
>
> My problem is around the carriage returns...
>
> At the moment I am replacing a vbCRLF with <br> - the problem is when they
> have something like this:
>
> [table]
> [tr]
> [td]my cell[/td][td]my second cell[/td]
> [/tr]
> [/table]
>
> I get a load of <br>'s that I don't really want, and of course because the
> table stuff in this case is replaced with the html for the table the
> <br>'s appear above it pushing it down the page - nightmare...
>
> What I am after I suppose is a way of being able to say - change a vbCRLF
> for a <br> but only if it's not proceeding any of the following....
>
> My initial thoughts were parse again - and remove and <br>'s if they are
> joined to say any of the above tags...
>
> strContent = Replace(strContent, "</tr><br>", "</tr>")
>
> for example...but it's not pretty, it doesn't feel "clever" and would
> require a load of additional parsing where mistakes could easily be
> made...
>
> The square bracketting tags etc will remain regardless of how this is
> resolved, so please no suggestions for css etc, but if anyone has any
> 'compatible' ideas please let me know.
>
> Regards
>
> Rob


Why don't you simply store the content as submitted, then parse to html when
you need to display? This is similar to data entered in textarea controls.
You don't insert <br> tags when you capture the data to a database, only
when you display it.


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-11-2005
"Curt_C [MVP]" wrote ...

> Then you are probably going to have to train your users. I mean if they
> put in a break then THEY put in a break. You are just doing what they
> want.


Users eh! *tut* )

If I did that though, the tables support for example to appear correctly
would have to be entered all on one line...a complex table layout would be
almost impossible to decipher if there was anything wrong with it, if they
enter it all on one line that's up to them, but my parsing I believe needs
to ignore the carriage returns in between table tags (opening and closing) -
when after cells and rows anyway...

Regards

Rob


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      04-11-2005
"Chris Hohmann" wrote ...

> Why don't you simply store the content as submitted, then parse to html
> when you need to display?


Hi Chris, thanks for the reply.

I thought of this when I first starting writing it some 2+ years ago, the
site in question gets a reasonable amount of traffic each month, the biggest
I've worked on thus far, not necessarily huge in comparision to Amazon and
the like though, but still, I decided to parse once, store to SQL Server,
then on the displaying page all the app has to do is get the content and
dump to the page, no further formatting is needed because the CSS handles
the rest - if I did it the other way, *every* user would trigger a parse of
the content for every page - I figured this would cause a bit of a
performance over head.

> This is similar to data entered in textarea controls. You don't insert
> <br> tags when you capture the data to a database, only when you display
> it.


Normally I'd agree with that, if it was just some text and some carriage
returns, but because they are entering all kinds of formatting in there as
well, bold, italics, lists, tables and the like that needs to be changed
anyway, so it all gets done in the one swoop..

Regards

Rob


 
Reply With Quote
 
Chris Hohmann
Guest
Posts: n/a
 
      04-11-2005
"Rob Meade" <(E-Mail Removed)> wrote in message
news:wXx6e.9695$(E-Mail Removed) ...
> "Chris Hohmann" wrote ...
>
>> Why don't you simply store the content as submitted, then parse to html
>> when you need to display?

>
> Hi Chris, thanks for the reply.
>
> I thought of this when I first starting writing it some 2+ years ago, the
> site in question gets a reasonable amount of traffic each month, the
> biggest I've worked on thus far, not necessarily huge in comparison to
> Amazon and the like though, but still, I decided to parse once, store to
> SQL Server, then on the displaying page all the app has to do is get the
> content and dump to the page, no further formatting is needed because the
> CSS handles the rest - if I did it the other way, *every* user would
> trigger a parse of the content for every page - I figured this would cause
> a bit of a performance over head.
>
>> This is similar to data entered in textarea controls. You don't insert
>> <br> tags when you capture the data to a database, only when you display
>> it.

>
> Normally I'd agree with that, if it was just some text and some carriage
> returns, but because they are entering all kinds of formatting in there as
> well, bold, italics, lists, tables and the like that needs to be changed
> anyway, so it all gets done in the one swoop..
>
> Regards
>
> Rob
>


Ok. It looks like you have a few options here:
1. Create a complex de-parsing algorithm that distinguished between display
linebreaks and markup linebreaks. This methodology will never be foolproof.

2. Introduce an explicit break tag into your custom markup language, perhaps
"[b]"? This of course raises the question, "Why use a custom markup at all?
Why not simply use HTML to begin with?"

3. Save both the original text and the parsed text when inserting/updating
data. To improve performance, you could save the original and parsed text to
files and simply store file references in the database. Here's an article on
the merits of storing file references instead of the actual data. It focuses
on image files, but it actually applies to any large file:
http://aspfaq.com/show.asp?id=2149

HTH
-Chris Hohmann



 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
subprocess.Popen not replacing current process? goodman Python 4 11-05-2010 01:54 AM
replacing (not overriding) a core Java class with a custom one Adam Monsen Java 3 01-27-2009 02:38 AM
Dynamic dropdows appending not replacing second dropdown items seanmayhew@gmail.com ASP .Net 1 04-16-2005 04:04 PM
Replacing words from strings except 'and' / 'or' / 'and not' Nico Grubert Python 9 11-28-2004 11:33 PM
Re: Replacing words from strings except 'and' / 'or' / 'and not' Alexandre Cecchi Python 5 11-27-2004 04:33 PM



Advertisments