Skip to content

Commit f93bb9d

Browse files
Merge pull request #732 from LouiseSteward/fix/indexing-block-comments
Refine definition of block-level index comment
2 parents 068f078 + 022686f commit f93bb9d

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

assets/js/index-targets.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ function ebIndexGetComments () {
229229

230230
const comments = []
231231

232-
let indexedElement, commentValue, previousElementSibling,
233-
nextElementSibling, nextSibling, targetType, targetText
232+
let indexedElement, commentValue, nextElementSibling, nextSibling, targetType,
233+
targetText
234234

235235
// Regex for testing if a comment is an indexing comment
236236
const isAnIndexComment = /^\s*index:/
@@ -267,7 +267,6 @@ function ebIndexGetComments () {
267267
while (treeWalker.nextNode()) {
268268
if (isAnIndexComment.test(treeWalker.currentNode.nodeValue)) {
269269
nextSibling = treeWalker.currentNode.nextSibling
270-
previousElementSibling = treeWalker.currentNode.previousElementSibling
271270
nextElementSibling = treeWalker.currentNode.nextElementSibling
272271

273272
// If the previous or next sibling elements of the comment
@@ -279,10 +278,8 @@ function ebIndexGetComments () {
279278
// then we know that the index target must be inline, i.e.
280279
// inside a text element like a paragraph.
281280

282-
if (previousElementSibling !== null &&
283-
nextElementSibling !== null &&
284-
ebIndexOptions.blockLevelElements.includes(previousElementSibling.tagName) &&
285-
ebIndexOptions.blockLevelElements.includes(nextElementSibling.tagName)) {
281+
if (nextElementSibling !== null &&
282+
ebIndexOptions.blockLevelElements.includes(nextElementSibling.tagName)) {
286283
indexedElement = treeWalker.currentNode.nextElementSibling
287284
targetType = 'element'
288285
targetText = ''
@@ -319,13 +316,10 @@ function ebIndexGetComments () {
319316
if (thisNode.nodeType === Node.COMMENT_NODE &&
320317
isAnIndexComment.test(thisNode.nodeValue)) {
321318
nextSibling = thisNode.nextSibling
322-
previousElementSibling = thisNode.previousElementSibling
323319
nextElementSibling = thisNode.nextElementSibling
324320

325-
if (previousElementSibling !== null &&
326-
nextElementSibling !== null &&
327-
ebIndexOptions.blockLevelElements.includes(previousElementSibling.tagName) &&
328-
ebIndexOptions.blockLevelElements.includes(nextElementSibling.tagName)) {
321+
if (nextElementSibling !== null &&
322+
ebIndexOptions.blockLevelElements.includes(nextElementSibling.tagName)) {
329323
indexedElement = thisNode.nextElementSibling
330324
targetType = 'element'
331325
targetText = ''

0 commit comments

Comments
 (0)