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