The Wakaba and Kareha support thread, part 3 (535)

1 Name: !WAHa.06x36 : 2011-01-07 09:57 ID:eLRTX7Vk [Del]

This thread is for all your simple questions about installing and running Wakaba or Kareha, that just require quick answers. Please don't create new threads for issues like that, post them in here instead.

Before posting, check that the question has not already been answered in this thread, or in the previous two threads:

Also check the documentation:

There is also a setup guide by Anon:

Questions about "500 Internal Server Errors" go in this thread:

135 Name: Anonymous : 2011-11-15 08:34 ID:wyItaZu/ [Del]

Hey guys, I'm trying to add spoiler text support to wakaba, and I'm new to perl so this is a lot harder for me than it should be. Is there any reason why adding the following to `sub do_wakabamark($;$$)' is not working?

elsif(/^\[spoiler\]/) # spoilers{
if ($lines[0]=~/^\[spoiler\](.*)/){
while !($lines[0]=~/\[\/spoiler\]$/){
push @spoiler,$1; shift @lines;
$res.="<span class='spoiler'>".(join "<br />",@spoiler)."</span>";

Thanks in advance!!

136 Name: Anonymous : 2011-11-15 09:04 ID:Heaven [Del]

Oh and if it matters, I'm getting a regex error in this section for some reason, and I don't understand what that has to do with my changes:

# do ^H
my $regexp;
$line=~s{($regexp)}{"<del>".(substr $1,0,(length $1)/3)."</del>"}gex;

137 Post deleted by user.

138 Name: Anonymous : 2011-11-15 09:40 ID:Heaven [Del]


>elsif(/^\[spoiler\]/) # spoilers{

There's supposed to be a linebreak before the {.

139 Name: Anonymous : 2011-11-15 12:06 ID:wyItaZu/ [Del]

Made a bunch of changes and got it working for the most part, but now I can't make the spoilers work if post contains any other text before or after the tags. Here's what I have:

	elsif(/.*\[spoiler\].*/) # spoilers
my @spoiler;
if ($lines[0]=~/.*\[spoiler\](.*)/){
shift @lines;
while ($lines[0]!~/\[\/spoiler\]$/){
push @spoiler,$lines[0]; shift @lines;
shift @lines;
if ($lines[0]=~/\[\/spoiler\]$/){
$res.="<span class='spoiler'>".(join "<br />",@spoiler)."</span>";

Not sure what to do next...

140 Name: Anonymous : 2011-11-16 11:32 ID:wyItaZu/ [Del]

Okay, so I moved it until after WakabaMark finishes messing with the text, and did my best to work around the strange placement of the tags it introduced. Here's my "final" solution (until I get rid of Wakabamark completely and start from scrath):

$res=~s/\[spoiler\]*/\<span class\=\'spoiler\'\>/g;
$res=~s/\<p\>/ /g;
$res=~s/\<\/p\>/\<br \/\>\<br \/\>/g;
$res=~s/\<br \/>/ /;
$res=~s/\<\/span\>\<br \/\>\<br \/\>/\<\/span\>/g;

141 Name: !WAHa.06x36 : 2011-11-16 12:51 ID:Heaven [Del]


Protip: Don't do that. It seems like it's easy to write a simple text formatter using a bunch of chained regexes.

It is not.

Every single regex is going to interact with every other regex, in subtle ways you will not predict, and you will open yourself up to mis-formatting and HTML injections. Hunting these down will be painful, and once you are done (which you never really are) you will have an utterly unmaintainable monster.

If you want write a text formatter, you will need to use some kind or other of actual parser.

Name: Link:
Leave these fields empty (spam trap):
More options...