Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removing parse of old minted options

  • Loading branch information...
commit 2c45ea88ed788f6cb963532dd1207eef8b09e1a1 1 parent 5fefaaa
@csokol csokol authored
View
35 src/main/java/br/com/caelum/tubaina/parser/latex/CodeTag.java
@@ -1,7 +1,5 @@
package br.com.caelum.tubaina.parser.latex;
-import java.util.List;
-
import br.com.caelum.tubaina.parser.Indentator;
import br.com.caelum.tubaina.parser.Tag;
import br.com.caelum.tubaina.parser.html.CodeTagOptionsParser;
@@ -26,43 +24,18 @@ public CodeTag(Indentator indentator, SyntaxHighlighter syntaxHighlighter) {
codeTagOptionsParser = new CodeTagOptionsParser();
}
- public String parse(String string, String options) {
+ public String parse(String code, String options) {
- String mintedOptionalParameters = parseOptinals(options);
String chosenLanguage = codeTagOptionsParser.parseLanguage(options);
String latexFilename = latexFilenameFor(codeTagOptionsParser.parseFileName(options));
String latexReference = latexLabelFor(codeTagOptionsParser.parseLabel(options));
boolean numbered = options.contains(" #");
- String indentedString = this.indentator.indent(string);
+ String indentedCode = this.indentator.indent(code);
- String highlightedCode = syntaxHighlighter.highlight(indentedString, chosenLanguage, numbered);
-
- return latexReference + latexFilename + CodeTag.BEGIN + mintedOptionalParameters + "{"
- + chosenLanguage + "}\n" + highlightedCode + CodeTag.END;
- }
-
- private String parseOptinals(String options) {
- StringBuilder optionals = new StringBuilder("[");
- if (options.contains("#")) {
- optionals.append("linenos, numbersep=5pt");
- }
- List<Integer> lines = codeTagOptionsParser.parseHighlights(options);
- addLineHighlights(lines, optionals);
- String finalOptionals = optionals.append("]").toString();
- return finalOptionals.equals("[]")? "" : finalOptionals;
- }
+ String highlightedCode = syntaxHighlighter.highlight(indentedCode, chosenLanguage, numbered);
- private void addLineHighlights(List<Integer> lines, StringBuilder options) {
- if (!lines.isEmpty()) {
- options.append(", h=");
- for (Integer line : lines) {
- options.append(line.toString());
- options.append(",");
- }
- options.deleteCharAt(options.length() - 1);
- options.append("");
- }
+ return latexReference + latexFilename + CodeTag.BEGIN + highlightedCode + CodeTag.END;
}
private String latexFilenameFor(String filename) {
View
8 src/test/java/br/com/caelum/tubaina/parser/html/CodeTagOptionsParserTest.java
@@ -50,5 +50,13 @@ public void shouldParseFileName() {
String label = codeTagOptionsParser.parseFileName(options);
assertEquals("src/Main.java", label);
}
+
+ @Test
+ public void shouldParseJavascriptLang() {
+ CodeTagOptionsParser codeTagOptionsParser = new CodeTagOptionsParser();
+ String options = "javascript";
+ String lang = codeTagOptionsParser.parseLanguage(options);
+ assertEquals("javascript", lang);
+ }
}
View
149 src/test/java/br/com/caelum/tubaina/parser/latex/CodeTagTest.java
@@ -1,5 +1,6 @@
package br.com.caelum.tubaina.parser.latex;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
@@ -9,90 +10,82 @@
import br.com.caelum.tubaina.parser.html.desktop.SyntaxHighlighter;
import br.com.caelum.tubaina.util.CommandExecutor;
-
public class CodeTagTest {
- private CodeTag codeTag;
-
- @Before
- public void setUp() {
- this.codeTag = new CodeTag(new SimpleIndentator(4), new SyntaxHighlighter(new CommandExecutor(),
- SyntaxHighlighter.LATEX_OUTPUT));
+ private CodeTag codeTag;
+
+ @Before
+ public void setUp() {
+ this.codeTag = new CodeTag(new SimpleIndentator(4), new SyntaxHighlighter(
+ new CommandExecutor(), SyntaxHighlighter.LATEX_OUTPUT));
+ }
+
+ @Test
+ public void testPropertiesCodeTag() throws Exception {
+ String options = "properties";
+ String string = "blablah blah\n" + "#algum comentario\n" + "texto=valor\n"
+ + "texto:valor\n" + "texto valor";
+ String output = codeTag.parse(string, options);
+
+ assertPygmentsRan(output);
+ }
+
+ @Test
+ public void testPropertiesCodeTagWithEscapes() throws Exception {
+ String options = "properties abc";
+ String string = "blablah blah\n" + "#algum comentario\n" + "texto\\=valor=valor\n"
+ + "texto\\:valor:valor\n" + "texto\\ valor valor\n" + "a b\\#fake comentario";
+ String output = codeTag.parse(string, options);
+
+ assertPygmentsRan(output);
+ }
+
+ @Test
+ public void languageCodeTagShouldInsertLineNumbersWhenOptionContainsSharp() {
+ String string = "public static void main(String[] args) {";
+ String options = "java #";
+ String output = codeTag.parse(string, options);
+
+ assertPygmentsRan(output);
+ }
+
+ @Test
+ public void languageCodeTagShouldUnderstandLineNumbersEvenWhenNoLanguageIsSelected() {
+ String string = "def some: \"bizarre code\" in: unknownLanguage";
+ String options = "#";
+ String output = codeTag.parse(string, options);
+
+ assertPygmentsRan(output);
+ }
+
+ @Test
+ public void languageCodeTagShouldUnderstandLineNumbersAndHighlightsWhenNoLanguageIsSelected() {
+ String string = "def some: \"bizarre code\" \nin: unknownLanguage";
+ String options = "# h=1,2";
+ String output = codeTag.parse(string, options);
+
+ assertPygmentsRan(output);
}
@Test
- public void testPropertiesCodeTag() throws Exception {
- String options = "properties";
- String string = "blablah blah\n" +
- "#algum comentario\n" +
- "texto=valor\n" +
- "texto:valor\n" +
- "texto valor";
- String output = codeTag.parse(string, options);
-
- assertPygmentsRan(output);
- }
- @Test
- public void testPropertiesCodeTagWithEscapes() throws Exception {
- String options = "properties abc";
- String string = "blablah blah\n" +
- "#algum comentario\n" +
- "texto\\=valor=valor\n" +
- "texto\\:valor:valor\n" +
- "texto\\ valor valor\n" +
- "a b\\#fake comentario";
- String output = codeTag.parse(string, options);
-
- assertPygmentsRan(output);
- }
-
- @Test
- public void languageCodeTagShouldInsertLineNumbersWhenOptionContainsSharp(){
- String string = "public static void main(String[] args) {";
- String options = "java #";
- String output = codeTag.parse(string , options );
-
- assertPygmentsRan(output);
- }
-
- @Test
- public void languageCodeTagShouldUnderstandLineNumbersEvenWhenNoLanguageIsSelected(){
- String string = "def some: \"bizarre code\" in: unknownLanguage";
- String options = "#";
- String output = codeTag.parse(string , options);
-
- assertPygmentsRan(output);
- }
-
- @Test
- public void languageCodeTagShouldUnderstandLineNumbersAndHighlightsWhenNoLanguageIsSelected(){
- String string = "def some: \"bizarre code\" \nin: unknownLanguage";
- String options = "# h=1,2";
- String output = codeTag.parse(string , options );
-
- assertPygmentsRan(output);
- }
-
- @Test
- public void languageCodeTagShouldUnderstandLineNumbersAndCSharpLanguage(){
- String string = "public class SomeClass {";
- String options = "c# #";
- String output = codeTag.parse(string , options );
-
+ public void languageCodeTagShouldUnderstandLineNumbersAndCSharpLanguage() {
+ String string = "public class SomeClass {";
+ String options = "c# #";
+ String output = codeTag.parse(string, options);
+
assertPygmentsRan(output);
- }
-
+ }
+
@Test
public void codeTagWithReferenceWithoutLanguage() throws Exception {
String options = "label=javacode1";
String code = "class Main {\n" + "public static void main(String[] args) {\n"
+ "System.out.println(\"Hello world\");\n" + "}\n}";
String output = codeTag.parse(code, options);
-
+
assertTrue(output.startsWith("\\tubainaCodeLabel{javacode1}"));
assertPygmentsRan(output);
}
-
@Test
public void codeTagWithReferenceWithLanguage() throws Exception {
@@ -100,7 +93,7 @@ public void codeTagWithReferenceWithLanguage() throws Exception {
String code = "class Main {\n" + "public static void main(String[] args) {\n"
+ "System.out.println(\"Hello world\");\n" + "}\n}";
String output = codeTag.parse(code, options);
-
+
assertTrue(output.startsWith("\\tubainaCodeLabel{javacode1}"));
assertPygmentsRan(output);
}
@@ -111,7 +104,7 @@ public void codeTagWithFileNameWithoutLanguage() throws Exception {
String code = "class Main {\n" + "public static void main(String[] args) {\n"
+ "System.out.println(\"Hello world\");\n" + "}\n}";
String output = codeTag.parse(code, options);
-
+
assertTrue(output.startsWith("\\tubainaCodeFileName{src/Main.java}\n"));
assertPygmentsRan(output);
}
@@ -122,7 +115,7 @@ public void codeTagWithFileNameWithLanguage() throws Exception {
String code = "class Main {\n" + "public static void main(String[] args) {\n"
+ "System.out.println(\"Hello world\");\n" + "}\n}";
String output = codeTag.parse(code, options);
-
+
assertTrue(output.startsWith("\\tubainaCodeFileName{src/Main.java}\n"));
assertPygmentsRan(output);
}
@@ -138,9 +131,19 @@ public void codeTagWithFileNameWithLanguageAndLabel() throws Exception {
assertPygmentsRan(output);
}
+ @Test
+ public void javascriptLangBug() throws Exception {
+ String options = "javascript";
+ String code = "writeTotal(3.14159);";
+ String output = codeTag.parse(code, options);
+
+ assertFalse(output.contains("javascript"));
+ assertPygmentsRan(output);
+ }
+
private void assertPygmentsRan(String output) {
assertTrue(output.contains("\\begin{Verbatim}[commandchars="));
assertTrue(output.contains("\\end{Verbatim}"));
}
- //TODO: file name as an option to code
+ // TODO: file name as an option to code
}
Please sign in to comment.
Something went wrong with that request. Please try again.