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