All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladsch.flexmark.ext.typographic.TypographicExtension Maven / Gradle / Ivy

There is a newer version: 0.64.8
Show newest version
package com.vladsch.flexmark.ext.typographic;

import com.vladsch.flexmark.ext.typographic.internal.*;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.util.data.DataKey;
import com.vladsch.flexmark.util.data.MutableDataHolder;
import com.vladsch.flexmark.util.data.NullableDataKey;
import org.jetbrains.annotations.NotNull;

/**
 * Extension for typographics
 * 

* Create it with {@link #create()} and then configure it on the builders *

* The parsed typographic text is turned into {@link TypographicQuotes} and {@link TypographicSmarts} nodes. */ public class TypographicExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension { final public static DataKey ENABLE_QUOTES = new DataKey<>("ENABLE_QUOTES", true); final public static DataKey ENABLE_SMARTS = new DataKey<>("ENABLE_SMARTS", true); final public static DataKey ANGLE_QUOTE_CLOSE = new DataKey<>("ANGLE_QUOTE_CLOSE", "»"); final public static DataKey ANGLE_QUOTE_OPEN = new DataKey<>("ANGLE_QUOTE_OPEN", "«"); final public static NullableDataKey ANGLE_QUOTE_UNMATCHED = new NullableDataKey<>("ANGLE_QUOTE_UNMATCHED"); final public static DataKey DOUBLE_QUOTE_CLOSE = new DataKey<>("DOUBLE_QUOTE_CLOSE", "”"); final public static DataKey DOUBLE_QUOTE_OPEN = new DataKey<>("DOUBLE_QUOTE_OPEN", "“"); final public static NullableDataKey DOUBLE_QUOTE_UNMATCHED = new NullableDataKey<>("DOUBLE_QUOTE_UNMATCHED"); final public static DataKey ELLIPSIS = new DataKey<>("ELLIPSIS", "…"); final public static DataKey ELLIPSIS_SPACED = new DataKey<>("ELLIPSIS_SPACED", "…"); final public static DataKey EM_DASH = new DataKey<>("EM_DASH", "—"); final public static DataKey EN_DASH = new DataKey<>("EN_DASH", "–"); final public static DataKey SINGLE_QUOTE_CLOSE = new DataKey<>("SINGLE_QUOTE_CLOSE", "’"); final public static DataKey SINGLE_QUOTE_OPEN = new DataKey<>("SINGLE_QUOTE_OPEN", "‘"); final public static DataKey SINGLE_QUOTE_UNMATCHED = new DataKey<>("SINGLE_QUOTE_UNMATCHED", "’"); private TypographicExtension() { } public static TypographicExtension create() { return new TypographicExtension(); } @Override public void rendererOptions(@NotNull MutableDataHolder options) { } @Override public void parserOptions(MutableDataHolder options) { } @Override public void extend(Parser.Builder parserBuilder) { if (ENABLE_QUOTES.get(parserBuilder)) { TypographicOptions options = new TypographicOptions(parserBuilder); parserBuilder.customDelimiterProcessor(new AngleQuoteDelimiterProcessor(options)); parserBuilder.customDelimiterProcessor(new SingleQuoteDelimiterProcessor(options)); parserBuilder.customDelimiterProcessor(new DoubleQuoteDelimiterProcessor(options)); } if (ENABLE_SMARTS.get(parserBuilder)) { parserBuilder.customInlineParserExtensionFactory(new SmartsInlineParser.Factory()); } } @Override public void extend(@NotNull HtmlRenderer.Builder htmlRendererBuilder, @NotNull String rendererType) { if (htmlRendererBuilder.isRendererType("HTML") || htmlRendererBuilder.isRendererType("JIRA")) { htmlRendererBuilder.nodeRendererFactory(new TypographicNodeRenderer.Factory()); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy