Bug 304495 - [MediaWiki] Support for nested tables
Summary: [MediaWiki] Support for nested tables
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 1.8.0   Edit
Assignee: Jeremie Bresson CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2010-03-03 06:46 EST by Dan Berindei CLA
Modified: 2012-12-17 15:12 EST (History)
2 users (show)

See Also:


Attachments
mylyn/context/zip (911 bytes, application/octet-stream)
2010-03-04 22:56 EST, David Green CLA
no flags Details
JUnit test for MarkupLanguage. (6.92 KB, application/octet-stream)
2012-11-08 17:05 EST, Jeremie Bresson CLA
no flags Details
Screenshot - Second example - Bug 304495 (12.91 KB, image/png)
2012-12-12 16:49 EST, Jeremie Bresson CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Berindei CLA 2010-03-03 06:46:21 EST
Build Identifier: 20100204-0846

MediaWiki supports nested tables (don't know about others): http://meta.wikimedia.org/wiki/Help:Table#Nested_tables

The WikiText preview tab doesn't display the nested tables correctly, it looks like closing the inner table also closes the outer table.

Reproducible: Always

Steps to Reproduce:
Create a .mediawiki file with the following contents:

{| 
| f( ||
{| border="1"
| a
| b
|}
| ,
|
{| border="1"
| c
| d
|}

Switch to the preview pane and select view source from the context menu.

Expected:

<table><tr><td>f(</td><td><table border="1"><tr><td>a</td><td>b</td></tr></table></td><td>,</td><td><table border="1"><tr><td>a</td><td>b</td></tr></table></td><td></tr></table>

Actual:

<table><tr><td>f(</td><td>a</td><td>b</td></tr></table><p>| ,
|</p><table border="1"><tr><td>c</td><td>d</td></tr></table>
Comment 1 David Green CLA 2010-03-04 22:56:39 EST
Thanks for the bug.  Feel free to make a contribution!  I've highlighted the relevant code in the attached Mylyn context.
Comment 2 David Green CLA 2010-03-04 22:56:41 EST
Created attachment 161068 [details]
mylyn/context/zip
Comment 3 Jeremie Bresson CLA 2012-10-15 16:18:03 EDT
Very interesting case.

I made modification to the table bloc in:
bug 381912: [MediaWiki] support for nested blocks in table cells.

Now the current output is:
<table><tr><td>f(<table border="1"></table></td><td>a</td><td>b</td></tr></table><p>| ,
|</p><table border="1"><tr><td>c</td><td>d</td></tr></table></body></html>

I think, this is because the first table (without border) @canResume()@ when the cell "a" is presented. So every opened child bloc need to close: so the first table with border "1" is closed, and cell "a" belong to the table without border...

I am not sure in which order @canResume()@ should be asked. I need to try some stuff and to have a look on how the list bloc works (enclosing list in list is a much more frequent use case).
Comment 4 Jeremie Bresson CLA 2012-11-06 00:42:23 EST
Here a proposal:
https://git.eclipse.org/r/8525

It was about @Block.findCloseOffset(String, int)@: if the current block has a close offset before or at the same position than the nestedParent, it should process the line. Only if the parent block has a close offset before the current block it should close the current block.
Comment 5 Jeremie Bresson CLA 2012-11-08 16:58:50 EST
Never mind what I wrote in comment #4 !

The nested protocol works well. I made a mistake with the code proposed with bug 381912.

I implemented @TableBlock.canResume(String, int)@ and @TableBlock.findCloseOffset(String, int)@ to work on _new line, a new cell or a new header cell_ (see comment in @TableBlock.checkAtNewTableRow(String, int)@). If so, the nested protocol need to start as soon as the @BlockType.TABLE@ is opened (and not like currently when a cell is opened). Otherwise (like in the current implementation) the code is not symmetric.

I uploaded a new Patch on Gerrit:
https://git.eclipse.org/r/#/c/8525/

I think this solution is the correct one.
Comment 6 Jeremie Bresson CLA 2012-11-08 17:05:43 EST
Created attachment 223370 [details]
JUnit test for MarkupLanguage.


To understand the nested protocol, I wrote this test class. I am not sure if this is relevant for the code base.

I attached it here if someone is interested.
Comment 7 Jeremie Bresson CLA 2012-12-12 16:49:47 EST
Created attachment 224649 [details]
Screenshot - Second example - Bug 304495

A screenshot of a table defined by following MediaWiki code (second example):

bc. 
{| style="background-color:red;"
! AAA !! AAAAAAAA !! AA
|-
| a
| aaaaa
| aaa
{| style="background-color:green;"
! B 
| bbbb
|-
! BBB
| bb
|-
! BBBBB
| bb
|}
|-
| aaaa
{| style="background-color:yellow;"
! BBBBB !! BBB
|-
| bbbbb
| bbb
|-
| bb
{| style="background-color:blue;"
! CCC !! CCCCC !! CCCCC
|-
| cc
| ccccc
| ccc
|-
| c
| cccc
| ccc
|}
| bbbbb
|-
| bbbb
| bb
|}
| aaaaaaa
| aa
|-
| aaa
| aaaaaaaa
| aaaa
|}
Comment 8 Jeremie Bresson CLA 2012-12-12 16:57:04 EST
As asked in Gerrit, I added a second test case @testTableNestedMultiple()@.

Uploaded patch set 3:
https://git.eclipse.org/r/#/c/8525/

You can see a screenshot of this second example in attachment 224649 [details].

I created the expected pattern with using the html code produced by MediaWiki on the same input. Here the process:

* Take the HTML code produced by MediaWiki
* Format the HTML code with Tidy.
* Trim each line (inclusive tabs)
* Add \\s* at the end of each line
* Put the result in a StringBuilder

The code produced by MediaWiki is also compatible with the expected pattern.


In my opinion this second case is sufficient for this bug (it covers the requested topics "multi-level nesting" and "tables with multiple columns")

There is an example of a malformed markup in the example proposed in comment #0 (I have adapted this example for my first JUnit test case: @testTableNested()@ ). 

In my opinion, other table issues should be addressed in separate bugs.
Comment 9 David Green CLA 2012-12-12 17:21:55 EST
(In reply to comment #8)
> There is an example of a malformed markup in the example proposed in comment #0

How about this:

bc. 
{| 
 | first table first cell
{| 
 | second table first cell
 |}
 | first table first cell
 
Notice that the outer table is not closed.  Parsing has to be robust - we really want to guard against bad behaviour (such as infinite loops) by adding tests for malformed markup.
Comment 10 Jeremie Bresson CLA 2012-12-13 15:51:17 EST
In my opinion the "Missing closing mark on the outer table" was already covered in @testTableNested()@. The closing mark is also missing in the example provided by Dan Berindei in comment #0.

In oder to by more precise, I fixed the table in @testTableNested()@ (the outer table has now a closing mark) and I added a third case @testTableNestedMalformed()@.

I had to correct your example, because for the moment the Wikitext parser do not accept " |" as valid cell opening. This is also the case on a simple table (it has nothing to do with nested table, so I suggest we fix this bug in Bug 396545).

Notice that your example is parsed without problem. " |" is interpreted as "starting a pre-bloc" because of the leading space. It could have been a valid solution if MediaWiki had not decided otherwise (the leading blank spaces are ignored before the table marks). There is no infinite loops or stuff like that, it is just that your example required the resolution of this bug and of Bug 396545.


In my opinion fixing separate parsing errors should be fixed in separate bugs (even if both deals with tables).


In reply to you comment: "better to use assertEquals() since it is much more difficult to analyze a failed pattern match than an equals mismatch":
I changed the code @assertContainsPattern(html, pattern);@ for @assertTrue(html.contains(expected));@. My motivation for the pattern was: the proposed pattern was compatible with the current HTML output of MediaWiki... Now it is not, because MediaWiki to not trim all the line as WikiText does... In my opinion, when dealing with HTML code, having white spaces and line breaks near the html tags doesn't matter. But if you prefer the solution with @html.contains(..)@ it is up to you.

Uploaded patch set 4:
https://git.eclipse.org/r/#/c/8525
Comment 11 David Green CLA 2012-12-17 15:12:22 EST
Thanks for the contribution Jeremie.  I've merged the review, so marking this as fixed.