summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremie Bresson2012-12-13 15:00:13 (EST)
committerGerrit Code Review @ Eclipse.org2012-12-17 13:24:03 (EST)
commit09dc29695fbc50d2148695f851afb7468871959c (patch)
tree90d35d45ae2236d58cac543bb8f16d34e4af471a
parent56383c76b067722e9ed271c8627dd0d03efb8541 (diff)
downloadorg.eclipse.mylyn.docs-09dc29695fbc50d2148695f851afb7468871959c.zip
org.eclipse.mylyn.docs-09dc29695fbc50d2148695f851afb7468871959c.tar.gz
org.eclipse.mylyn.docs-09dc29695fbc50d2148695f851afb7468871959c.tar.bz2
304495: [MediaWiki] Support for nested tables.refs/changes/25/8525/5
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=304495 Change-Id: Iabf85fd32a2b4bb89999fe5d38e117410e7cb858
-rw-r--r--org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java6
-rw-r--r--org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java102
2 files changed, 104 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java
index 7f1105d..ff1f28c 100644
--- a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java
+++ b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java
@@ -7,7 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
- * Jeremie Bresson - Bug 381912
+ * Jeremie Bresson - Bug 381912, 304495
*******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.mediawiki.core.block;
@@ -301,12 +301,12 @@ public class TableBlock extends Block {
@Override
public boolean beginNesting() {
- return openCell;
+ return !isClosed();
}
@Override
public int findCloseOffset(String line, int lineOffset) {
- if (openCell) {
+ if (!isClosed()) {
if (!checkAtNewTableRow(line, lineOffset)) {
return -1;
}
diff --git a/org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java b/org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java
index fb6f248..91c795f 100644
--- a/org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java
+++ b/org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java
@@ -7,7 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
- * Jeremie Bresson - Bug 381506, 381912, 391850
+ * Jeremie Bresson - Bug 381506, 381912, 391850, 304495
*******************************************************************************/
package org.eclipse.mylyn.wikitext.mediawiki.core;
@@ -841,6 +841,106 @@ public class MediaWikiLanguageTest extends TestCase {
assertContainsPattern(html, pattern);
}
+ public void testTableNested() {
+ //BUG 304495:
+ StringBuilder sb = new StringBuilder();
+ sb.append("{|\n");
+ sb.append("| f ||\n");
+ sb.append("{| border=\"1\"\n");
+ sb.append("| a\n");
+ sb.append("| b\n");
+ sb.append("|}\n");
+ sb.append("| ,\n");
+ sb.append("|\n");
+ sb.append("{| border=\"1\"\n");
+ sb.append("| c\n");
+ sb.append("| d\n");
+ sb.append("|}\n");
+ sb.append("|}\n");
+
+ String html = parser.parseToHtml(sb.toString());
+ TestUtil.println("HTML: \n" + html);
+ Pattern pattern = Pattern.compile("<table>\\s*<tr>\\s*<td>\\s*f\\s*<table border=\"1\">\\s*<tr>\\s*<td>\\s*a\\s*</td>\\s*<td>\\s*b\\s*</td>\\s*</tr>\\s*</table>\\s*</td>\\s*<td>\\s*,\\s*</td>\\s*<td>\\s*<table border=\"1\">\\s*<tr>\\s*<td>\\s*c\\s*</td>\\s*<td>\\s*d\\s*</td>\\s*</tr>\\s*</table>\\s*</td>\\s*</tr>\\s*</table>");
+ assertContainsPattern(html, pattern);
+ }
+
+ public void testTableMalformed() {
+ //BUG 304495:
+ StringBuilder sb = new StringBuilder();
+ sb.append("{| \n");
+ sb.append("| first table first cell\n");
+ sb.append("{| \n");
+ sb.append("| second table first cell\n");
+ sb.append("|}\n");
+ sb.append("| first table first cell\n");
+
+ String html = parser.parseToHtml(sb.toString());
+ TestUtil.println("HTML: \n" + html);
+
+ String expected = "<table><tr><td>first table first cell<table><tr><td>second table first cell</td></tr></table></td><td>first table first cell</td></tr></table>";
+ assertTrue(html.contains(expected));
+ }
+
+ public void testTableNestedMultiple() {
+ //BUG 304495:
+ StringBuilder sb;
+ sb = new StringBuilder();
+ sb.append("{| style=\"background-color:red;\"\n");
+ sb.append("! AAA !! AAAAAAAA !! AA\n");
+ sb.append("|-\n");
+ sb.append("| a\n");
+ sb.append("| aaaaa\n");
+ sb.append("| aaa\n");
+ sb.append("{| style=\"background-color:green;\"\n");
+ sb.append("! B \n");
+ sb.append("| bbbb\n");
+ sb.append("|-\n");
+ sb.append("! BBB\n");
+ sb.append("| bb\n");
+ sb.append("|-\n");
+ sb.append("! BBBBB\n");
+ sb.append("| bb\n");
+ sb.append("|}\n");
+ sb.append("|-\n");
+ sb.append("| aaaa\n");
+ sb.append("{| style=\"background-color:yellow;\"\n");
+ sb.append("! BBBBB !! BBB\n");
+ sb.append("|-\n");
+ sb.append("| bbbbb\n");
+ sb.append("| bbb\n");
+ sb.append("|-\n");
+ sb.append("| bb\n");
+ sb.append("{| style=\"background-color:blue;\"\n");
+ sb.append("! CCC !! CCCCC !! CCCCC\n");
+ sb.append("|-\n");
+ sb.append("| cc\n");
+ sb.append("| ccccc\n");
+ sb.append("| ccc\n");
+ sb.append("|-\n");
+ sb.append("| c\n");
+ sb.append("| cccc\n");
+ sb.append("| ccc\n");
+ sb.append("|}\n");
+ sb.append("| bbbbb\n");
+ sb.append("|-\n");
+ sb.append("| bbbb\n");
+ sb.append("| bb\n");
+ sb.append("|}\n");
+ sb.append("| aaaaaaa\n");
+ sb.append("| aa\n");
+ sb.append("|-\n");
+ sb.append("| aaa\n");
+ sb.append("| aaaaaaaa\n");
+ sb.append("| aaaa\n");
+ sb.append("|}\n");
+
+ String html = parser.parseToHtml(sb.toString());
+ TestUtil.println("HTML: \n" + html);
+
+ String expected = "<table style=\"background-color:red;\"><tr><th>AAA</th><th>AAAAAAAA</th><th>AA</th></tr><tr><td>a</td><td>aaaaa</td><td>aaa<table style=\"background-color:green;\"><tr><th>B </th><td>bbbb</td></tr><tr><th>BBB</th><td>bb</td></tr><tr><th>BBBBB</th><td>bb</td></tr></table></td></tr><tr><td>aaaa<table style=\"background-color:yellow;\"><tr><th>BBBBB</th><th>BBB</th></tr><tr><td>bbbbb</td><td>bbb</td></tr><tr><td>bb<table style=\"background-color:blue;\"><tr><th>CCC</th><th>CCCCC</th><th>CCCCC</th></tr><tr><td>cc</td><td>ccccc</td><td>ccc</td></tr><tr><td>c</td><td>cccc</td><td>ccc</td></tr></table></td><td>bbbbb</td></tr><tr><td>bbbb</td><td>bb</td></tr></table></td><td>aaaaaaa</td><td>aa</td></tr><tr><td>aaa</td><td>aaaaaaaa</td><td>aaaa</td></tr></table>";
+ assertTrue(html.contains(expected));
+ }
+
public void testEntityReference() {
String tests = "&Agrave; &Aacute; &Acirc; &Atilde; &Auml; &Aring; &AElig; &Ccedil; &Egrave; &Eacute; &Ecirc; &Euml; &Igrave; &Iacute; &Icirc; &Iuml; &Ntilde; &Ograve; &Oacute; &Ocirc; &Otilde; &Ouml; &Oslash; &Ugrave; &Uacute; &Ucirc; &Uuml; &szlig; &agrave; &aacute; &acirc; &atilde; &auml; &aring; &aelig; &ccedil; &egrave; &eacute; &ecirc; &euml; &igrave; &iacute; &icirc; &iuml; &ntilde; &ograve; &oacute; &ocirc; &oelig; &otilde; &ouml; &oslash; &ugrave; &uacute; &ucirc; &uuml; &yuml; &iquest; &iexcl; &sect; &para; &dagger; &Dagger; &bull; &ndash; &mdash; &lsaquo; &rsaquo; &laquo; &raquo; &lsquo; &rsquo; &ldquo; &rdquo; &trade; &copy; &reg; &cent; &euro; &yen; &pound; &curren; &#8304; &sup1; &sup2; &sup3; &#8308; &int; &sum; &prod; &radic; &minus; &plusmn; &infin; &asymp; &prop; &equiv; &ne; &le; &ge; &times; &middot; &divide; &part; &prime; &Prime; &nabla; &permil; &deg; &there4; &alefsym; &oslash; &isin; &notin; &cap; &cup; &sub; &sup; &sube; &supe; &not; &and; &or; &exist; &forall; &rArr; &lArr; &dArr; &uArr; &hArr; &rarr; &darr; &uarr; &larr; &harr; &mdash; &ndash;";
final String[] allEntities = tests.split("\\s+");