Package org.b3log.solo.util

Source Code of org.b3log.solo.util.Markdowns

/*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.b3log.solo.util;

import java.io.StringReader;
import java.io.StringWriter;
import org.b3log.latke.util.Strings;
import org.tautua.markdownpapers.Markdown;

/**
* <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities.
*
* <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 28, 2012
* @since 0.4.5
*/
public final class Markdowns {

    /**
     * Converts the specified markdown text to HTML.
     *
     * @param markdownText the specified markdown text
     * @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}
     * @throws Exception exception
     */
    public static String toHTML(final String markdownText) throws Exception {
        if (Strings.isEmptyOrNull(markdownText)) {
            return null;
        }

        final StringWriter writer = new StringWriter();
        final Markdown markdown = new Markdown();

        markdown.transform(new StringReader(markdownText), writer);

        return writer.toString();
    }

    /**
     * Private constructor.
     */
    private Markdowns() {
    }
}
TOP

Related Classes of org.b3log.solo.util.Markdowns

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.