<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>
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>");
}
}
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