Skip to content

Commit

Permalink
Merged #63.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbullock committed Dec 24, 2013
2 parents f47137f + de30990 commit 5a9427b
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 41 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<args4j.version>2.0.23</args4j.version>
<freemarker.version>2.3.19</freemarker.version>
<junit.version>4.8.1</junit.version>
<markdownj.version>0.3.0-1.0.2b4</markdownj.version>
<pegdown.version>1.4.1</pegdown.version>
<jetty.version>8.1.12.v20130726</jetty.version>
</properties>

Expand Down Expand Up @@ -216,9 +216,9 @@
<version>5.1.21</version>
</dependency> -->
<dependency>
<groupId>org.markdownj</groupId>
<artifactId>markdownj</artifactId>
<version>${markdownj.version}</version>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>${pegdown.version}</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jbake/app/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ConfigUtil {
public static CompositeConfiguration load(File source) throws ConfigurationException {
if (config == null) {
config = new CompositeConfiguration();
config.setListDelimiter(',');
File customConfigFile = new File(source, "custom.properties");
if (customConfigFile.exists()) {
config.addConfiguration(new PropertiesConfiguration(customConfigFile));
Expand Down
71 changes: 66 additions & 5 deletions src/main/java/org/jbake/app/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import static org.asciidoctor.OptionsBuilder.options;
import static org.asciidoctor.SafeMode.UNSAFE;

import com.petebevin.markdown.MarkdownProcessor;
import org.pegdown.Extensions;

import org.pegdown.PegDownProcessor;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.io.IOUtils;
import org.asciidoctor.Asciidoctor;
Expand Down Expand Up @@ -46,15 +49,69 @@ public class Parser {
private Asciidoctor asciidoctor;
private String contentPath;
private DateFormat dateFormat;
private PegDownProcessor pegdownProcessor;

/**
* Creates a new instance of Parser.
*/
public Parser(CompositeConfiguration config, String contentPath) {
this.config = config;
dateFormat = new SimpleDateFormat(config.getString(ConfigUtil.DATE_FORMAT));
this.dateFormat = new SimpleDateFormat(config.getString(ConfigUtil.DATE_FORMAT));
this.contentPath = contentPath;
asciidoctor = Factory.create();
this.asciidoctor = Factory.create();

String[] mdExts = config.getStringArray("markdown.extensions");

if (mdExts.length > 0) {
int extensions = Extensions.NONE;

for (int index = 0; index < mdExts.length; index++) {
if (mdExts[index].equals("HARDWRAPS")) {
extensions |= Extensions.HARDWRAPS;
}
else if (mdExts[index].equals("AUTOLINKS")) {
extensions |= Extensions.AUTOLINKS;
}
else if (mdExts[index].equals("FENCED_CODE_BLOCKS")) {
extensions |= Extensions.FENCED_CODE_BLOCKS;
}
else if (mdExts[index].equals("DEFINITIONS")) {
extensions |= Extensions.DEFINITIONS;
}
else if (mdExts[index].equals("ABBREVIATIONS")) {
extensions |= Extensions.ABBREVIATIONS;
}
else if (mdExts[index].equals("QUOTES")) {
extensions |= Extensions.QUOTES;
}
else if (mdExts[index].equals("SMARTS")) {
extensions |= Extensions.SMARTS;
}
else if (mdExts[index].equals("SMARTYPANTS")) {
extensions |= Extensions.SMARTYPANTS;
}
else if (mdExts[index].equals("SUPPRESS_ALL_HTML")) {
extensions |= Extensions.SUPPRESS_ALL_HTML;
}
else if (mdExts[index].equals("SUPPRESS_HTML_BLOCKS")) {
extensions |= Extensions.SUPPRESS_HTML_BLOCKS;
}
else if (mdExts[index].equals("SUPPRESS_INLINE_HTML")) {
extensions |= Extensions.SUPPRESS_INLINE_HTML;
}
else if (mdExts[index].equals("TABLES")) {
extensions |= Extensions.TABLES;
}
else if (mdExts[index].equals("WIKILINKS")) {
extensions |= Extensions.WIKILINKS;
}
else if (mdExts[index].equals("ALL")) {
extensions = Extensions.ALL;
}
}

this.pegdownProcessor = new PegDownProcessor(extensions);
}
}

/**
Expand Down Expand Up @@ -274,8 +331,12 @@ private void processBody(List<String> contents, File file) {
}

if (file.getPath().endsWith(".md")) {
MarkdownProcessor markdown = new MarkdownProcessor();
content.put("body", markdown.markdown(body.toString()));
if (pegdownProcessor == null) {
pegdownProcessor = new PegDownProcessor();
}

String markdown = pegdownProcessor.markdownToHtml(body.toString());
content.put("body", markdown);
} else if (file.getPath().endsWith(".ad") || file.getPath().endsWith(".asciidoc") || file.getPath().endsWith(".adoc")) {
processAsciiDoc(body);
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ base.template=base.zip
# default asciidoctor options
asciidoctor.attributes=source-highlighter=prettify
# default date format used in content files
date.format=yyyy-MM-dd
date.format=yyyy-MM-dd
# comma delimited default markdown extensions; for available extensions:
# http://www.decodified.com/pegdown/api/org/pegdown/Extensions.html
markdown.extensions=HARDWRAPS,AUTOLINKS,FENCED_CODE_BLOCKS,DEFINITIONS
Loading

0 comments on commit 5a9427b

Please sign in to comment.