001/*
002    Licensed to the Apache Software Foundation (ASF) under one
003    or more contributor license agreements.  See the NOTICE file
004    distributed with this work for additional information
005    regarding copyright ownership.  The ASF licenses this file
006    to you under the Apache License, Version 2.0 (the
007    "License"); you may not use this file except in compliance
008    with the License.  You may obtain a copy of the License at
009
010       http://www.apache.org/licenses/LICENSE-2.0
011
012    Unless required by applicable law or agreed to in writing,
013    software distributed under the License is distributed on an
014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015    KIND, either express or implied.  See the License for the
016    specific language governing permissions and limitations
017    under the License.
018 */
019package org.apache.wiki.markdown;
020
021import com.vladsch.flexmark.html.HtmlRenderer;
022import com.vladsch.flexmark.parser.Parser;
023import com.vladsch.flexmark.util.data.MutableDataHolder;
024import org.apache.oro.text.regex.Pattern;
025import org.apache.wiki.api.core.Context;
026import org.apache.wiki.markdown.extensions.jspwikilinks.attributeprovider.JSPWikiLinkAttributeProviderFactory;
027import org.apache.wiki.markdown.extensions.jspwikilinks.postprocessor.JSPWikiNodePostProcessorFactory;
028import org.apache.wiki.markdown.renderer.JSPWikiNodeRendererFactory;
029
030import java.util.List;
031
032
033/**
034 * Flexmark entry point to bootstrap JSPWiki extensions.
035 */
036public class MarkdownForJSPWikiExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension {
037
038    private final Context context;
039    private final boolean isImageInlining;
040    private final List< Pattern > inlineImagePatterns;
041
042    public MarkdownForJSPWikiExtension( final Context context,
043                                        final boolean isImageInlining,
044                                        final List< Pattern > inlineImagePatterns ) {
045        this.context = context;
046        this.isImageInlining = isImageInlining;
047        this.inlineImagePatterns = inlineImagePatterns;
048    }
049
050    /**
051     * {@inheritDoc}
052     */
053    @Override
054    public void rendererOptions( final MutableDataHolder options ) {
055    }
056
057    /**
058     * {@inheritDoc}
059     */
060    @Override
061    public void parserOptions( final MutableDataHolder options ) {
062    }
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public void extend( final HtmlRenderer.Builder rendererBuilder, final String rendererType ) {
069        rendererBuilder.nodeRendererFactory( new JSPWikiNodeRendererFactory( context ) );
070        rendererBuilder.attributeProviderFactory( new JSPWikiLinkAttributeProviderFactory( context, isImageInlining, inlineImagePatterns ) );
071    }
072
073    /**
074     * {@inheritDoc}
075     */
076    @Override
077    public void extend( final Parser.Builder parserBuilder ) {
078        parserBuilder.postProcessorFactory( new JSPWikiNodePostProcessorFactory( context, parserBuilder, isImageInlining, inlineImagePatterns ) );
079    }
080
081}