tithonium: (Default)
[personal profile] tithonium
Insane? why yes, yes I am.

$text =~ s!^\s*\*\s*(.+)$!<li>$1</li>!gm;
$text =~ s!<li>!<ul>\n<li>!s;
$text =~ s!(.*</li>)!$1\n</ul>!s;

$text =~ s!(?<=\s)\*(\S[^\*]+?\S)\*(?=\s)!<b>$1</b>!gs;
$text =~ s!(?<=\s)/(\S[^\*]+?\S)/(?=\s)!<i>$1</i>!gs;
$text =~ s^(?<!>)(\r\n|\n|\r)^<br />$1^gs;


All so that things like

la la la /but/ la la *then* la la
* foo
*foo


can become


la la la but la la then la la
  • foo
  • foo



And I refuse to implement Markdown or anything like that for this. And because XML::Simple is too dumb to let me say "never parse the contents of tags named <text>".

edit: also, one of these days I might actually remember how to write zero-width negative look-behinds, so I don't have to keep looking it up. But not yet.
(deleted comment)

Date: 2008-06-26 09:22 pm (UTC)
From: [identity profile] tithonium.livejournal.com
What a horrifying thought.

Date: 2008-06-27 05:09 am (UTC)
From: [identity profile] stolen-tea.livejournal.com
As of HTML 4.01, the end tag "may be omitted". In XHTML, it's mandatory, of course. :/

Date: 2008-06-27 11:42 am (UTC)
From: [identity profile] tedder42.livejournal.com
Use word breaks, like \b, instead of \s and such. Should clean your regexes up significantly.

Date: 2008-06-27 04:10 pm (UTC)
From: [identity profile] tithonium.livejournal.com
Can't. * and / are non-word characters.

Date: 2008-06-27 06:11 pm (UTC)
From: [identity profile] tedder42.livejournal.com
Can't you still do this?

m#\*\b(.*?)\b\*# ..

Profile

tithonium: (Default)
tithonium

February 2019

S M T W T F S
     12
3456789
10111213141516
17181920212223
2425262728  

Expand Cut Tags

No cut tags