From 327a952a2f36f3a4eef2d76c3671a1737e550ce5 Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Sat, 23 Apr 2011 08:23:52 +0200 Subject: [PATCH] SONAR-2384 Complete the support of emphasis --- sonar-markdown/pom.xml | 4 ---- .../java/org/sonar/markdown/HtmlEmphasisChannel.java | 6 ++++-- .../test/java/org/sonar/markdown/MarkdownEngineTest.java | 9 +++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/sonar-markdown/pom.xml b/sonar-markdown/pom.xml index 76e2a7c3aef..ed1672cfe65 100644 --- a/sonar-markdown/pom.xml +++ b/sonar-markdown/pom.xml @@ -16,10 +16,6 @@ org.codehaus.sonar sonar-channel - - commons-io - commons-io - org.slf4j slf4j-api 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 146797ed7e4..48d42b1114b 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java @@ -24,11 +24,13 @@ import org.sonar.channel.RegexChannel; class HtmlEmphasisChannel extends RegexChannel { public HtmlEmphasisChannel() { - super("\\*[^\n\r]*\\*"); + super("\\*\\S[^\n\r\\*\\s]*\\*"); } @Override protected void consume(CharSequence token, MarkdownOutput output) { - output.append("" + token.subSequence(1, token.length() - 1) + ""); + output.append(""); + output.append(token.subSequence(1, token.length() - 1)); + output.append(""); } } 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 e90b45a093f..f3669cd0181 100644 --- a/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java +++ b/sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java @@ -40,6 +40,15 @@ public class MarkdownEngineTest { public void shouldEmphaseText() { assertThat(MarkdownEngine.convertToHtml("This is *important*"), is("This is important")); assertThat(MarkdownEngine.convertToHtml("This should not be * \n emphase"), is("This should not be *
emphase")); + assertThat(MarkdownEngine.convertToHtml("This is *very* very *important*"), is("This is very very important")); + assertThat(MarkdownEngine.convertToHtml("Not * emphase * because of whitespaces"), is("Not * emphase * because of whitespaces")); + assertThat(MarkdownEngine.convertToHtml("Not *emphase * because of whitespace"), is("Not *emphase * because of whitespace")); + assertThat(MarkdownEngine.convertToHtml("Not * emphase* because of whitespace"), is("Not * emphase* because of whitespace")); + assertThat(MarkdownEngine.convertToHtml("emphase*inside*word"), is("emphaseinsideword")); + + // not supported yet + //assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*")); + } @Test -- 2.39.5