/*
* Copyright 2011 OverZealous Creations, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.atecher.mintools.markdown.remark.option;
import com.atecher.mintools.markdown.remark.IgnoredHtmlElement;
import java.util.HashSet;
import java.util.Set;
/**
* This class is used to configure the Remark engine.
* <p>
* Standard profiles have been created for a variety of Markdown processors, including:
* <ul>
* <li>{@link #markdown() Standard Markdown}</li>
* <li>{@link #markdownExtra() PHP Markdown Extra}</li>
* <li>{@link #multiMarkdown() MultiMarkdown}</li>
* <li>{@link #pegdownBase() pegdown basic}</li>
* <li>{@link #pegdownAllExtensions() pegdown with all extensions}</li>
* <li>{@link #github() Github Flavored Markdown}</li>
* </ul>
*
* @author Phil DeJarnett
*/
public class Options implements Cloneable {
/**
* Provides settings to control how Tables are converted.
*/
public enum Tables {
/**
* Remove all tables and their contents
*/
REMOVE(true, false, false, false, false),
/**
* Leave all tables and their contents as raw HTML (the default, as
* this is the recommended syntax from Markdown)
*/
LEAVE_AS_HTML(false, true, false, false, false),
/**
* Convert tables to clean code block (compatible with the original Markdown)
*/
CONVERT_TO_CODE_BLOCK(false, false, true, true, true),
/**
* Convert tables to the syntax used by PHP Markdown Extra.
*
* @see <a href="http://michelf.com/projects/php-markdown/extra/#table">PHP Markdown Extra Tables</a>
*/
MARKDOWN_EXTRA(false, false, true, false, false),
/**
* Convert tables to the syntax used by MultiMarkdown.
*
* @see <a href="http://fletcher.github.com/peg-multimarkdown/#tables">MultiMarkdown Tables</a>
*/
MULTI_MARKDOWN(false, false, true, false, true);
/**
* Private fields
*/
private final boolean removed;
private final boolean leftAsHtml;
private final boolean convertedToText;
private final boolean renderedAsCode;
private final boolean colspanEnabled;
Tables(boolean removed, boolean leftAsHtml, boolean convertedToText, boolean renderedAsCode, boolean colspanEnabled) {
this.removed = removed;
this.leftAsHtml = leftAsHtml;
this.convertedToText = convertedToText;
this.renderedAsCode = renderedAsCode;
this.colspanEnabled = colspanEnabled;
}
/**
* True if the table is to be fully removed.
*
* @return true or false
*/
public boolean isRemoved() {
return removed;
}
/**
* True if the table is to be left as raw HTML.
*
* @return true or false
*/
public boolean isLeftAsHtml() {
return leftAsHtml;
}
/**
* True if the table is to be converted to plain text.
* This is true if the result is a Markdown table or a code block.
*
* @return true or false
*/
public boolean isConvertedToText() {
return convertedToText;
}
/**
* True if the table should be rendered as a code block
*
* @return true or false
*/
public boolean isRenderedAsCode() {
return renderedAsCode;
}
/**
* True if the table is rendered as a MultiMarkdown table with column spanning.
*
* @return true or false
*/
public boolean isColspanEnabled() {
return colspanEnabled;
}
}
/**
* Provides settings to configure if fenced code blocks are used.
*/
public enum FencedCodeBlocks {
/**
* Completely disables fenced code blocks.
*/
DISABLED(false, ' '),
/**
* Enables fenced code blocks, using multiple {@code '~'} as the separator characters.
*/
ENABLED_TILDE(true, '~'),
/**
* Enables fenced code blocks, using multiple {@code '`'} as the separator characters.
*/
ENABLED_BACKTICK(true, '`');
private final boolean enabled;
private final char separatorCharacter;
FencedCodeBlocks(boolean enabled, char separatorCharacter) {
this.enabled = enabled;
this.separatorCharacter = separatorCharacter;
}
/**
* True if fenced code blocks are enabled
*
* @return true or false
*/
public boolean isEnabled() {
return enabled;
}
/**
* Returns the separator character to use.
*
* @return the separator character
*/
public char getSeparatorCharacter() {
return separatorCharacter;
}
}
/**
* Provides options for how to handle in-word emphasis.
*/
public enum InWordEmphasis {
/**
* Uses the default mode, which allows in-word emphasis. Because Remark only uses
* asterisks for spacing ({@code '*'}), this mode works with parsers that disable
* in-word underscores ({@code '_'}) but not in-word asterisks.
*/
NORMAL(true, false),
/**
* Adds spaces around the in-word emphasis characters. This will actually render different output.
* <p>
* For example, {@code My<em>Example</em>Word} becomes {@code My *Example* Word}. This will actually
* render as {@code My <em>Example</em> Word}.
*/
ADD_SPACES(true, true),
/**
* Removes in-word emphasis altogether. Designed for parsers that do not allow in-word asterisks
* or in-word underscores.
* <p>
* This means that {@code My<em>Example</em>Word} becomes {@code MyExampleWord}.
*/
REMOVE_EMPHASIS(false, false);
private final boolean emphasisPreserved;
private final boolean additionalSpacingNeeded;
InWordEmphasis(boolean emphasisPreserved, boolean additionalSpacingNeeded) {
this.emphasisPreserved = emphasisPreserved;
this.additionalSpacingNeeded = additionalSpacingNeeded;
}
/**
* Returns whether or not to preserve emphasis at all.
*
* @return true if emphasis should be preserved, false to remove it altogether.
*/
public boolean isEmphasisPreserved() {
return emphasisPreserved;
}
/**
* Returns true when Remark should add spaces around the emphasis characters.
*
* @return true if spaces should be added.
*/
public boolean isAdditionalSpacingNeeded() {
return additionalSpacingNeeded;
}
}
/**
* Creates and returns a new Options set with the default options
* compatible with the original Markdown.
*
* @return Options for original Markdown compatibility
*/
public static Options markdown() {
return new Options();
}
/**
* Creates and returns a new Options set with the default options
* compatible with PHP Markdown Extra features.
*
* <p>Enables:</p>
* <ul>
* <li>headerIDs</li>
* <li>Markdown Extra f