Spoilers in Wakaba (16)

1 Name: #!/usr/bin/anonymous : 2011-11-15 16:37 ID:vXrur0sV This thread was merged from the former /code/ board. You can view the archive here.

So I'm trying to add spoiler support in Wakaba, and I'm having a lot of trouble that I think is stemming from regex. I'm new to perl, so this is a bit hard for me. I'm adding the following to sub do_wakabamark($;$$) to accomplish this:

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

2 Name: #!/usr/bin/anonymous : 2011-11-15 16:37 ID:vXrur0sV

...oh, and anyone know what's wrong?

3 Name: #!/usr/bin/anonymous : 2011-11-15 20:10 ID:vXrur0sV

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\]$/){
$lines[0]="";
}
}
$res.="<span class='spoiler'>".(join "<br />",@spoiler)."</span>";
}

Anyone know what to do next?

4 Name: #!/usr/bin/anonymous : 2011-11-22 02:57 ID:fn49OQZ2

Ohhhh. Hrm.
How would someone go about doing this in Kareha? I've never worked with Perl before but I'd love to have this on one of my Kareha boards.

5 Name: #!/usr/bin/anonymous : 2011-12-01 23:55 ID:HUAkezOC

>>4

it'd be a simple case of a search/replace for [spoiler] tags and an sgml tag balancer

captcha: shit

6 Name: #!/usr/bin/anonymous : 2012-01-07 10:11 ID:lZtWuGxo

below do_wakabamark is do_spans edit that function

7 Name: Mr. Manager!!vBeIv0NZ : 2012-02-03 04:31 ID:rbxt0snr

>>135-141
So I FINALLY got spoilers working properly. I don't remember who told me, but the only way to get this to work without completely rewriting wakabamark was to hold off on the spoiler function until AFTER all wakabamark related things were completed. Anyways, I went ahead and put my code right after:

    # restore >>1 references hidden in code blocks
$comment=~s/&gtgt;/&gt; &gt;/g;

...which was on line 846 in my version of wakaba.pl. Next is the actual spoiler code:

    # new spoiler code (can't put it in 'do_wakabamark' because of 'do_spans' messing with the order of tags
if($comment=~/.*\[spoiler\].*/){
$comment=~s/\[spoiler\]*/\<span class\=\'spoiler\'\>/g;
$comment=~s/\[\/spoiler\]*/\<\/span\>/g;
$comment=~s/\<span class\=\'spoiler\'\>\<br \/\>/\<span class\=\'spoiler\'\>/g;
$comment=~s/\<\/span\>\<br \/\>/\<\/span\>/g;
}

Hopefully this helped -someone- out.

8 Name: #!/usr/bin/anonymous : 2012-02-08 02:56 ID:DZ2UrGTF

>>7
I use Kareha so it is probably not useful to me, but I am thankful that you came back to share the code with other Wakaba users.

9 Name: xenu : 2012-02-19 15:25 ID:/rDAX+RF

Don't fucking parse BBCode with regex!

10 Name: #!/usr/bin/anonymous : 2012-02-28 05:08 ID:7o0JyRUH

I actually wasn't aware that this was doing this until I read this post. After changing some code around (thanks to your example) I have fixed the problem with my bbcodes that I didn't even know was a problem until now.

Thank you!

11 Name: #!/usr/bin/anonymous : 2012-06-01 19:25 ID:Heaven

>>9
It's just one BBCode tag and it creates SPAN tags. You should take your meme-spewing elsewhere.

12 Name: #!/usr/bin/anonymous : 2012-07-25 03:56 ID:j5RC6tZ3

Bump, hopefully someone has gotten spoiler tags in Kareha.

13 Name: #!/usr/bin/anonymous : 2012-07-25 04:05 ID:j5RC6tZ3

I found a 2006 post:
# do <span class="spoiler">
$line=~s{ (?<![0-9a-zA-Z\*_\x80-\x9f\xe0-\xfc]) (~~) (?![<>\s\*_]) ([^<>]+?) (?<![<>\s\*_\x80-\x9f\xe0-\xfc]) \1 (?![0-9a-zA-Z\*_]) }{<span class="spoiler">$2</span>}gx;

Sorry.

14 Name: #!/usr/bin/anonymous : 2012-10-08 20:34 ID:Heaven

Please, use %%spoiler%% instead of BB-like tags.
Percent symbols feel better.

15 Name: #!/usr/bin/anonymous : 2012-11-24 14:34 ID:Heaven

>>14
But then how would you do nested spoilers? They are fun.

16 Name: #!/usr/bin/anonymous : 2013-03-17 20:49 ID:Heaven

Now you have two problems.

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