Fix incorrectly detecting a section heading inside the table of contents

Change-Id: I7209b523c3322b3b379e6aa82a4b2014cc39c404
This commit is contained in:
Bartosz Dziewoński 2019-10-24 18:24:59 +02:00
parent 112ea056cd
commit e8012b7094
3 changed files with 22 additions and 20 deletions

View file

@ -368,6 +368,21 @@ function getLocalTimestampParser() {
return parseFunction;
}
/**
* Callback for document.createTreeWalker that will skip over nodes where we don't want to detect
* comments (or section headings).
*
* @param {Node} node
* @return {number} Appropriate NodeFilter constant
*/
function acceptOnlyNodesAllowingComments( node ) {
// The table of contents has a heading that gets erroneously detected as a section
if ( node.id === 'toc' ) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
/**
* Find all timestamps within a DOM subtree.
*
@ -380,7 +395,12 @@ function getLocalTimestampParser() {
function findTimestamps( rootNode ) {
var
matches = [],
treeWalker = rootNode.ownerDocument.createTreeWalker( rootNode, NodeFilter.SHOW_TEXT, null, false ),
treeWalker = rootNode.ownerDocument.createTreeWalker(
rootNode,
NodeFilter.SHOW_TEXT,
acceptOnlyNodesAllowingComments,
false
),
dateRegexp = getLocalTimestampRegexp(),
node, match;
@ -630,7 +650,7 @@ function getComments( rootNode ) {
rootNode,
// eslint-disable-next-line no-bitwise
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT,
null,
acceptOnlyNodesAllowingComments,
false
);

View file

@ -1,13 +1,4 @@
[
{
"level": 0,
"range": [
"0/4/1/0/0",
"0/4/1/0/1"
],
"replies": [],
"type": "heading"
},
{
"level": 0,
"range": [

View file

@ -1,13 +1,4 @@
[
{
"level": 0,
"range": [
"0/0/0/1/0/0",
"0/0/0/1/0/1"
],
"replies": [],
"type": "heading"
},
{
"level": 0,
"range": [