From 06af298d5bc741fd45ade3045f98518db1f61357 Mon Sep 17 00:00:00 2001 From: Freddy Mallet Date: Sun, 24 Apr 2011 00:42:00 +0200 Subject: [PATCH] SONAR-2384 Add support for html list and fix javadoc by escaping html tags --- .../org/sonar/markdown/HtmlCodeChannel.java | 4 +- .../sonar/markdown/HtmlEmphasisChannel.java | 4 +- .../sonar/markdown/HtmlEndOfLineChannel.java | 2 +- .../org/sonar/markdown/HtmlListChannel.java | 89 +++++++++++++++++++ .../org/sonar/markdown/HtmlUrlChannel.java | 2 +- .../org/sonar/markdown/MarkdownEngine.java | 1 + .../sonar/markdown/MarkdownEngineTest.java | 5 ++ 7 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java 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 tag. + * Markdown treats double simple quotes ('') as indicators of code. Text wrapped with two '' will be wrapped with an HTML {@literal } tag. * - * E.g., the input ''printf()'' will produce printf() + * E.g., the input ''printf()'' will produce {@literal}printf(){@literal} */ class HtmlCodeChannel extends RegexChannel { 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 tag. + * Markdown treats asterisks (*) as indicators of emphasis. Text wrapped with one * will be wrapped with an HTML {@literal } tag. * - * E.g., the input *word* will produce work + * E.g., the input *word* will produce {@literal }work{@literal } */ class HtmlEmphasisChannel extends RegexChannel { 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
+ * Markdown replace any line return by an HTML {@literal
} * 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 { + + 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(""); + return true; + } + return false; + } finally { + pendingListConstruction = false; + } + } + + private class ListElementChannel extends RegexChannel { + + public ListElementChannel() { + super("\\s*+\\*\\s[^\r\n]*+"); + } + + @Override + protected void consume(CharSequence token, MarkdownOutput output) { + if ( !pendingListConstruction) { + output.append("