Package org.jsoup.parser
Class TagSet
java.lang.Object
org.jsoup.parser.TagSet
A TagSet controls the
Tag configuration for a Document's parse, and its serialization. It contains the initial
defaults, and after the parse, any additionally discovered tags.- Since:
- 1.20.1
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInsert a tag into this TagSet.copyCustomizers(TagSet base) private voidAdds the tag, but does not set defined.booleanGet an existing Tag from this TagSet by tagName and namespace.inthashCode()static TagSetHtml()Returns a mutable copy of the default HTML tag set.(package private) static TagSetInitialize the default HTML tag set.Register a callback to customize eachTagas it's added to this TagSet.private TagSetGet a Tag by name from this TagSet.(package private) TagTag.valueOf with the normalName via the token.normalName, to save redundant lower-casing passes.valueOf(String tagName, String namespace, ParseSettings settings) Get a Tag by name from this TagSet.
-
Field Details
-
HtmlTagSet
-
tags
-
source
-
customizers
-
-
Constructor Details
-
TagSet
-
TagSet
public TagSet() -
TagSet
Creates a new TagSet by copying the current tags and customizers from the provided source TagSet. Changes made to one TagSet will not affect the other.- Parameters:
template- the TagSet to copy
-
-
Method Details
-
Html
Returns a mutable copy of the default HTML tag set. -
copyCustomizers
-
add
Insert a tag into this TagSet. If the tag already exists, it is replaced.Tags explicitly added like this are considered to be known tags (vs those that are dynamically created via .valueOf() if not already in the set.
- Parameters:
tag- the tag to add- Returns:
- this TagSet
-
doAdd
Adds the tag, but does not set defined. Used in .valueOf -
get
Get an existing Tag from this TagSet by tagName and namespace. The tag name is not normalized, to support mixed instances.- Parameters:
tagName- the case-sensitive tag namenamespace- the namespace- Returns:
- the tag, or null if not found
-
valueOf
Tag.valueOf with the normalName via the token.normalName, to save redundant lower-casing passes. Provide a null normalName unless we already have one; will be normalized if required from tagName. -
valueOf
Get a Tag by name from this TagSet. If not previously defined (unknown), returns a new tag.New tags will be added to this TagSet.
- Parameters:
tagName- Name of tag, e.g. "p".namespace- the namespace for the tag.settings- used to control tag name sensitivity- Returns:
- The tag, either defined or new generic.
-
valueOf
Get a Tag by name from this TagSet. If not previously defined (unknown), returns a new tag.New tags will be added to this TagSet.
- Parameters:
tagName- Name of tag, e.g. "p". Case-sensitive.namespace- the namespace for the tag.- Returns:
- The tag, either defined or new generic.
- See Also:
-
onNewTag
Register a callback to customize eachTagas it's added to this TagSet.Customizers are invoked once per Tag, when they are added (explicitly or via the valueOf methods).
For example, to allow all unknown tags to be self-closing during when parsing as HTML:
Parser parser = Parser.htmlParser(); parser.tagSet().onNewTag(tag -> { if (!tag.isKnownTag()) tag.set(Tag.SelfClose); }); Document doc = Jsoup.parse(html, parser);- Parameters:
customizer- aConsumer<Tag>that will be called for each newly added or cloned Tag; callers can inspect and modify the Tag's state (e.g. set options)- Returns:
- this TagSet, to allow method chaining
- Since:
- 1.21.0
-
equals
-
hashCode
public int hashCode() -
initHtmlDefault
Initialize the default HTML tag set. -
setupTags
-