Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremie Bresson2013-01-11 16:52:42 +0000
committerGerrit Code Review @ Eclipse.org2013-01-18 18:58:26 +0000
commit971ca520c1cc4d13ec90809a8cf41b17b442db90 (patch)
treef44874b16713ee2d59c92aadbfe098aeabacf6ea
parent332283a3febb1428d7ea4cba02d29c6fba3ecd8c (diff)
downloadorg.eclipse.mylyn.docs-971ca520c1cc4d13ec90809a8cf41b17b442db90.tar.gz
org.eclipse.mylyn.docs-971ca520c1cc4d13ec90809a8cf41b17b442db90.tar.xz
org.eclipse.mylyn.docs-971ca520c1cc4d13ec90809a8cf41b17b442db90.zip
396545: [MediaWiki] blank spaces at the beginning of table lines
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=396545 Change-Id: I0cdf4ed7377b5f85b0685a9720940fa83dcfe114
-rw-r--r--org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/TableBlock.java20
-rw-r--r--org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguage.java5
-rw-r--r--org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java63
3 files changed, 72 insertions, 16 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 ff1f28c2e..52ed1d19c 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 David Green and others.
+ * Copyright (c) 2007, 2013 David Green and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,7 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
- * Jeremie Bresson - Bug 381912, 304495
+ * Jeremie Bresson - Bug 381912, 304495, 396545
*******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.mediawiki.core.block;
@@ -31,17 +31,17 @@ public class TableBlock extends Block {
private static final Pattern rowCellSplitter = Pattern.compile("\\s*(\\|\\||!!)\\s*"); //$NON-NLS-1$
- private static final Pattern startPattern = Pattern.compile("\\{\\|\\s*(.+)?"); //$NON-NLS-1$
+ private static final Pattern startPattern = Pattern.compile("\\s*\\{\\|\\s*(.+)?"); //$NON-NLS-1$
private static final Pattern optionsPattern = Pattern.compile("([a-zA-Z]+)=\"([^\"]*)\""); //$NON-NLS-1$
- private static final Pattern newRowPattern = Pattern.compile("\\|-\\s*(.+)?"); //$NON-NLS-1$
+ private static final Pattern newRowPattern = Pattern.compile("\\s*\\|-\\s*(.+)?"); //$NON-NLS-1$
- private static final Pattern cellPattern = Pattern.compile("(\\||!)\\s*(.+)?"); //$NON-NLS-1$
+ private static final Pattern cellPattern = Pattern.compile("\\s*(\\||!)\\s*(.+)?"); //$NON-NLS-1$
private static final Pattern cellSplitterPattern = Pattern.compile("\\s*(?:([^\\|\\[]+)?\\|)?\\s*(.+)?"); //$NON-NLS-1$
- private static final Pattern endPattern = Pattern.compile("\\|\\}\\s*(.+)?"); //$NON-NLS-1$
+ private static final Pattern endPattern = Pattern.compile("\\s*\\|\\}\\s*(.+)?"); //$NON-NLS-1$
private int blockLineCount;
@@ -316,11 +316,9 @@ public class TableBlock extends Block {
private boolean checkAtNewTableRow(String line, int lineOffset) {
if (lineOffset < line.length()) {
- char startChar = line.charAt(lineOffset);
- if (startChar == '|' || startChar == '!') {
- //new line, a new cell or a new header cell
- return true;
- }
+ Matcher m = cellPattern.matcher(line);
+ m.region(lineOffset, line.length());
+ return m.matches();
}
return false;
}
diff --git a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguage.java b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguage.java
index 6e64befbf..e6ed61d21 100644
--- a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguage.java
+++ b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 David Green and others.
+ * Copyright (c) 2007, 2013 David Green and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
+ * Jeremie Bresson - Bug 396545
*******************************************************************************/
package org.eclipse.mylyn.wikitext.mediawiki.core;
@@ -88,6 +89,7 @@ public class MediaWikiLanguage extends AbstractMediaWikiLanguage {
blocks.add(new HeadingBlock());
blocks.add(new ListBlock());
+ blocks.add(new TableBlock());
if (hasPreformattedBlock()) {
// preformatted blocks are lines that start with a single space, and thus are non-optimal for
@@ -96,7 +98,6 @@ public class MediaWikiLanguage extends AbstractMediaWikiLanguage {
}
blocks.add(new SourceBlock());
- blocks.add(new TableBlock());
blocks.add(new TableOfContentsBlock());
blocks.add(new EscapeBlock());
blocks.add(new CommentBlock());
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 811018718..1bb930b41 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2012 David Green and others.
+ * Copyright (c) 2007, 2013 David Green and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,7 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
- * Jeremie Bresson - Bug 381506, 381912, 391850, 304495
+ * Jeremie Bresson - Bug 381506, 381912, 391850, 304495, 396545
*******************************************************************************/
package org.eclipse.mylyn.wikitext.mediawiki.core;
@@ -871,7 +871,7 @@ public class MediaWikiLanguageTest extends TestCase {
assertContainsPattern(html, pattern);
}
- public void testTableMalformed() {
+ public void testTableNestedMalformed() {
//BUG 304495:
StringBuilder sb = new StringBuilder();
sb.append("{| \n");
@@ -948,6 +948,63 @@ public class MediaWikiLanguageTest extends TestCase {
assertTrue(html.contains(expected));
}
+ public void testTableLeadingSpaces() {
+ //BUG 396545:
+ StringBuilder sb = new StringBuilder();
+ sb.append("{| \n");
+ sb.append(" ! lorem\n");
+ sb.append(" ! ipsum\n");
+ sb.append(" |-\n");
+ sb.append(" | dolor\n");
+ sb.append(" | amtis\n");
+ sb.append(" |}\n");
+
+ String html = parser.parseToHtml(sb.toString());
+ TestUtil.println("HTML: \n" + html);
+
+ String expected = "<table><tr><th>lorem</th><th>ipsum</th></tr><tr><td>dolor</td><td>amtis</td></tr></table>";
+ assertTrue(html.contains(expected));
+ }
+
+ public void testTableLeadingSpacesInContext() {
+ //BUG 396545:
+ StringBuilder sb = new StringBuilder();
+ sb.append("aaa\n");
+ sb.append(" {| border=\"1\" \n");
+ sb.append(" ! other !! test !! table\n");
+ sb.append(" |-\n");
+ sb.append(" | with\n");
+ sb.append(" | some\n");
+ sb.append(" | cells\n");
+ sb.append("|-\n");
+ sb.append(" | and || a || line\n");
+ sb.append(" |}\n");
+ sb.append(" bbb");
+
+ String html = parser.parseToHtml(sb.toString());
+ TestUtil.println("HTML: \n" + html);
+
+ String expected = "<p>aaa</p><table border=\"1\"><tr><th>other</th><th>test</th><th>table</th></tr><tr><td>with</td><td>some</td><td>cells</td></tr><tr><td>and</td><td>a</td><td>line</td></tr></table><pre>bbb\n</pre>";
+ assertTrue(html.contains(expected));
+ }
+
+ public void testTableLeadingSpacesNestedMalformed() {
+ //BUG 396545:
+ 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 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+");

Back to the top