com.vladsch.flexmark.ext.typographic.TypographicExtension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flexmark-ext-typographic Show documentation
Show all versions of flexmark-ext-typographic Show documentation
flexmark-java extension for typographic
package com.vladsch.flexmark.ext.typographic;
import com.vladsch.flexmark.Extension;
import com.vladsch.flexmark.ext.typographic.internal.*;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.options.DataKey;
import com.vladsch.flexmark.util.options.MutableDataHolder;
/**
* Extension for typographics
*
* Create it with {@link #create()} and then configure it on the builders
* ({@link com.vladsch.flexmark.parser.Parser.Builder#extensions(Iterable)},
* {@link com.vladsch.flexmark.html.HtmlRenderer.Builder#extensions(Iterable)}).
*
*
* The parsed typographic text is turned into {@link TypographicQuotes} and {@link TypographicSmarts} nodes.
*
*/
public class TypographicExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension {
public static final DataKey ENABLE_QUOTES = new DataKey<>("ENABLE_QUOTES", true);
public static final DataKey ENABLE_SMARTS = new DataKey<>("ENABLE_SMARTS", true);
/**
* @deprecated use {@link #ENABLE_QUOTES}
*/
public static final DataKey TYPOGRAPHIC_QUOTES = ENABLE_QUOTES;
/**
* @deprecated use {@link #ENABLE_SMARTS}
*/
public static final DataKey TYPOGRAPHIC_SMARTS = ENABLE_SMARTS;
public static final DataKey ANGLE_QUOTE_CLOSE = new DataKey<>("ANGLE_QUOTE_CLOSE", "»");
public static final DataKey ANGLE_QUOTE_OPEN = new DataKey<>("ANGLE_QUOTE_OPEN", "«");
public static final DataKey ANGLE_QUOTE_UNMATCHED = new DataKey<>("ANGLE_QUOTE_UNMATCHED", (String) null);
public static final DataKey DOUBLE_QUOTE_CLOSE = new DataKey<>("DOUBLE_QUOTE_CLOSE", "”");
public static final DataKey DOUBLE_QUOTE_OPEN = new DataKey<>("DOUBLE_QUOTE_OPEN", "“");
public static final DataKey DOUBLE_QUOTE_UNMATCHED = new DataKey<>("DOUBLE_QUOTE_UNMATCHED", (String) null);
public static final DataKey ELLIPSIS = new DataKey<>("ELLIPSIS", "…");
public static final DataKey ELLIPSIS_SPACED = new DataKey<>("ELLIPSIS_SPACED", "…");
public static final DataKey EM_DASH = new DataKey<>("EM_DASH", "—");
public static final DataKey EN_DASH = new DataKey<>("EN_DASH", "–");
public static final DataKey SINGLE_QUOTE_CLOSE = new DataKey<>("SINGLE_QUOTE_CLOSE", "’");
public static final DataKey SINGLE_QUOTE_OPEN = new DataKey<>("SINGLE_QUOTE_OPEN", "‘");
public static final DataKey SINGLE_QUOTE_UNMATCHED = new DataKey<>("SINGLE_QUOTE_UNMATCHED", "’");
private TypographicExtension() {
}
public static Extension create() {
return new TypographicExtension();
}
@Override
public void rendererOptions(final MutableDataHolder options) {
}
@Override
public void parserOptions(final MutableDataHolder options) {
}
@Override
public void extend(Parser.Builder parserBuilder) {
if (ENABLE_QUOTES.getFrom(parserBuilder)) {
TypographicOptions options = new TypographicOptions(parserBuilder);
parserBuilder.customDelimiterProcessor(new AngleQuoteDelimiterProcessor(options));
parserBuilder.customDelimiterProcessor(new SingleQuoteDelimiterProcessor(options));
parserBuilder.customDelimiterProcessor(new DoubleQuoteDelimiterProcessor(options));
}
if (ENABLE_SMARTS.getFrom(parserBuilder)) parserBuilder.customInlineParserExtensionFactory(new SmartsInlineParser.Factory());
}
@Override
public void extend(HtmlRenderer.Builder rendererBuilder, String rendererType) {
switch (rendererType) {
case "HTML":
case "JIRA":
case "YOUTRACK":
rendererBuilder.nodeRendererFactory(new TypographicNodeRenderer.Factory());
break;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy