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

I

ibiza

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
 
P

Peter Rilling

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.
 
I

ibiza

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!
 
S

S. Justin Gengo [MCP]

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
 
I

ibiza

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 :\
 
S

S. Justin Gengo [MCP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top