summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremie Bresson2012-07-09 09:52:54 (EDT)
committer David Green2012-07-09 09:54:59 (EDT)
commit06dad7631296413db2294f81c0ae6bbd6ee1224a (patch)
tree8b27b54ae2aecd74ad1d5bcc10f8c391533a9867
parenta7131f1a24bc3bbbd7389872ab61c09b055c1091 (diff)
downloadorg.eclipse.mylyn.docs-06dad7631296413db2294f81c0ae6bbd6ee1224a.zip
org.eclipse.mylyn.docs-06dad7631296413db2294f81c0ae6bbd6ee1224a.tar.gz
org.eclipse.mylyn.docs-06dad7631296413db2294f81c0ae6bbd6ee1224a.tar.bz2
bug 381506: [MediaWiki] support markups and tags in pre-formatted blocks
In pre-formatted blocks starting with a space (not using a <pre> tag) it is possible to include wiki markups and some html tags to create style (for example <font>). Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=381506 Change-Id: I616a41d96ef6eae5b571fcc8f7c50a7328b22048
-rw-r--r--org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/PreformattedBlock.java19
-rw-r--r--org.eclipse.mylyn.wikitext.tests/src/org/eclipse/mylyn/wikitext/mediawiki/core/MediaWikiLanguageTest.java34
2 files changed, 47 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/PreformattedBlock.java b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/PreformattedBlock.java
index 8fa6287..8f286d8 100644
--- a/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/PreformattedBlock.java
+++ b/org.eclipse.mylyn.wikitext.mediawiki.core/src/org/eclipse/mylyn/internal/wikitext/mediawiki/core/block/PreformattedBlock.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 David Green and others.
+ * Copyright (c) 2007, 2012 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 381506
*******************************************************************************/
package org.eclipse.mylyn.internal.wikitext.mediawiki.core.block;
@@ -82,9 +83,7 @@ public class PreformattedBlock extends Block {
int contentEnd = closeMatcher.start(1);
int newContentStart = closeMatcher.end(1);
if (contentEnd > 0) {
- String content = line.substring(offset, contentEnd);
- builder.characters(content);
- builder.characters("\n"); //$NON-NLS-1$
+ addContent(line.substring(0, contentEnd), offset);
}
setClosed(true);
if (newContentStart < line.length()) {
@@ -100,12 +99,20 @@ public class PreformattedBlock extends Block {
}
}
if (line.length() >= lineStart) {
- builder.characters(line.substring(lineStart));
- builder.characters("\n"); //$NON-NLS-1$
+ addContent(line, lineStart);
}
return -1;
}
+ private void addContent(String line, int offset) {
+ if (usesTag) {
+ builder.characters(line.substring(offset));
+ } else {
+ getMarkupLanguage().emitMarkupLine(parser, state, line, offset);
+ }
+ builder.characters("\n"); //$NON-NLS-1$
+ }
+
private void processHtmlAttributes(Attributes attributes, String htmlAttributes) {
if (htmlAttributes != null) {
Pattern pattern = Pattern.compile("\\s+([a-zA-Z][a-zA-Z0-9_:-]*)=\"([^\"]*)\""); //$NON-NLS-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 df3aabb..781c712 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,6 +7,7 @@
*
* Contributors:
* David Green - initial API and implementation
+ * Jeremie Bresson - Bug 381506
*******************************************************************************/
package org.eclipse.mylyn.wikitext.mediawiki.core;
@@ -339,6 +340,7 @@ public class MediaWikiLanguageTest extends TestCase {
}
public void testPreformattedWithTagStartEndOnSameLine2() {
+ //see also BUG 381506 for the usage of tags:
String html = parser.parseToHtml("example:\n\n<pre><a href=\"show_bug.cgi\\?id\\=(.+?)\">.+?<span class=\"summary\">(.+?)</span></pre>\n\nIf");
TestUtil.println("HTML: \n" + html);
assertTrue(Pattern.compile(
@@ -358,6 +360,38 @@ public class MediaWikiLanguageTest extends TestCase {
.find());
}
+ public void testPreformattedWithTagAndMarkup() {
+ //BUG 381506:
+ String html = parser.parseToHtml("example:\n\n<pre>a block\nWith '''Bold text''' or ''Italic text'' style\nIs not converted</pre>\n\nIf");
+ TestUtil.println("HTML: \n" + html);
+ assertTrue(Pattern.compile(
+ "<body><p>example:</p><pre>"
+ + "a block\\s+With '''Bold text''' or ''Italic text'' style\\s+Is not converted"
+ + "\\s+</pre><p>If</p></body>")
+ .matcher(html)
+ .find());
+ }
+
+ public void testPreformattedWithMarkup() {
+ //BUG 381506:
+ String html = parser.parseToHtml("normal para\n preformatted\n with '''Bold text''' or ''Italic text'' style\n more pre\nnormal para");
+ TestUtil.println("HTML: \n" + html);
+ assertTrue(Pattern.compile(
+ "<body><p>normal para</p><pre>preformatted\\s+with <b>Bold text</b> or <i>Italic text</i> style\\s+more pre\\s+</pre><p>normal para</p></body>")
+ .matcher(html)
+ .find());
+ }
+
+ public void testPreformattedWithFont() {
+ //BUG 381506:
+ String html = parser.parseToHtml("normal para\n preformatted\n with <font color=\"red\">some red color</font>\n more pre\nnormal para");
+ TestUtil.println("HTML: \n" + html);
+ assertTrue(Pattern.compile(
+ "<body><p>normal para</p><pre>preformatted\\s+with <font color=\"red\">some red color</font>\\s+more pre\\s+</pre><p>normal para</p></body>")
+ .matcher(html)
+ .find());
+ }
+
public void testHtmlTags() {
String html = parser.parseToHtml("normal para <b id=\"foo\">test heading</b>");
TestUtil.println("HTML: \n" + html);