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!!
...oh, and anyone know what's wrong?
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?
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.
it'd be a simple case of a search/replace for [spoiler] tags and an sgml tag balancer
captcha: shit
below do_wakabamark
is do_spans
edit that function
>>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/>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.
>>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.
Don't fucking parse BBCode with regex!
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!
>>9
It's just one BBCode tag and it creates SPAN tags. You should take your meme-spewing elsewhere.
Bump, hopefully someone has gotten spoiler tags in Kareha.
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.
Please, use %%spoiler%% instead of BB-like tags.
Percent symbols feel better.
>>14
But then how would you do nested spoilers? They are fun.
Now you have two problems.