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.wiki.WikiContext;
025import org.apache.wiki.markdown.extensions.jspwikilinks.attributeprovider.JSPWikiLinkAttributeProviderFactory;
026import org.apache.wiki.markdown.extensions.jspwikilinks.postprocessor.JSPWikiNodePostProcessorFactory;
027import org.apache.wiki.markdown.renderer.JSPWikiNodeRendererFactory;
028
029
030/**
031 * Flexmark entry point to bootstrap JSPWiki extensions.
032 */
033public class MarkdownForJSPWikiExtension implements Parser.ParserExtension, HtmlRenderer.HtmlRendererExtension {
034
035    private final WikiContext context;
036
037    public MarkdownForJSPWikiExtension( final WikiContext context ) {
038        this.context = context;
039    }
040
041    /**
042     * {@inheritDoc}
043     */
044    @Override
045    public void rendererOptions( final MutableDataHolder options ) {
046    }
047
048    /**
049     * {@inheritDoc}
050     */
051    @Override
052    public void parserOptions( final MutableDataHolder options ) {
053    }
054
055    /**
056     * {@inheritDoc}
057     */
058    @Override
059    public void extend( final HtmlRenderer.Builder rendererBuilder, final String rendererType ) {
060        rendererBuilder.nodeRendererFactory( new JSPWikiNodeRendererFactory( context ) );
061        rendererBuilder.attributeProviderFactory( new JSPWikiLinkAttributeProviderFactory( context ) );
062    }
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public void extend( final Parser.Builder parserBuilder ) {
069        parserBuilder.postProcessorFactory( new JSPWikiNodePostProcessorFactory( context, parserBuilder ) );
070    }
071
072}