diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-05 15:08:04 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-05-05 15:08:04 +0200 |
commit | bcc445118956633eb4084581a47edbe5672cefb4 (patch) | |
tree | bb9a602d2fe81041dd27ac00766b3895ce2f993e /sonar-markdown | |
parent | ae508ce93d67bb07ee70c2ec5290d6d093e12de4 (diff) | |
download | sonarqube-bcc445118956633eb4084581a47edbe5672cefb4.tar.gz sonarqube-bcc445118956633eb4084581a47edbe5672cefb4.zip |
Reduce technical debt
Diffstat (limited to 'sonar-markdown')
-rw-r--r-- | sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java | 5 | ||||
-rw-r--r-- | sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java | 42 |
2 files changed, 28 insertions, 19 deletions
diff --git a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java index 0f71e4cda31..956bd1978e5 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/HtmlListChannel.java @@ -34,6 +34,7 @@ class HtmlListChannel extends Channel<MarkdownOutput> { try { if (code.getColumnPosition() == 0 && listElement.consume(code, output)) { while (endOfLine.consume(code, output) && listElement.consume(code, output)) { + // consume input } output.append("</ul>"); return true; @@ -52,7 +53,7 @@ class HtmlListChannel extends Channel<MarkdownOutput> { @Override protected void consume(CharSequence token, MarkdownOutput output) { - if ( !pendingListConstruction) { + if (!pendingListConstruction) { output.append("<ul>"); pendingListConstruction = true; } @@ -75,7 +76,7 @@ class HtmlListChannel extends Channel<MarkdownOutput> { } } - private class EndOfLine extends RegexChannel<MarkdownOutput> { + private static final class EndOfLine extends RegexChannel<MarkdownOutput> { public EndOfLine() { super("(\r?\n)|(\r)"); 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 73c639e8182..13c80ce39ff 100644 --- a/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java +++ b/sonar-markdown/src/main/java/org/sonar/markdown/MarkdownEngine.java @@ -19,37 +19,45 @@ */ package org.sonar.markdown; -import java.util.ArrayList; -import java.util.List; - import org.sonar.channel.Channel; import org.sonar.channel.ChannelDispatcher; import org.sonar.channel.CodeReader; +import java.util.Arrays; +import java.util.List; + /** * Entry point of the Markdown library */ -public class MarkdownEngine { +public final class MarkdownEngine { - private MarkdownOutput output; private ChannelDispatcher<MarkdownOutput> dispatcher; private MarkdownEngine() { - output = new MarkdownOutput(); - List<Channel> markdownChannels = new ArrayList<Channel>(); - markdownChannels.add(new HtmlUrlChannel()); - markdownChannels.add(new HtmlEndOfLineChannel()); - markdownChannels.add(new HtmlEmphasisChannel()); - markdownChannels.add(new HtmlListChannel()); - markdownChannels.add(new HtmlCodeChannel()); - markdownChannels.add(new IdentifierAndNumberChannel()); - markdownChannels.add(new BlackholeChannel()); + List<Channel> markdownChannels = Arrays.<Channel>asList( + new HtmlUrlChannel(), + new HtmlEndOfLineChannel(), + new HtmlEmphasisChannel(), + new HtmlListChannel(), + new HtmlCodeChannel(), + new IdentifierAndNumberChannel(), + new BlackholeChannel()); dispatcher = new ChannelDispatcher<MarkdownOutput>(markdownChannels); } + private String convert(String input) { + CodeReader reader = new CodeReader(input); + try { + MarkdownOutput output = new MarkdownOutput(); + dispatcher.consume(reader, output); + return output.toString(); + + } finally { + reader.close(); + } + } + public static String convertToHtml(String input) { - MarkdownEngine engine = new MarkdownEngine(); - engine.dispatcher.consume(new CodeReader(input), engine.output); - return engine.output.toString(); + return new MarkdownEngine().convert(input); } } |