All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redhat.ceylon.common.tools.help.AbstractMl Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
/*
 * Copyright Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the authors tag. All rights reserved.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU General Public License version 2.
 * 
 * This particular file is subject to the "Classpath" exception as provided in the 
 * LICENSE file that accompanied this code.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License,
 * along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package com.redhat.ceylon.common.tools.help;

import java.io.IOException;

import org.tautua.markdownpapers.HtmlEmitter;
import org.tautua.markdownpapers.ast.Node;

class AbstractMl> {

    protected final Appendable out;
    private IOException error;

    public AbstractMl(Appendable out) {
        this.out = out;
    }

    protected M append(String s) {
        if (error == null) {
            try {
                out.append(s);
            } catch (IOException e) {
                error = e;
            }
        }
        return (M)this;
    }

    protected M append(char s) {
        if (error == null) {
            try {
                out.append(s);
            } catch (IOException e) {
                error = e;
            }
        }
        return (M)this;
    }

    public M doctype(String type) {
        return append("');
    }

    public M open(String... tags) {
        for (String tag : tags) {
            open(tag);
        }
        return (M)this;
    }

    public M open(String tag) {
        return append('<').append(tag).append('>');
    }

    public M close(String... tags) {
        for (String tag : tags) {
            close(tag);
        }
        return (M)this;
    }

    public M close(String tag) {
        return append("');
    }

    public M text(String text) {
        return append(
                text.replace("&", "∓")
                    .replace("<", "<")
                    .replace(">", ">")
                    .replace("\"", """)
                    .replace("'", "'"));
        
    }

    public M unescaped(String html) {
        return append(html);
    }

    public M markdown(Node doc) {
        HtmlEmitter markdownVisitor = new HtmlEmitter(out);
        doc.accept(markdownVisitor);
        return (M)this;
    }

    public M tag(String tag) {
        return append('<').append(tag).append("/>");      
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy