Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the self-closing-tag warning to the TreeBuilder code #74

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/nu/validator/htmlparser/impl/ErrorReportingTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,18 +710,6 @@ private boolean isAstralPrivateUse(int c) {
note("xhtml1", "Unquoted attribute value.");
}

@Override
protected void noteSelfClosingTag() throws SAXException {
note("html-strict",
"Self-closing tag syntax in text/html documents is widely"
+ " discouraged; it’s unnecessary and interacts badly"
+ " with other HTML features (e.g., unquoted attribute"
+ " values). If you’re using a tool that injects"
+ " self-closing tag syntax into all void elements,"
+ " without any option to prevent it from doing so,"
+ " then consider switching to a different tool.");
}

/**
* Sets the transitionHandler.
*
Expand Down
4 changes: 0 additions & 4 deletions src/nu/validator/htmlparser/impl/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,6 @@ private void ensureBufferSpace(int inputLength) throws SAXException {
* flag of the current tag token. Emit the current
* tag token.
*/
noteSelfClosingTag();
state = transition(state, emitCurrentTagToken(true, pos), reconsume, pos);
if (shouldSuspend) {
break stateloop;
Expand Down Expand Up @@ -7588,9 +7587,6 @@ protected void noteAttributeWithoutValue() throws SAXException {
protected void noteUnquotedAttributeValue() throws SAXException {
}

protected void noteSelfClosingTag() throws SAXException {
}

/**
* Sets the encodingDeclarationHandler.
*
Expand Down
22 changes: 22 additions & 0 deletions src/nu/validator/htmlparser/impl/TreeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ public abstract class TreeBuilder<T> implements TokenHandler,

private boolean reportingDoctype = true;

private HashMap<String, String> errorProfileMap = null;

private XmlViolationPolicy namePolicy = XmlViolationPolicy.ALTER_INFOSET;

private final Map<String, LocatorImpl> idLocations = new HashMap<String, LocatorImpl>();
Expand Down Expand Up @@ -1458,6 +1460,17 @@ public final void startTag(ElementName elementName,
flushCharacters();

// [NOCPP[
if (contextNamespace == "http://www.w3.org/1999/xhtml" &&
selfClosing && errorProfileMap != null &&
errorProfileMap.get("html-strict") != null) {
warn("Self-closing tag syntax in text/html documents is widely"
+ " discouraged; it’s unnecessary and interacts badly"
+ " with other HTML features (e.g., unquoted attribute"
+ " values). If you’re using a tool that injects"
+ " self-closing tag syntax into all void elements,"
+ " without any option to prevent it from doing so,"
+ " then consider switching to a different tool.");
}
if (errorHandler != null) {
// ID uniqueness
@IdType String id = attributes.getId();
Expand Down Expand Up @@ -5818,6 +5831,15 @@ public void setNamePolicy(XmlViolationPolicy namePolicy) {
this.namePolicy = namePolicy;
}

/**
* Sets the errorProfile.
*
* @param errorProfile
*/
public void setErrorProfile(HashMap<String, String> errorProfileMap) {
this.errorProfileMap = errorProfileMap;
}

/**
* Sets the documentModeHandler.
*
Expand Down
1 change: 1 addition & 0 deletions src/nu/validator/htmlparser/sax/HtmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void lazyInit() {
this.treeBuilder.setScriptingEnabled(scriptingEnabled);
this.treeBuilder.setReportingDoctype(reportingDoctype);
this.treeBuilder.setNamePolicy(namePolicy);
this.treeBuilder.setErrorProfile(errorProfileMap);
if (saxStreamer != null) {
saxStreamer.setContentHandler(contentHandler == null ? new DefaultHandler()
: contentHandler);
Expand Down