mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-24 00:13:36 +00:00
Fix incorrectly detecting a section heading inside the table of contents
Change-Id: I7209b523c3322b3b379e6aa82a4b2014cc39c404
This commit is contained in:
parent
112ea056cd
commit
e8012b7094
|
@ -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
|
||||
);
|
||||
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
[
|
||||
{
|
||||
"level": 0,
|
||||
"range": [
|
||||
"0/4/1/0/0",
|
||||
"0/4/1/0/1"
|
||||
],
|
||||
"replies": [],
|
||||
"type": "heading"
|
||||
},
|
||||
{
|
||||
"level": 0,
|
||||
"range": [
|
||||
|
|
|
@ -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": [
|
||||
|
|
Loading…
Reference in a new issue