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

com.overzealous.remark.convert.Division Maven / Gradle / Ivy

Go to download

markdown generator from html updated but based on original Apache 2.0 licensed code from https://bitbucket.org/OverZealous/remark/src/default/

There is a newer version: 2.0.18
Show newest version
/**
 * (c) Copyright 2019-2020 IBM Corporation
 * 1 New Orchard Road, 
 * Armonk, New York, 10504-1722
 * United States
 * +1 914 499 1900
 * support: Nathaniel Mills [email protected]
 *
 * 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 com.overzealous.remark.convert;

import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.select.Elements;
import com.overzealous.remark.util.BlockWriter;

/**
 * Handles input (input) tags.
 * 
 * @author Nathaniel Mills
 */
public class Division extends AbstractNodeHandler {

    /**
     * Allows for div tags to be filtered.
     *
     * @param parent
     *            The previous node walker, in case we just want to remove an
     *            element.
     * @param node
     *            Node to handle
     * @param converter
     *            Parent converter for this object.
     * @param pw
     *            Annotation Writer to receive annotations mapping generated
     *            markdown to document element(s)
     * @param baseUri
     *            the base URI needed to flesh out partial (local) image or href
     *            URL references
     * @param domain
     *            the domain from the baseUri used to find domain specific
     *            filtering rules
     * @param level
     * @param searchLevel
     * @return the Node where level matches searchLevel, otherwise, returns null
     */
    public Node handleNode(NodeHandler parent, Element node,
        DocumentConverter converter, ProvenanceWriter pw, String baseUri,
        String domain, String level, String searchLevel) {
        BlockWriter out = converter.output;
        boolean hasRole = false;
        String strAttributes = "";
        if (node.hasAttr("role") && node.attr("role").trim().length() > 0) {
            hasRole = true;
            Elements elts = node.getElementsByTag(node.tagName());
            // elts[0] is the article tag (others are children)
            Attributes attrs = elts.get(0).attributes();
            for (Attribute attr : attrs) {
                strAttributes += attr.toString() + " ";
            }
            String md = "";
            if (strAttributes.length() > 0) {
                md = "";
            } else {
                md =  "";
            }
            saveAnnotation(pw, level, node, md);
            out = converter.output;
            if (converter.options.tables.includeComments()) {
                out.startBlock();
                out.print(md);
                out.println();
            }
        }
        Node result = converter.walkNodes(parent, node, pw, baseUri, domain,
            level, searchLevel);
        if (hasRole) {
            String md = "";
            saveAnnotation(pw, level, node, md);
            if (converter.options.tables.includeComments()) {
                out.print(md);
                out.println();
                out.endBlock();
            }
        }
        return result;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy