-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prior to this, the "Start working on this section" overlay would appear far after the next available section, instead only appearing after the next contribution survey row (which does not account for H1 headings, other sections, etc.) This changes the detection to also break the detection as soon as it finds a section heading that isn't a CSR heading.
- Loading branch information
1 parent
31a9dd5
commit df82208
Showing
4 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import last from '../../util/last'; | ||
|
||
/** | ||
* Get the level (1 to 6) of any parsed wikitext heading. | ||
* | ||
* This is its own function to account for different parse outputs (Legacy, Parsoid, | ||
* DiscussionTools, etc.) | ||
* | ||
* @param el The element to check. This MUST be a wikitext heading. | ||
* @return The level of the heading (1 to 6) | ||
*/ | ||
export default function getWikiHeadingLevel( el: Element ) { | ||
const h = el.classList.contains( 'mw-heading' ) ? | ||
el.querySelector( 'h1, h2, h3, h4, h5, h6' ) : | ||
el; | ||
|
||
// Check if this is a valid header | ||
if ( !/^H\d+$/.test( h.tagName ) ) { | ||
throw new Error( 'Heading element does not contain a valid <h*> element' ); | ||
} | ||
|
||
return +last( h.tagName ) as 1 | 2 | 3 | 4 | 5 | 6; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Check if a given parameter is a wikitext heading parsed into HTML. | ||
* | ||
* This is its own function to account for different parse outputs (Legacy, Parsoid, | ||
* DiscussionTools, etc.) | ||
* | ||
* @param el The element to check | ||
* @return `true` if the element is a heading, `false` otherwise | ||
*/ | ||
export default function isWikiHeading( el: Element ): boolean { | ||
return ( el.classList.contains( 'mw-heading' ) || /^H\d$/.test( el.tagName ) ); | ||
} |