aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-markdown/src
diff options
context:
space:
mode:
authorFreddy Mallet <freddy.mallet@gmail.com>2011-04-24 00:42:00 +0200
committerFreddy Mallet <freddy.mallet@gmail.com>2011-04-24 00:42:00 +0200
commit06af298d5bc741fd45ade3045f98518db1f61357 (patch)
tree770e6e3e187e5535ca08e1402416f90881a1673c /sonar-markdown/src
parente9c89df95a32fae52406c4400a76a68121a1f3d9 (diff)
downloadsonarqube-06af298d5bc741fd45ade3045f98518db1f61357.tar.gz
sonarqube-06af298d5bc741fd45ade3045f98518db1f61357.zip
SONAR-2384 Add support for html list and fix javadoc by escaping html tags
Diffstat (limited to 'sonar-markdown/src')
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java4
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java4
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlEndOfLineChannel.java2
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java89
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java2
-rw-r--r--sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java1
-rw-r--r--sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java5
7 files changed, 101 insertions, 6 deletions
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java
index b2601557b34..ed2591a0197 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java
@@ -22,9 +22,9 @@ package org.sonar.markdown;
import org.sonar.channel.RegexChannel;
/**
- * Markdown treats double simple quotes ('') as indicators of code. Text wrapped with two '' will be wrapped with an HTML <code> tag.
+ * Markdown treats double simple quotes ('') as indicators of code. Text wrapped with two '' will be wrapped with an HTML {@literal <code>} tag.
*
- * E.g., the input ''printf()'' will produce <code>printf()</code>
+ * E.g., the input ''printf()'' will produce {@literal<code>}printf(){@literal</code>}
*/
class HtmlCodeChannel extends RegexChannel<MarkdownOutput> {
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
index bb53dd8a43e..da0c263cb13 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
@@ -22,9 +22,9 @@ package org.sonar.markdown;
import org.sonar.channel.RegexChannel;
/**
- * Markdown treats asterisks (*) as indicators of emphasis. Text wrapped with one * will be wrapped with an HTML <em> tag.
+ * Markdown treats asterisks (*) as indicators of emphasis. Text wrapped with one * will be wrapped with an HTML {@literal <em>} tag.
*
- * E.g., the input *word* will produce <em>work</word>
+ * E.g., the input *word* will produce {@literal <em>}work{@literal </word>}
*/
class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEndOfLineChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEndOfLineChannel.java
index e990b0a9584..6ca806ed97c 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEndOfLineChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEndOfLineChannel.java
@@ -22,7 +22,7 @@ package org.sonar.markdown;
import org.sonar.channel.RegexChannel;
/**
- * Markdown replace any line return by an HTML <br/>
+ * Markdown replace any line return by an HTML {@literal <br/>}
* tag.
*
*/
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java
new file mode 100644
index 00000000000..0f71e4cda31
--- /dev/null
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java
@@ -0,0 +1,89 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.markdown;
+
+import org.sonar.channel.Channel;
+import org.sonar.channel.CodeReader;
+import org.sonar.channel.RegexChannel;
+
+class HtmlListChannel extends Channel<MarkdownOutput> {
+
+ private ListElementChannel listElement = new ListElementChannel();
+ private EndOfLine endOfLine = new EndOfLine();
+ private boolean pendingListConstruction;
+
+ @Override
+ public boolean consume(CodeReader code, MarkdownOutput output) {
+ try {
+ if (code.getColumnPosition() == 0 && listElement.consume(code, output)) {
+ while (endOfLine.consume(code, output) && listElement.consume(code, output)) {
+ }
+ output.append("</ul>");
+ return true;
+ }
+ return false;
+ } finally {
+ pendingListConstruction = false;
+ }
+ }
+
+ private class ListElementChannel extends RegexChannel<MarkdownOutput> {
+
+ public ListElementChannel() {
+ super("\\s*+\\*\\s[^\r\n]*+");
+ }
+
+ @Override
+ protected void consume(CharSequence token, MarkdownOutput output) {
+ if ( !pendingListConstruction) {
+ output.append("<ul>");
+ pendingListConstruction = true;
+ }
+ output.append("<li>");
+ output.append(token.subSequence(searchIndexOfFirstCharacter(token), token.length()));
+ output.append("</li>");
+ }
+
+ private int searchIndexOfFirstCharacter(CharSequence token) {
+ for (int index = 0; index < token.length(); index++) {
+ if (token.charAt(index) == '*') {
+ for (index++; index < token.length(); index++) {
+ if (token.charAt(index) != ' ') {
+ return index;
+ }
+ }
+ }
+ }
+ return token.length() - 1;
+ }
+ }
+
+ private class EndOfLine extends RegexChannel<MarkdownOutput> {
+
+ public EndOfLine() {
+ super("(\r?\n)|(\r)");
+ }
+
+ @Override
+ protected void consume(CharSequence token, MarkdownOutput output) {
+ output.append(token);
+ }
+ }
+}
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java
index 7080a6abe3f..2158c428f00 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java
@@ -22,7 +22,7 @@ package org.sonar.markdown;
import org.sonar.channel.RegexChannel;
/**
- * Markdown will wrap any URL with an HTML <a href="URL"> tag.
+ * Markdown will wrap any URL with an HTML {@literal <a href="URL">} tag.
*
*/
class HtmlUrlChannel extends RegexChannel<MarkdownOutput> {
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java b/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java
index 773126ac166..73c639e8182 100644
--- a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java
+++ b/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java
@@ -40,6 +40,7 @@ public class MarkdownEngine {
markdownChannels.add(new HtmlUrlChannel());
markdownChannels.add(new HtmlEndOfLineChannel());
markdownChannels.add(new HtmlEmphasisChannel());
+ markdownChannels.add(new HtmlListChannel());
markdownChannels.add(new HtmlCodeChannel());
markdownChannels.add(new IdentifierAndNumberChannel());
markdownChannels.add(new BlackholeChannel());
diff --git a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
index 4054e9a97f6..9579828af9b 100644
--- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
+++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java
@@ -35,6 +35,11 @@ public class MarkdownEngineTest {
public void shouldDecorateEndOfLine() {
assertThat(MarkdownEngine.convertToHtml("1\r2\r\n3\n"), is("1<br/>2<br/>3<br/>"));
}
+
+ @Test
+ public void shouldDecorateList() {
+ assertThat(MarkdownEngine.convertToHtml(" * one\r* two\r\n* three\n * \n *five"), is("<ul><li>one</li>\r<li>two</li>\r\n<li>three</li>\n<li> </li>\n</ul> *five"));
+ }
@Test
public void shouldDecorateCode() {