001/* 002 * JDrupes MDoclet 003 * Copyright 2013 Raffael Herzog 004 * Copyright (C) 2017 Michael N. Lipp 005 * 006 * This program is free software; you can redistribute it and/or modify it 007 * under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, but 012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 013 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 014 * for more details. 015 * 016 * You should have received a copy of the GNU General Public License along 017 * with this program; if not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.jdrupes.mdoclet.renderers; 020 021import static org.jdrupes.mdoclet.renderers.TagRendering.simplifySingleParagraph; 022 023import java.util.regex.Matcher; 024import java.util.regex.Pattern; 025 026import org.jdrupes.mdoclet.MDoclet; 027 028import com.sun.javadoc.SeeTag; 029 030 031/** 032 * Renderer for `@see` tags. 033 */ 034public class SeeTagRenderer implements TagRenderer<SeeTag> { 035 036 public static final SeeTagRenderer INSTANCE = new SeeTagRenderer(); 037 038 private static final Pattern SIMPLE_LINK 039 = Pattern.compile("(?<label>[^<]*)<(?<url>[^>]+)>"); 040 041 @Override 042 public void render(SeeTag tag, StringBuilder target, MDoclet doclet) { 043 if ( tag.text().startsWith("\"") && tag.text().endsWith("\"") 044 && tag.text().length() > 1 ) { 045 String text = tag.text().substring(1, tag.text().length() - 1).trim(); 046 Matcher matcher = SIMPLE_LINK.matcher(text); 047 if (matcher.matches()) { 048 String label = matcher.group("label"); 049 if ( label == null || label.isEmpty()) { 050 label = matcher.group("url"); 051 } else { 052 label = label.trim(); 053 } 054 text = "[" + label + "](" + matcher.group("url") + ")"; 055 } 056 target.append(tag.name()).append(" ") 057 .append(simplifySingleParagraph(doclet.toHtml(text))); 058 return; 059 } 060 VERBATIM.render(tag, target, doclet); 061 } 062}