]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2384 Complete the support of emphasis
authorsimonbrandhof <simon.brandhof@gmail.com>
Sat, 23 Apr 2011 06:23:52 +0000 (08:23 +0200)
committersimonbrandhof <simon.brandhof@gmail.com>
Sat, 23 Apr 2011 06:23:52 +0000 (08:23 +0200)
sonar-markdown/pom.xml
sonar-markdown/src/main/java/org/sonar/markdown/HtmlEmphasisChannel.java
sonar-markdown/src/test/java/org/sonar/markdown/MarkdownEngineTest.java

index 76e2a7c3aefa886825834bf0c54a49add25a0ef4..ed1672cfe65334cbc119a24adbc12282a2c5a5ff 100644 (file)
                        <groupId>org.codehaus.sonar</groupId>
                        <artifactId>sonar-channel</artifactId>
                </dependency>
-               <dependency>
-                       <groupId>commons-io</groupId>
-                       <artifactId>commons-io</artifactId>
-               </dependency>
                <dependency>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
index 146797ed7e4a50ffe1ca1e752231698490e8042c..48d42b1114b3be750a1a2641dfde63607a583b03 100644 (file)
@@ -24,11 +24,13 @@ import org.sonar.channel.RegexChannel;
 class HtmlEmphasisChannel extends RegexChannel<MarkdownOutput> {
 
   public HtmlEmphasisChannel() {
-    super("\\*[^\n\r]*\\*");
+    super("\\*\\S[^\n\r\\*\\s]*\\*");
   }
 
   @Override
   protected void consume(CharSequence token, MarkdownOutput output) {
-    output.append("<em>" + token.subSequence(1, token.length() - 1) + "</em>");
+    output.append("<em>");
+    output.append(token.subSequence(1, token.length() - 1));
+    output.append("</em>");
   }
 }
index e90b45a093f63815945a0f026ef52f002502fbea..f3669cd018127d680435cd4d4309ba5b887dbdef 100644 (file)
@@ -40,6 +40,15 @@ public class MarkdownEngineTest {
   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"));
+    assertThat(MarkdownEngine.convertToHtml("This is *very* very *important*"), is("This is <em>very</em> very <em>important</em>"));
+    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("emphase<em>inside</em>word"));
+
+    // not supported yet
+    //assertThat(MarkdownEngine.convertToHtml("\\*surrounded by literal asterisks\\*"), is("\\*surrounded by literal asterisks\\*"));
+
   }
 
   @Test