460811: Change unsupported blocks to use line breaks instead of newlines
* Replaced newlines (\r) with line breaks (<br/>) in
UnsupportedBlockStrategy
* Added NoOpBlockStrategy that outputs no line breaks, and bound its use
to specific block elements
* Updated tests
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=460811
Change-Id: I45d67752806f02ba9138c00f6b730a33c17f53d7
Signed-off-by: Michael Nelson <michael.nelson@tasktop.com>
diff --git a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategies.java b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategies.java
index 1faeff3..bcc8ed3 100644
--- a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategies.java
+++ b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategies.java
@@ -86,8 +86,16 @@
}
@Override
- BlockStrategy getUnsupportedElementStrategy() {
- return UnsupportedBlockStrategy.instance;
+ BlockStrategy getUnsupportedElementStrategy(BlockType elementType) {
+ switch (elementType) {
+ case BULLETED_LIST:
+ case DEFINITION_LIST:
+ case NUMERIC_LIST:
+ case TABLE:
+ return NoOpBlockStrategy.instance;
+ default:
+ return UnsupportedBlockStrategy.instance;
+ }
}
@Override
diff --git a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/ElementStrategies.java b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/ElementStrategies.java
index d2a7533..fa46a02 100644
--- a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/ElementStrategies.java
+++ b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/ElementStrategies.java
@@ -80,7 +80,7 @@
abstract ElementStrategy getSupportedStrategy(ElementType elementType);
- abstract ElementStrategy getUnsupportedElementStrategy();
+ abstract ElementStrategy getUnsupportedElementStrategy(ElementType elementType);
abstract ElementStrategy createSubstitutionElementStrategy(ElementType alternative);
@@ -99,7 +99,7 @@
}
}
if (elementStrategy == null) {
- elementStrategy = getUnsupportedElementStrategy();
+ elementStrategy = getUnsupportedElementStrategy(elementType);
}
return elementStrategy;
}
diff --git a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/NoOpBlockStrategy.java b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/NoOpBlockStrategy.java
new file mode 100644
index 0000000..49ae0d7
--- /dev/null
+++ b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/NoOpBlockStrategy.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Green - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.wikitext.html.core;
+
+import org.eclipse.mylyn.wikitext.core.parser.Attributes;
+import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder;
+import org.eclipse.mylyn.wikitext.core.parser.DocumentBuilder.BlockType;
+
+public class NoOpBlockStrategy implements BlockStrategy {
+
+ static final NoOpBlockStrategy instance = new NoOpBlockStrategy();
+
+ @Override
+ public void beginBlock(DocumentBuilder builder, BlockType type, Attributes attributes) {
+ }
+
+ @Override
+ public void endBlock(DocumentBuilder builder) {
+ }
+
+}
diff --git a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/SpanStrategies.java b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/SpanStrategies.java
index 679ab3d..8e61ca1 100644
--- a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/SpanStrategies.java
+++ b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/SpanStrategies.java
@@ -73,7 +73,7 @@
}
@Override
- SpanStrategy getUnsupportedElementStrategy() {
+ SpanStrategy getUnsupportedElementStrategy(SpanType elementType) {
return UnsupportedSpanStrategy.instance;
}
diff --git a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/UnsupportedBlockStrategy.java b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/UnsupportedBlockStrategy.java
index 3144b57..e7cc292 100644
--- a/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/UnsupportedBlockStrategy.java
+++ b/org.eclipse.mylyn.wikitext.html.core/src/org/eclipse/mylyn/internal/wikitext/html/core/UnsupportedBlockStrategy.java
@@ -21,12 +21,12 @@
@Override
public void beginBlock(DocumentBuilder builder, BlockType type, Attributes attributes) {
- builder.characters("\n"); //$NON-NLS-1$
}
@Override
public void endBlock(DocumentBuilder builder) {
- builder.characters("\n"); //$NON-NLS-1$
+ builder.lineBreak();
+ builder.lineBreak();
}
}
diff --git a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategiesTest.java b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategiesTest.java
index 3ce4133..c5fe615 100644
--- a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategiesTest.java
+++ b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/BlockStrategiesTest.java
@@ -100,12 +100,20 @@
@Test
public void fallBackToUnsupported() {
BlockStrategies strategies = new BlockStrategies(Sets.newHashSet(BlockType.PARAGRAPH));
- List<BlockType> unsupportedBlockTypes = ImmutableList.of(BlockType.TABLE, BlockType.TABLE_ROW,
- BlockType.BULLETED_LIST, BlockType.NUMERIC_LIST, BlockType.DEFINITION_LIST);
+ BlockStrategy strategy = strategies.getStrategy(BlockType.TABLE_ROW, new Attributes());
+ assertNotNull(strategy);
+ assertTrue(UnsupportedBlockStrategy.class.equals(strategy.getClass()));
+ }
+
+ @Test
+ public void fallBackToNoOp() {
+ BlockStrategies strategies = new BlockStrategies(Sets.newHashSet(BlockType.PARAGRAPH));
+ List<BlockType> unsupportedBlockTypes = ImmutableList.of(BlockType.TABLE, BlockType.BULLETED_LIST,
+ BlockType.NUMERIC_LIST, BlockType.DEFINITION_LIST);
for (BlockType blockType : unsupportedBlockTypes) {
BlockStrategy strategy = strategies.getStrategy(blockType, new Attributes());
assertNotNull(strategy);
- assertEquals(UnsupportedBlockStrategy.class, strategy.getClass());
+ assertTrue(NoOpBlockStrategy.class.equals(strategy.getClass()));
}
}
diff --git a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderTest.java b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderTest.java
index aa85931..f354282 100644
--- a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderTest.java
+++ b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderTest.java
@@ -51,6 +51,7 @@
builder.setSupportedBlockTypes(Sets.newHashSet(BlockType.PARAGRAPH));
builder.setSupportedSpanTypes(Sets.newHashSet(SpanType.BOLD), Collections.<SpanHtmlElementStrategy> emptyList());
builder.setSupportedHeadingLevel(3);
+ builder.beginDocument();
}
@Test
@@ -72,7 +73,8 @@
writer = new StringWriter();
builder = new HtmlSubsetDocumentBuilder(writer, false);
builder.characters("test");
- assertContent("test");
+ builder.flush();
+ assertEquals("test", writer.toString());
}
@Test
@@ -223,7 +225,7 @@
@Test
public void blockParagraphUnsupportedWithoutFallback() {
- assertUnsupportedBlock("\ntest\n", BlockType.PARAGRAPH, BlockType.CODE);
+ assertUnsupportedBlock("test<br/><br/>", BlockType.PARAGRAPH, BlockType.CODE);
}
@Test
@@ -238,7 +240,7 @@
@Test
public void blockCodeUnsupportedWithoutFallback() {
- assertUnsupportedBlock("\ntest\n", BlockType.CODE, BlockType.LIST_ITEM);
+ assertUnsupportedBlock("test<br/><br/>", BlockType.CODE, BlockType.LIST_ITEM);
}
@Test
@@ -258,7 +260,7 @@
@Test
public void blockQuoteUnsupportedWithoutFallback() {
- assertUnsupportedBlock("\ntest\n", BlockType.QUOTE, BlockType.CODE);
+ assertUnsupportedBlock("test<br/><br/>", BlockType.QUOTE, BlockType.CODE);
}
@Test
@@ -293,7 +295,7 @@
public void blockBulletedListUnsupported() {
builder.setSupportedBlockTypes(Sets.newHashSet(BlockType.PARAGRAPH));
buildList(BlockType.BULLETED_LIST);
- assertContent("\n<p>test 0</p><p>test 1</p>\n");
+ assertContent("<p>test 0</p><p>test 1</p>");
}
@Test
@@ -307,7 +309,7 @@
public void blockNumericListUnsupported() {
builder.setSupportedBlockTypes(Sets.newHashSet(BlockType.PARAGRAPH));
buildList(BlockType.NUMERIC_LIST);
- assertContent("\n<p>test 0</p><p>test 1</p>\n");
+ assertContent("<p>test 0</p><p>test 1</p>");
}
@Test
@@ -321,13 +323,13 @@
public void testTableUnsupported() {
builder.setSupportedBlockTypes(Sets.newHashSet(BlockType.PARAGRAPH));
buildTable();
- assertContent("\n\n<p>test 0/0</p><p>test 1/0</p><p>test 2/0</p>\n\n<p>test 0/1</p><p>test 1/1</p><p>test 2/1</p>\n\n");
+ assertContent("<p>test 0/0</p><p>test 1/0</p><p>test 2/0</p><br/><br/><p>test 0/1</p><p>test 1/1</p><p>test 2/1</p><br/><br/>");
}
@Test
public void testParagraphUnsupported() {
builder.setSupportedBlockTypes(Collections.<BlockType> emptySet());
- assertUnsupportedBlock("\ntest\n", BlockType.PARAGRAPH);
+ assertUnsupportedBlock("test<br/><br/>", BlockType.PARAGRAPH);
}
@Test
@@ -642,6 +644,7 @@
}
private void assertContent(String expectedContent) {
+ builder.endDocument();
assertEquals(expectedContent, writer.toString());
}
}
diff --git a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderXhtmlStrictTest.java b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderXhtmlStrictTest.java
index acae39b..2eb31ce 100644
--- a/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderXhtmlStrictTest.java
+++ b/org.eclipse.mylyn.wikitext.html.tests/src/org/eclipse/mylyn/internal/wikitext/html/core/HtmlSubsetDocumentBuilderXhtmlStrictTest.java
@@ -188,7 +188,7 @@
public void paragraphAndDivNotSupported() {
builder.setSupportedBlockTypes(Sets.newHashSet(BlockType.CODE));
builder.characters("foo");
- assertContent("\nfoo\n");
+ assertContent("foo<br/><br/>");
}
@Test