diff --git a/.gitignore b/.gitignore index 3297b0f..fc3126c 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,11 @@ out/ # Other *.pyc + +#Eclipse +/bin/ + +#Gradle +.gradle +build/ + diff --git a/README.markdown b/README.markdown index 53c3003..f3df268 100644 --- a/README.markdown +++ b/README.markdown @@ -76,6 +76,16 @@ concurrent accesses, since neither the [PegDownProcessor] nor the underlying par See for the pegdown API documentation. +Command Line Interface +---------------------- + +Running _pegdown_ from the command line is pretty easy as well. Download the `-fat` jar file from the link given in the Installation instructions. And run: + +`> java -jar pegdown--fat.jar` + +The command line options will be printed to the console. + + Plugins ------- diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..71369f4 --- /dev/null +++ b/build.gradle @@ -0,0 +1,104 @@ +apply plugin: 'java' +apply plugin: 'eclipse' +apply plugin: 'maven-publish' + +sourceCompatibility = 1.6 +version = '1.6' +group = 'org.pegdown' + + +jar { + manifest { + attributes 'Implementation-Title': 'PegDown', + 'Implementation-Version': version + } +} + +repositories { + mavenCentral() + jcenter() + maven { + url "https://repo1.maven.org/maven2" + } + +} + + + +dependencies { + compile ( + [group: 'org.parboiled', name: 'parboiled-java', version: '1.1.7'] + ) + testCompile ( + [group: 'net.sf.jtidy', name: 'jtidy', version: 'r938'], + [group: 'org.specs2', name: 'specs2-core_2.11', version: '2.4.16'] + ) +} + + + + task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allSource + } + + task docJar(type: Jar) { + dependsOn javadoc + classifier "javadoc" + from javadoc.destinationDir + } + + task allJar(type: Jar){ + dependsOn sourceJar, docJar, jar + classifier "all" + from sourceSets.main.allSource, javadoc.destinationDir, sourceSets.main.output + } + +//create a single Jar with all dependencies +task fatJar(type: Jar) { + group = "java" + dependsOn classes + classifier "fat" + baseName = project.name + '-fat' + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} + + + publishing { + publications { + maven(MavenPublication) { + from components.java + artifact sourceJar + artifact docJar + artifact allJar + artifact fatJar + + pom.withXml{ + Node n=asNode().appendNode("scm") + n.appendNode("url","git@github.com:sirthias/pegdown.git") + n.appendNode("connection","scm:git:git@github.com:sirthias/pegdown.git") + //developers + n=asNode().appendNode("developers") + n=n.appendNode("developer") + n.appendNode("id","sirthias") + n.appendNode("name","Mathias Doenitz") + //licences + Node lic=asNode().appendNode("licenses") + n=lic.appendNode("license") + n.appendNode("name","Apache License 2.0") + n.appendNode("url","http://www.apache.org/licenses/LICENSE-2.0") + n.appendNode("distribution","repo") + n.appendNode("comments","Applies to all PegDown products") + //fat jar + n=lic.appendNode("license") + n.appendNode("name","OW2 License") + n.appendNode("url","http://asm.ow2.org/license.html") + n.appendNode("distribution","repo") + n.appendNode("comments","The -fat library repacks dependent libraries. This additional license applies only to specific parts of the product.") + + } + } + } + } + diff --git a/src/main/java/org/pegdown/cli/PegDownCLI.java b/src/main/java/org/pegdown/cli/PegDownCLI.java new file mode 100644 index 0000000..2e420d3 --- /dev/null +++ b/src/main/java/org/pegdown/cli/PegDownCLI.java @@ -0,0 +1,137 @@ +package org.pegdown.cli; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardOpenOption; +import java.nio.file.attribute.FileAttribute; +import java.util.List; + +import org.pegdown.Extensions; +import org.pegdown.PegDownProcessor; + +/** + * This class is the command line interface for PegDown. It simply converts one input file to a html output file. + * + * @author Jan Ortner + * + */ +public class PegDownCLI { + + /** + * The main method parses the arguments, reads the input file, transforms the content via a PegDownProcessor + * to a html string and writes this string to the output file. + * @param args the command line arguments (see {@link #printUsage()}) + */ + public static void main(String[] args) { + Path input=null; + Path output=null; + int extensions=Extensions.ALL; + //parsing arguments + for(int i=0; i inLines=Files.readAllLines(input); + String in=""; + for(String line:inLines){ + in+=line+"\n"; + } + PegDownProcessor proc=new PegDownProcessor(extensions); + String out=proc.markdownToHtml(in); + try { + if(output.getParent()!=null) + Files.createDirectory(output.getParent(), (FileAttribute[]) null); + Files.write(output, out.getBytes(), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE ); + } catch (IOException e) { + e.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Gets the mask of the given extension. It reads the static variable with the given name from + * {@link Extensions} and returns the value of the field. + * @param extension the extension + * @return the mask or 0 if the extension was not found + */ + public static int getExtensionMask(String extension){ + try{ + Field f=Extensions.class.getField(extension); + if((f.getModifiers()&Modifier.STATIC)!=0 + && f.getType().equals(int.class) + ){ + return f.getInt(null); + } + + }catch(Exception e){ + e.printStackTrace(); + } + return 0; + } + + /** + * Prints the usage to the standard output stream. + */ + public static void printUsage(){ + String usage="Usage: \n"; + usage+="java -jar org.pegdown.cli.PegDownCLI [+/-E\"extension\"] [ouputfile]\n"; + usage+="\ninputfile:\n"; + usage+="The input file needs to be in markdownformat\n"; + usage+="\noutputfile:\n"; + usage+="The output file will be in html format\n"; + usage+="\nExtensions:\n"; + usage+="+ or - will select if an extension should be added or removed.\n"; + usage+="This is done in the order given by the arguments, initially ALL extensions are enabled.\n"; + usage+="Example:\n"; + usage+="-EALL - will remove all default extensions\n"; + usage+="Built-in extensions:\n"; + Field[] extensions=Extensions.class.getDeclaredFields(); + for(int i=0; i