Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown.extensions: Added STRIKETHROUGH, enhanced configuration of markdown.extensions: ALL,-HARDWRAPS #171

Merged
merged 2 commits into from
Feb 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 54 additions & 29 deletions src/main/java/org/jbake/parser/MarkdownEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,67 @@ public void processBody(final ParserContext context) {
int extensions = Extensions.NONE;
if (mdExts.length > 0) {
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;
String ext = mdExts[index];
if (ext.startsWith("-")) {
ext = ext.substring(1);
extensions=removeExtension(extensions, extensionFor(ext));
} else {
if (ext.startsWith("+")) {
ext = ext.substring(1);
}
extensions=addExtension(extensions, extensionFor(ext));
}
}

}

long maxParsingTime = context.getConfig().getLong("markdown.maxParsingTimeInMillis", PegDownProcessor.DEFAULT_MAX_PARSING_TIME);

PegDownProcessor pegdownProcessor = new PegDownProcessor(extensions, maxParsingTime);
context.setBody(pegdownProcessor.markdownToHtml(context.getBody()));
}

private int extensionFor(String name) {
int extension = Extensions.NONE;
if (name.equals("HARDWRAPS")) {
extension = Extensions.HARDWRAPS;
} else if (name.equals("AUTOLINKS")) {
extension = Extensions.AUTOLINKS;
} else if (name.equals("FENCED_CODE_BLOCKS")) {
extension = Extensions.FENCED_CODE_BLOCKS;
} else if (name.equals("DEFINITIONS")) {
extension = Extensions.DEFINITIONS;
} else if (name.equals("ABBREVIATIONS")) {
extension = Extensions.ABBREVIATIONS;
} else if (name.equals("QUOTES")) {
extension = Extensions.QUOTES;
} else if (name.equals("SMARTS")) {
extension = Extensions.SMARTS;
} else if (name.equals("SMARTYPANTS")) {
extension = Extensions.SMARTYPANTS;
} else if (name.equals("SUPPRESS_ALL_HTML")) {
extension = Extensions.SUPPRESS_ALL_HTML;
} else if (name.equals("SUPPRESS_HTML_BLOCKS")) {
extension = Extensions.SUPPRESS_HTML_BLOCKS;
} else if (name.equals("SUPPRESS_INLINE_HTML")) {
extension = Extensions.SUPPRESS_INLINE_HTML;
} else if (name.equals("TABLES")) {
extension = Extensions.TABLES;
} else if (name.equals("WIKILINKS")) {
extension = Extensions.WIKILINKS;
//} else if (name.equals("ANCHORLINKS")) { // not available in pegdown-1.4.2
// extension = Extensions.ANCHORLINKS;
} else if (name.equals("STRIKETHROUGH")) {
extension = Extensions.STRIKETHROUGH;
} else if (name.equals("ALL")) {
extension = Extensions.ALL;
}
return extension;
}
private int addExtension(int previousExtensions, int additionalExtension) {
return previousExtensions | additionalExtension;
}
private int removeExtension(int previousExtensions, int unwantedExtension) {
return previousExtensions & (~unwantedExtension);
}

}