Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Wakaba Spoiler tags

Name: Anonymous 2011-11-15 11:59

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

Name: Anonymous 2011-11-15 15:08

>>1
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:
[code]
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>";
        }
[code]
What's my next step?

Name: Anonymous 2011-11-15 21:26

new to perl
Now you have three problems.

Name: Anonymous 2011-11-15 21:38

>>3
;_;

Name: Anonymous 2011-11-15 21:58

Perl considered harmful.
Use Ruby1.9 instead.

Name: Anonymous 2011-11-15 22:25

>>5
No.

Name: Anonymous 2011-11-15 22:28

Perl considered harmful.
Use Anythingbut Perl instead.

Name: Anonymous 2011-11-15 22:29

>>7
That's nice and all, but I'd really like to focus on learning.

Name: Anonymous 2011-11-15 22:32

Learning considered harmful.
Use PHPand MySQL instead.

Name: Anonymous 2011-11-15 22:43

>>9
Oh you.

Name: Anonymous 2011-11-15 23:35

If it ain't Lisp, it's crap.

Name: Anonymous 2011-11-15 23:36

Lisp is shit.

Name: Anonymous 2011-11-15 23:47

>>11
>>12
Sadly, my source is Perl. I can't change that.

Name: Anonymous 2011-11-16 0:08

1) sudo cpan ptkdb (it might take a while to download dependencies)
2) run your'e program with perl -d:ptkdb myperlscript.pl
3) enjoy (or at least try)

Name: Anonymous 2011-11-16 0:26

>>14
How would this help?

Name: Anonymous 2011-11-16 0:42

>>15
You can debug the program and understand how it works using a GUI application (ptkdb)

Name: Anonymous 2011-11-16 14:37

Okay, so I moved it until after WakabaMark finishes parsing the text, and did my best to work around the strange tags it introduced. Here's my "final" solution:


if($res=~/.*\[spoiler\].*/){
    $res=~s/\[spoiler\]*/\<span class\=\'spoiler\'\>/g;
    $res=~s/\[\/spoiler\]*/\<\/span\>/g;
    $res=~s/\<p\>/ /g;
    $res=~s/\<\/p\>/\<br \/\>\<br \/\>/g;
    $res=~s/\<br \/>/ /;
    $res=~s/\<\/span\>\<br \/\>\<br \/\>/\<\/span\>/g;
}

Name: Anonymous 2011-11-16 14:53

Regex markup parsing considered harmful and slow as fuck.

Name: Anonymous 2011-11-16 14:58

>>18
Is there any other way to go about doing something like this?

Name: Anonymous 2011-11-16 15:05

>>19
I use a C extension for markdown parsing, shit's fast yo!

for Ruby

Name: Anonymous 2011-11-16 15:16

>>20
Is there any real reason for me to do this?

Name: Anonymous 2011-11-16 15:53

>>21
Besides speed? Nope.

You are fucked though if absolutely need to produce valid html, without overlapping/unclosed tags. Or if you want to do some complex stuff like "no markup inside code tags", etc.

Name: Anonymous 2011-11-16 15:58

>>21
lol, no

Name: Mr. Bradeli !tRiPfAGSxc 2012-02-02 23:35

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.

Name: Anonymous 2012-02-03 13:11

ruby owns

Don't change these.
Name: Email:
Entire Thread Thread List