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.parser.markdown;
020
021import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
022import com.vladsch.flexmark.ext.toc.TocExtension;
023import com.vladsch.flexmark.parser.Parser;
024import com.vladsch.flexmark.parser.ParserEmulationProfile;
025import com.vladsch.flexmark.util.ast.Node;
026import com.vladsch.flexmark.util.builder.Extension;
027import com.vladsch.flexmark.util.data.MutableDataSet;
028import org.apache.wiki.WikiContext;
029import org.apache.wiki.WikiPage;
030import org.apache.wiki.markdown.MarkdownForJSPWikiExtension;
031import org.apache.wiki.parser.JSPWikiMarkupParser;
032import org.apache.wiki.parser.WikiDocument;
033
034import java.util.Arrays;
035
036
037/**
038 * Simple placeholder for Markdown Nodes
039 */
040public class MarkdownDocument extends WikiDocument {
041
042    private static final long serialVersionUID = 1L;
043
044    private final Node md;
045
046    public MarkdownDocument( final WikiPage page, final Node md ) {
047        super( page );
048        this.md = md;
049    }
050
051    public Node getMarkdownNode() {
052        return md;
053    }
054
055    /**
056     * configuration options for MarkdownRenderers.
057     *
058     * @param context current wikicontext
059     * @return configuration options for MarkdownRenderers.
060     */
061    public static MutableDataSet options( final WikiContext context ) {
062        MutableDataSet options = new MutableDataSet();
063        options.setFrom( ParserEmulationProfile.COMMONMARK );
064        // align style of Markdown's footnotes extension with jspwiki footnotes refs
065        options.set( FootnoteExtension.FOOTNOTE_LINK_REF_CLASS, JSPWikiMarkupParser.CLASS_FOOTNOTE_REF );
066        options.set( Parser.EXTENSIONS, Arrays.asList( new Extension[] { new MarkdownForJSPWikiExtension( context ),
067                                                                         FootnoteExtension.create(),
068                                                                         TocExtension.create() } ) );
069        return options;
070    }
071
072}