diff options
author | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-23 15:33:33 +0200 |
---|---|---|
committer | Freddy Mallet <freddy.mallet@gmail.com> | 2011-04-23 15:33:33 +0200 |
commit | 3e265a43011c4bc6c9b8c5df4484fcef8ac7965b (patch) | |
tree | 310dc035bfa52ddc2435085bc024ce325ef5ffcd | |
parent | 327a952a2f36f3a4eef2d76c3671a1737e550ce5 (diff) | |
download | sonarqube-3e265a43011c4bc6c9b8c5df4484fcef8ac7965b.tar.gz sonarqube-3e265a43011c4bc6c9b8c5df4484fcef8ac7965b.zip |
SONAR-2384 Add a new HtmlCodeChannel to transform ''printf()'' into <code>printf()</code>
6 files changed, 47 insertions, 4 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 new file mode 100644 index 00000000000..4fd5d3fd11c --- /dev/null +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlCodeChannel.java @@ -0,0 +1,36 @@ +/* + * 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.RegexChannel; + +class HtmlCodeChannel extends RegexChannel<MarkdownOutput> { + + public HtmlCodeChannel() { + super("''.+?''"); + } + + @Override + protected void consume(CharSequence token, MarkdownOutput output) { + output.append("<code>"); + output.append(token.subSequence(2, token.length() - 2)); + output.append("</code>"); + } +} 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 48d42b1114b..ffaf0ac60e7 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java @@ -24,7 +24,7 @@ import org.sonar.channel.RegexChannel; class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> { public HtmlEmphasisChannel() { - super("\\*\\S[^\n\r\\*\\s]*\\*"); + super("\\*[^\n\r\\*\\s]++\\*"); } @Override 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 6bfa51d8508..14933ca029a 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlUrlChannel.java @@ -24,7 +24,7 @@ import org.sonar.channel.RegexChannel; class HtmlUrlChannel extends RegexChannel<MarkdownOutput> { public HtmlUrlChannel() { - super("https?://[\\w\\d:#@%/;$()~_?\\+-=\\.&]*"); + super("https?://[\\w\\d:#@%/;$()~_?\\+-=\\.&]++"); } @Override diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/IdentifierAndNumberChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/IdentifierAndNumberChannel.java index cb94f4b205e..74b8dffb3b3 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/IdentifierAndNumberChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/IdentifierAndNumberChannel.java @@ -24,7 +24,7 @@ import org.sonar.channel.RegexChannel; class IdentifierAndNumberChannel extends RegexChannel<MarkdownOutput> { public IdentifierAndNumberChannel() { - super("[\\p{Alpha}\\d]++"); + super("[\\w\\d]++"); } @Override 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 fb51e9c4b2f..6a7f84dd7d4 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java @@ -37,6 +37,7 @@ public class MarkdownEngine { markdownChannels.add(new HtmlUrlChannel()); markdownChannels.add(new HtmlEndOfLineChannel()); markdownChannels.add(new HtmlEmphasisChannel()); + markdownChannels.add(new HtmlCodeChannel()); markdownChannels.add(new IdentifierAndNumberChannel()); markdownChannels.add(new BlackholeChannel()); dispatcher = new ChannelDispatcher<MarkdownOutput>(markdownChannels); 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 f3669cd0181..4054e9a97f6 100644 --- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java +++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java @@ -37,6 +37,12 @@ public class MarkdownEngineTest { } @Test + public void shouldDecorateCode() { + assertThat(MarkdownEngine.convertToHtml("This is a ''line of code''"), is("This is a <code>line of code</code>")); + assertThat(MarkdownEngine.convertToHtml("This is not a ''line of code"), is("This is not a ''line of code")); + } + + @Test public void shouldEmphaseText() { assertThat(MarkdownEngine.convertToHtml("This is *important*"), is("This is <em>important</em>")); assertThat(MarkdownEngine.convertToHtml("This should not be * \n emphase"), is("This should not be * <br/> emphase")); @@ -47,7 +53,7 @@ public class MarkdownEngineTest { assertThat(MarkdownEngine.convertToHtml("emphase*inside*word"), is("emphase<em>inside</em>word")); // not supported yet - //assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*")); + // assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*")); } |