diff options
author | Jeremie Bresson | 2013-01-11 16:52:42 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2013-01-18 18:58:26 +0000 |
commit | 971ca520c1cc4d13ec90809a8cf41b17b442db90 (patch) | |
tree | f44874b16713ee2d59c92aadbfe098aeabacf6ea | |
parent | 332283a3febb1428d7ea4cba02d29c6fba3ecd8c (diff) | |
download | org.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
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 = "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ñ Ò Ó Ô Õ Ö Ø Ù Ú Û Ü ß à á â ã ä å æ ç è é ê ë ì í î ï ñ ò ó ô œ õ ö ø ù ú û ü ÿ ¿ ¡ § ¶ † ‡ • – — ‹ › « » ‘ ’ “ ” ™ © ® ¢ € ¥ £ ¤ ⁰ ¹ ² ³ ⁴ ∫ ∑ ∏ √ − ± ∞ ≈ ∝ ≡ ≠ ≤ ≥ × · ÷ ∂ ′ ″ ∇ ‰ ° ∴ ℵ ø ∈ ∉ ∩ ∪ ⊂ ⊃ ⊆ ⊇ ¬ ∧ ∨ ∃ ∀ ⇒ ⇐ ⇓ ⇑ ⇔ → ↓ ↑ ← ↔ — –"; final String[] allEntities = tests.split("\\s+"); |