Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Fixing mismatched BBCode
« Reply #60, on December 10th, 2011, 11:56 PM »
Quote
I'm trying to figure out a 'simple' way to prevent nesting 'li' tags inside others...
You're not entirely supposed to. An li can contain a sub list, provided that the sublist is contained inside a list tag (as HTML itself allows)

That's the beauty of the nesting logic as it stands - if the li > li isn't inside a list (i.e. it's not li > list > li), the inner li should not be parsed by the bbc parser. That's why preparsecode munges it first, so that you always get li being contained inside a list and not anything else.

You don't need to explicitly disallow li as a child, as IIRC disallowing as a child may even disallow it entirely in the nested chain which isn't necessarily desirable (because IIRC it would disallow the otherwise valid permutation of li > list > li)
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #61, on December 11th, 2011, 08:42 PM »
I would assume that even if li > list > li is valid, it would have to be coded this way: li authorizes list and only that -- and list authorizes li and only that... That way, problem fixed. (i.e. I could rely on this setting to fix tag nesting.)

Anyway...

The current code is nearly TWO HUNDRED freaking lines long[1]. As opposed to the original dozen lines that did their job perfectly, i.e. point out any mismatched tags...
I'm not even sure it's worth committing the code. I mean, it (finally) works on my complex string, but OTOH, it's become such a beast that I'm sure we'll definitely find situations where it doesn't work very well... :-/
 1. It was about 150 lines long when I suddenly decided Wedge should be nice enough to prevent using block tags inside non-block tags. Heck... Even then, if you have something strange like an opening "s", then an opening "b", then a closing "s", it will add the closing "b" before the opening block tag of course, but then again AFTER the closing "s". Don't ask too much of me...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Fixing mismatched BBCode
« Reply #62, on December 11th, 2011, 09:12 PM »
No, li doesn't have to authorise that. The only rule it really needs is that li must be inside a list. Then the trick is making sure where list is, which IIRC is anywhere that a block context allows it to be.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #63, on December 11th, 2011, 10:13 PM »
Quote from Arantor on December 11th, 2011, 09:12 PM
No, li doesn't have to authorise that. The only rule it really needs is that li must be inside a list. Then the trick is making sure where list is, which IIRC is anywhere that a block context allows it to be.
The preparsecode stuff to check for this is so fucked up, once again...

Okay, I'm... I'm... I think I'm finished with fixNestings. :sob:

It's really, really horribly complex. 200 lines of code after cleanup. It seems to work but it's so... fragile. I don't know if I should commit.

So I just need to know -- is anyone of you with read access, willing to commit some of their time to look through my new code, and try to ensure it won't break anything...?

Oh, and I just discovered that using specific footnote contents, you can break your page layout. Yay.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Fixing mismatched BBCode
« Reply #64, on December 11th, 2011, 10:17 PM »
Quote
The preparsecode stuff to check for this is so fucked up, once again...
preparsecode only checks that li is contained inside a list and that list contains li tags, or it should be. Anything else (like the parent/children stuff) is done at parse time.

As far as testing goes, I think it's the sort of thing that is simply going to require hammering until we can say that it doesn't break. We can construct unit tests for it, but they're only going to be generic cases, unfortunately.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #65, on December 11th, 2011, 11:45 PM »
Okay, done...

I've made so many tests using my test code, it should really be okay at this point... But you never know.
Also, I need to fix that bug with nb parsing... Grmpf. It's like it never ends... And my code is pretty useless -- I mean, the auto-fixer doesn't really have a point because parse_bbc already accounts for most errors...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Fixing mismatched BBCode
« Reply #66, on December 11th, 2011, 11:48 PM »
Yes, but if the parser can safely avoid accounting for those things, it can be made faster...

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #67, on December 12th, 2011, 12:02 AM »
I'll leave it up to you to look into all of this... I feel I have done my share of the work on this for now! :P

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

groundup

  • Posts: 25
Re: Fixing mismatched BBCode
« Reply #69, on December 27th, 2011, 04:21 AM »
Quote from Nao on December 8th, 2011, 12:14 AM
Okay, I'll look into doing that tomorrow...

Still, complex errors won't be magically fixed, I'm afraid... Unless, unless I do a stricter check.
So while typing this post, it came to me that I could use a stack of tags and stack/unstack data and... Well, have a look at this code:

Code: [Select]
[/quote][quote author=Nao link=msg=1 date=1309111289]Lorem ipsum?[/quote]What is that?
I don't speak rubbish!
[nb]I'm wondering if Rory does, though? He had time to learn...[ /code]
[ code][ nb][ /code][ /nb]

And... Here's the error message I'm getting following my latest rewrite. Which is actually SHORTER than the last one ;) It's not perfect but I'm working on it eheh.

Pretty cool uh?

PS: and yes, it works with tag nesting too, since it's a stack... i.e. if I have properly nested 'b' tags inside the quote, everything's fine.

PPS: the main issue with fixing tags in the middle of a message is that I would then have to find the exact position of the tag... I guess it's doable, though, but I'll have to go through a series of strpos etc or something to fill in the list first, so it'll definitely make the code bigger.
Looks very exciting. I would love to see a link on there to fix them automatically by "guessing" like we do now or at least give the user a hint.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #70, on December 27th, 2011, 09:37 AM »
You mean you'd like to see some pseudo code on how I did it? :p

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Re: Fixing mismatched BBCode
« Reply #71, on December 27th, 2011, 09:53 AM »
What I think he's trying to say is to offer the user a link to try to fix the codes or simply tell the user of mismatched tags like you already have in the post error box
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Fixing mismatched BBCode
« Reply #72, on December 27th, 2011, 10:29 AM »
The problem with auto fixing is that you can actually make things so much worse.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Fixing mismatched BBCode
« Reply #73, on December 27th, 2011, 10:43 AM »
I think our current implementation works best.
But I'd like to ensure the error message path is used for quick edit as well. Firefox does it already iirc. At least on my custom noisen code. I need to remember working on that.