Skip to content

Commit

Permalink
Headings in nested sections (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedziolkaMichal committed Nov 2, 2022
1 parent b896708 commit 2348481
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/nu/validator/checker/schematronequiv/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@

import java.io.ByteArrayInputStream;
import java.io.StringReader;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -1133,8 +1134,6 @@ public void setLocator(Locator locator) {

private int currentPtr;

private int currentSectioningDepth;

public Assertions() {
super();
}
Expand Down Expand Up @@ -1288,7 +1287,7 @@ private StackNode peek() {

private int currentHeadingPtr;

private int currentSectioningElementPtr;
private final LinkedList<Integer> sectioningElementPtrs = new LinkedList<>();

private boolean hasVisibleMain;

Expand Down Expand Up @@ -1636,8 +1635,7 @@ public void endElement(String uri, String localName, String name)
}
if ("article" == localName || "aside" == localName
|| "nav" == localName || "section" == localName) {
currentSectioningElementPtr = currentPtr - 1;
currentSectioningDepth--;
sectioningElementPtrs.pollLast();
}
}
if ((locator = openActiveDescendants.remove(node)) != null) {
Expand All @@ -1659,8 +1657,6 @@ public void startDocument() throws SAXException {
currentPtr = 0;
currentFigurePtr = -1;
currentHeadingPtr = -1;
currentSectioningElementPtr = -1;
currentSectioningDepth = 0;
stack[0] = null;
hasVisibleMain = false;
hasMetaCharset = false;
Expand Down Expand Up @@ -1690,6 +1686,7 @@ public void reset() {
allIds.clear();
siblingSources.clear();
secondLevelH1s.clear();
sectioningElementPtrs.clear();
}

/**
Expand Down Expand Up @@ -2237,15 +2234,14 @@ msg, getDocumentLocator(),
}
if ("article" == localName || "aside" == localName
|| "nav" == localName || "section" == localName) {
currentSectioningElementPtr = currentPtr + 1;
currentSectioningDepth++;
sectioningElementPtrs.add(currentPtr + 1);
}
if ("h1" == localName || "h2" == localName || "h3" == localName
|| "h4" == localName || "h5" == localName
|| "h6" == localName) {
currentHeadingPtr = currentPtr + 1;
if (currentSectioningElementPtr > -1) {
stack[currentSectioningElementPtr].setHeadingFound();
if (!sectioningElementPtrs.isEmpty()) {
stack[sectioningElementPtrs.peekLast()].setHeadingFound();
}
}
if (((ancestorMask & H1_MASK) != 0 || (ancestorMask & H2_MASK) != 0
Expand Down Expand Up @@ -2483,9 +2479,9 @@ msg, getDocumentLocator(),
hasVisibleMain = true;
}
} else if ("h1" == localName) {
if (currentSectioningDepth > 1) {
if (sectioningElementPtrs.size() > 1) {
warn(h1WarningMessage);
} else if (currentSectioningDepth == 1) {
} else if (sectioningElementPtrs.size() == 1) {
secondLevelH1s.add(new LocatorImpl(getDocumentLocator()));
} else {
hasTopLevelH1 = true;
Expand Down

0 comments on commit 2348481

Please sign in to comment.