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

ch.raffael.doclets.pegdown.DocletLinkRenderer Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
/*
 * Copyright 2013 Raffael Herzog
 *
 * This file is part of pegdown-doclet.
 *
 * pegdown-doclet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * pegdown-doclet is distributed in the hope that it will be useful,
 * but WITHOUT ANY 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 pegdown-doclet.  If not, see .
 */
package ch.raffael.doclets.pegdown;

import com.google.common.base.CharMatcher;
import org.pegdown.LinkRenderer;
import org.pegdown.ast.WikiLinkNode;


/**
 * The default link renderer for this doclet. It overrides the rendering of Wiki-Style
 * links to support the following scheme:
 *
 * * `[[http://www.example.com/]]` is rendered as
 *   `www.example.com`
 *
 * * `[[http://www.example.com/ Example]]` is rendered as
 *   `Example`
 *
 * All other links will be rendered by Pegdown's default renderer.
 *
 * @author Raffael Herzog
 */
public class DocletLinkRenderer extends LinkRenderer {

    @Override
    public Rendering render(WikiLinkNode node) {
        String url = node.getText().trim();
        int pos = CharMatcher.WHITESPACE.indexIn(url);
        String text = url;
        if ( pos >= 0 ) {
            text = url.substring(pos).trim();
            url = url.substring(0, pos);
        }
        return new Rendering(url, text);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy