    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.htmltowiki.syntax.markdown;
    020
    021import org.apache.wiki.htmltowiki.WhitespaceTrimWriter;
    022import org.apache.wiki.htmltowiki.XHtmlElementToWikiTranslator;
    023import org.apache.wiki.htmltowiki.XHtmlToWikiConfig;
    024import org.apache.wiki.htmltowiki.syntax.OptionDecorator;
    025import org.apache.wiki.htmltowiki.syntax.PlainTextDecorator;
    026import org.apache.wiki.htmltowiki.syntax.TableDecorator;
    027import org.apache.wiki.htmltowiki.syntax.TbodyDecorator;
    028import org.apache.wiki.htmltowiki.syntax.TextElementDecorator;
    029import org.apache.wiki.htmltowiki.syntax.TrDecorator;
    030import org.apache.wiki.htmltowiki.syntax.WikiSyntaxDecorator;
    031
    032import java.io.PrintWriter;
    033import java.util.Deque;
    034
    035
    036/**
    037 * Markdown wiki syntax decorator which translates to wiki syntax. Delegates each kind of XHTML element to its specific decorator.
    038 */
    039public class MarkdownSyntaxDecorator extends WikiSyntaxDecorator {
    040
    041    /** {@inheritDoc} */
    042    @Override
    043    public void init( final PrintWriter out,
    044                      final Deque< String > liStack,
    045                      final Deque< String > preStack,
    046                      final WhitespaceTrimWriter outTrimmer,
    047                      final XHtmlToWikiConfig config,
    048                      final XHtmlElementToWikiTranslator chain ) {
    049        this.config = config;
    050        this.outTrimmer = outTrimmer;
    051        this.chain = chain;
    052
    053        this.cssStyle = new MarkdownPlainTextCssSpecialDecorator( out, chain );
    054        this.pre = new MarkdownPlainTextMonospaceDecorator( cssStyle, out, preStack, chain );
    055        this.em = new MarkdownPlainTextItalicDecorator( pre, out, chain );
    056        this.strong = new MarkdownPlainTextBoldDecorator( em, out, chain );
    057        this.css = new MarkdownPlainTextCssDecorator( strong, out, chain );
    058        this.plainText = new PlainTextDecorator( css, out, chain );
    059
    060        this.a = new MarkdownADecorator( out, config, chain );
    061        this.br = new MarkdownBrDecorator( out, preStack, chain );
    062        this.code = new MarkdownCodeDecorator( out, preStack, chain );
    063        this.dd = new MarkdownDdDecorator( out, chain );
    064        this.dl = new MarkdownDlDecorator( out, chain );
    065        this.dt = new MarkdownDtDecorator( out, chain );
    066        this.form = new MarkdownFormDecorator( out, chain );
    067        this.hr = new MarkdownHrDecorator( out, chain );
    068        this.h1 = new MarkdownH1Decorator( out, chain );
    069        this.h2 = new MarkdownH2Decorator( out, chain );
    070        this.h3 = new MarkdownH3Decorator( out, chain );
    071        this.h4 = new MarkdownH4Decorator( out, chain );
    072        this.img = new MarkdownImageDecorator( out, config );
    073        this.input = new MarkdownInputDecorator( out, chain );
    074        this.li = new MarkdownLiDecorator( out, liStack, chain );
    075        this.ol = new MarkdownOlDecorator( out, liStack, chain );
    076        this.option = new OptionDecorator( out, chain );
    077        this.p = new MarkdownPDecorator( out, chain );
    078        this.table = new TableDecorator( out, outTrimmer, chain );
    079        this.tbody = new TbodyDecorator( out, chain );
    080        this.td = new MarkdownTdDecorator( out, preStack, chain );
    081        this.th = new MarkdownThDecorator( out, preStack, chain );
    082        this.thead = new MarkdownTheadDecorator( out, chain );
    083        this.tr = new TrDecorator( out, chain );
    084        this.textarea = new MarkdownTextAreaDecorator( out, chain );
    085        this.textElement = new TextElementDecorator( out, preStack );
    086        this.select = new MarkdownSelectDecorator( out, chain );
    087        this.strike = new MarkdownStrikeDecorator( out, chain );
    088        this.sub = new MarkdownSubDecorator( out, chain );
    089        this.sup = new MarkdownSupDecorator( out, chain );
    090        this.ul = new MarkdownUlDecorator( out, liStack, chain );
    091        this.underline = new MarkdownUnderlineDecorator( out, chain );
    092    }
    093
    094}