Hello,
I want to write a _very_ simple text parser that would replace a
string like:
"This is text with /italics/, *bold* and _underline_."
and generate automatically something like this:
"This is text with <i>italics</i>, <b>bold</b> and <span
class="underlin e">underline </span>."
I've found a lot of code snippets explaining how to do BBCode, but
BBCode has different opening and closing pseudo-tags. In my example,
the opening and closing tags are the same (either /, * or _). So I
need something slightly more intelligent that would count the number
of /, * or _ tags, see if that number is even or odd and decide
accordingly if it must replace the char with an opening or closing
tag. (I hope my wording makes sense. It's very clear in my head :-D)
How would you implement that? I reckon it can't be hard, but I just
can't figure how to do it right now!
Thanks for any insight!
I want to write a _very_ simple text parser that would replace a
string like:
"This is text with /italics/, *bold* and _underline_."
and generate automatically something like this:
"This is text with <i>italics</i>, <b>bold</b> and <span
class="underlin e">underline </span>."
I've found a lot of code snippets explaining how to do BBCode, but
BBCode has different opening and closing pseudo-tags. In my example,
the opening and closing tags are the same (either /, * or _). So I
need something slightly more intelligent that would count the number
of /, * or _ tags, see if that number is even or odd and decide
accordingly if it must replace the char with an opening or closing
tag. (I hope my wording makes sense. It's very clear in my head :-D)
How would you implement that? I reckon it can't be hard, but I just
can't figure how to do it right now!
Thanks for any insight!
Comment