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

org.jdrupes.mdoclet.MDoclet Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
/*
 * JDrupes MDoclet
 * Copyright (C) 2021 Michael N. Lipp
 * 
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Affero General Public License as published by 
 * the Free Software Foundation; either version 3 of the License, or 
 * (at your option) any later version.
 *
 * This program 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 Affero General Public License 
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along 
 * with this program; if not, see .
 */

package org.jdrupes.mdoclet;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;

import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic;
import javax.tools.DocumentationTool.Location;
import javax.tools.JavaFileManager;

import org.jdrupes.mdoclet.internal.doclets.formats.html.HtmlDoclet;
import org.jdrupes.mdoclet.processors.FlexmarkProcessor;

import com.sun.source.doctree.DocCommentTree;

import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;

/**
 * The Doclet implementation, which converts the Markdown from the JavaDoc 
 * comments and tags to HTML.
 * 
 * The doclet works by installing wrappers to intercept the 
 * {@link HtmlDoclet}'s calls to access the {@link DocCommentTree}s 
 * (see {@link DocCommentTreeWrapper}). At the root of this interception
 * is a modified doclet environment ({@link MDocletEnvironment}) that 
 * installs a wrapper around doc trees access.
 * 
 * For some strange reason, the `StandardDoclet` does not work
 * with interface {@link DocletEnvironment} but insists on the instance
 * being a `DocEnvImpl`. Therefore {@link MDocletEnvironment} has
 * to extend this class which requires to allow module access with
 * `--add-exports=jdk.javadoc/org.jdrupes.mdoclet.internal.tool=ALL-UNNAMED`.
 */
public class MDoclet implements Doclet {

    public static final String HIGHLIGHT_JS_HTML
        = "\n"
            + "";

    private Reporter reporter;
    private JavaFileManager fileManager;

    private String markdownProcessorName = FlexmarkProcessor.class.getName();
    private MarkdownProcessor processor;
    private List processorOptions = new ArrayList<>();
    private Option origHeaderOpt;
    private String bufferedHeader = "";
    private Option allowScriptsOpt;
    private boolean disableHighlight;
    private boolean disableAutoHighlight;
    private String highlightStyle = "default";

    private final HtmlDoclet htmlDoclet;

    public MDoclet() {
        htmlDoclet = new HtmlDoclet(this);
    }

    @Override
    public void init(Locale locale, Reporter reporter) {
        this.reporter = reporter;
        htmlDoclet.init(locale, reporter);
    }

    @Override
    public String getName() {
        return getClass().getSimpleName();
    }

    @Override
    public Set getSupportedOptions() {
        Set




© 2015 - 2025 Weber Informatics LLC | Privacy Policy