469,282 Members | 1,909 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

how to transform a list form of hyphens to an html unordered list

Hi all,

I have a question which I have no ideal of the answer...I am currently
working on a web application and at some time, I have a string
representing a short text. This could be a simple example :

"This is my list :\n\r-list item 1\n\r-list item 2\n\r-list item
3\n\r\n\rThis was a great list."

Let's say this outputs like that :
-------------------------------------------
This is my list :
-list item 1
-list item 2
-list item 3

This was a great list.
-------------------------------------------

Would it be simple with regular expression to transform the list formed
of hyphens("-") to an HTML unordered list? I mean that the preceding
example would rather output as :
-------------------------------------------
This is my list :
<ul><li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li></ul>

This was a great list.
-------------------------------------------

I have some experience with regular expression but have not a clue on
how to do this...I also see some problems as if the string starts with
an hyphen, as it would also need to transform correctly, event if it
doesn't have the /n/r before the hyphen("-").
e.g. "-list item 1/n/r- list item 2" should output as :
-------------------------------------------
<ul><li>list item 1</li>
<li>list item 2</li><ul>
-------------------------------------------

And what about if there are two lists separated by some carriage
returns?...As you can see, I really don't know where to start with this
problem. :/

Thanks in advance,

ibiza

Feb 9 '06 #1
5 2064
Do you have a finite list of ways that this information could be formatted?
For instance, do you allow spaces before and after the dash (-) or maybe
returns between each list item? In other words, is the information that you
receive predictable?

If it is predictable, I would just go through the list one line at a time
and output it into a new string with the appropriate markup.

"ibiza" <la******@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi all,

I have a question which I have no ideal of the answer...I am currently
working on a web application and at some time, I have a string
representing a short text. This could be a simple example :

"This is my list :\n\r-list item 1\n\r-list item 2\n\r-list item
3\n\r\n\rThis was a great list."

Let's say this outputs like that :
-------------------------------------------
This is my list :
-list item 1
-list item 2
-list item 3

This was a great list.
-------------------------------------------

Would it be simple with regular expression to transform the list formed
of hyphens("-") to an HTML unordered list? I mean that the preceding
example would rather output as :
-------------------------------------------
This is my list :
<ul><li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li></ul>

This was a great list.
-------------------------------------------

I have some experience with regular expression but have not a clue on
how to do this...I also see some problems as if the string starts with
an hyphen, as it would also need to transform correctly, event if it
doesn't have the /n/r before the hyphen("-").
e.g. "-list item 1/n/r- list item 2" should output as :
-------------------------------------------
<ul><li>list item 1</li>
<li>list item 2</li><ul>
-------------------------------------------

And what about if there are two lists separated by some carriage
returns?...As you can see, I really don't know where to start with this
problem. :/

Thanks in advance,

ibiza

Feb 9 '06 #2
well, if I give this possibility to the users, I'd appreciate they
respect some format :)
e.g. always a carriage return then a "-". As soon as this is
encountered, this means a list to the application. If he decides to add
spaces after the "-", I guess they should be rendered maybe? And if he
decides to input two carriage returns in a row, this would mean the end
of the list and a new paragraph.

As for going line per line, the problem for me is the beginning and the
end of the list. I mean, how can I find where it does begin and
end?...could you give me some help with this?

thanks a lot for your reply!

Feb 9 '06 #3
ibiza,

If it's formatting user data entered into a text box. Check out freetextbox:
http://www.freetextbox.com

It's a WYSIWIG editor that would let your users create the list themselves
without having to know html markup. You can enable and disable any buttons
in the editor you'd like.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"ibiza" <la******@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
well, if I give this possibility to the users, I'd appreciate they
respect some format :)
e.g. always a carriage return then a "-". As soon as this is
encountered, this means a list to the application. If he decides to add
spaces after the "-", I guess they should be rendered maybe? And if he
decides to input two carriage returns in a row, this would mean the end
of the list and a new paragraph.

As for going line per line, the problem for me is the beginning and the
end of the list. I mean, how can I find where it does begin and
end?...could you give me some help with this?

thanks a lot for your reply!

Feb 9 '06 #4
thanks for the tip :)

but unfortunately, there is a licensing cost (it's for my work so I
guess they ought to buy it if I'd use it) and it's too much for what I
need...regex should be well enough for my problem, but I have
difficulties with the correct one to use :\

Feb 9 '06 #5
Ibiza,

No, you don't have to pay a dime unless you need to use the "Pro" features
or want the source code.

A quote from the licensing section of the creator's site:

Free License (free!)
You may download FreeTextBox 3.0 and include it in all your projects
including those you host and those you redistrubute. Pro features of
FreeTextBox 3.0 will be disabled.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"ibiza" <la******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
thanks for the tip :)

but unfortunately, there is a licensing cost (it's for my work so I
guess they ought to buy it if I'd use it) and it's too much for what I
need...regex should be well enough for my problem, but I have
difficulties with the correct one to use :\

Feb 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Peter Collinson | last post: by
3 posts views Thread by David Ross | last post: by
33 posts views Thread by Jim Cobban | last post: by
69 posts views Thread by markarichman | last post: by
1 post views Thread by simplico | last post: by
1 post views Thread by shapper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.