Permalink
Browse files

Differentiating numbered code from unnumbered on code cache

  • Loading branch information...
1 parent 981ca94 commit 19aeb58f529960f1bfc7932c0237ad2d3e2ecbe6 @ceci ceci committed Apr 24, 2013
@@ -13,7 +13,7 @@
public CodeTag() {
SyntaxHighlighter syntaxHighlighter = new SyntaxHighlighter(new SimpleCommandExecutor(),
- CodeOutputType.KINDLE_HTML, new CodeCache(CodeOutputType.HTML));
+ CodeOutputType.HTML, new CodeCache(CodeOutputType.HTML));
htmlCodeTag = new HtmlAndKindleCodeTag(syntaxHighlighter);
}
@@ -28,13 +28,14 @@ public SyntaxHighlighter(CommandExecutor commandExecutor, CodeOutputType outputT
}
public String highlight(String code, String language, boolean numbered, List<Integer> lines) {
- if (codeCache.exists(code)) {
- return codeCache.find(code);
+ String codeAndOptions = code + numbered;
+ if (codeCache.exists(codeAndOptions)) {
+ return codeCache.find(codeAndOptions);
}
ArrayList<String> commandWithArgs = buildCommand(language, numbered, lines);
String codeHighlighted = commandExecutor.execute(commandWithArgs, code);
- codeCache.write(code, codeHighlighted);
+ codeCache.write(codeAndOptions, codeHighlighted);
return codeHighlighted;
}
@@ -7,24 +7,37 @@
public class CodeTagTest extends AbstractTagTest {
- @Test
- public void shouldCallHtmlCodeTag() {
- String code = "public static void main(String[] args) {\n" +
- " String name = \"Gabriel\";\n" +
- " System.out.println(\"Hello, \" + name);\n" +
- "}";
- CodeChunk chunk = new CodeChunk(code, "");
+ @Test
+ public void notNumberedGenericCode() {
+ String code = "public static void main(String[] args) {\n" + " String name = \"Gabriel\";\n"
+ + " System.out.println(\"Hello, \" + name);\n" + "}";
+ CodeChunk chunk = new CodeChunk(code, "");
String result = getContent(chunk);
- Assert.assertEquals("<pre ><div class=\"highlight\">" +
- "<pre><span class=\"lineno\">1</span> " +
- "public static void main(String[] args) {" +
- "\n<span class=\"lineno\">2</span> " +
- " String name = &quot;Gabriel&quot;;" +
- "\n<span class=\"lineno\">3</span> " +
- " System.out.println(&quot;Hello, &quot; + name);" +
- "\n<span class=\"lineno\">4</span>" +
- " }" +
- "\n</pre>" +
+ Assert.assertEquals("<pre ><div class=\"highlight\">" +
+ "<pre>public static void main(String[] args) {" +
+ "\n String name = &quot;Gabriel&quot;;" +
+ "\n System.out.println(&quot;Hello, &quot; + name);" +
+ "\n}" +
+ "\n</pre>" +
+ "</div></pre>", result);
+ }
+
+ @Test
+ public void numberedGenericCode() {
+ String code = "public static void main(String[] args) {\n" + " String name = \"Gabriel\";\n"
+ + " System.out.println(\"Hello, \" + name);\n" + "}";
+ CodeChunk chunk = new CodeChunk(code, "#");
+ String result = getContent(chunk);
+ Assert.assertEquals("<pre ><div class=\"highlight\">" +
+ "<pre><span class=\"lineno\">1</span> " +
+ "public static void main(String[] args) {" +
+ "\n<span class=\"lineno\">2</span> " +
+ " String name = &quot;Gabriel&quot;;" +
+ "\n<span class=\"lineno\">3</span> " +
+ " System.out.println(&quot;Hello, &quot; + name);" +
+ "\n<span class=\"lineno\">4</span>" +
+ " }" +
+ "\n</pre>" +
"</div></pre>", result);
}
}

0 comments on commit 19aeb58

Please sign in to comment.