org.magicwerk.brownies.html.HtmlHeading Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2010 by Thomas Mauch
*
* 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.
*
* $Id: HtmlDiv.java 3298 2016-09-26 23:42:02Z origo $
*/
package org.magicwerk.brownies.html;
import org.jdom2.Element;
import org.magicwerk.brownies.core.TypeTools;
/**
* A HTML heading element, e.g. {@literal , } etc.
*
* @author Thomas Mauch
* @version $Id: HtmlDiv.java 3298 2016-09-26 23:42:02Z origo $
*/
public class HtmlHeading extends HtmlInline {
/**
* Constructor.
*/
public HtmlHeading(int level) {
super(new Element(getHeadingTag(level)));
}
public HtmlHeading(int level, String text) {
this(level);
addText(text);
}
//
public static String getHeadingTag(int level) {
return "h" + level;
}
/**
* Returns level of heading.
*
* @param name element name (e.g. "h1")
* @return level of heading, -1 if this is not a heading
*/
public static int getHeadingLevel(String name) {
if (name.startsWith("h")) {
Integer level = TypeTools.parseIntIf(name.substring(1));
if (level != null) {
return level;
}
}
return -1;
}
}