Skip to content

Commit

Permalink
Match tag names after uppercasing
Browse files Browse the repository at this point in the history
Fixes #165
  • Loading branch information
tomayac committed Oct 10, 2024
1 parent e6b7ef0 commit def94c5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "text-fragments-polyfill",
"version": "6.0.0",
"version": "6.1.0",
"description": "This is a polyfill for the [Text Fragments](https://wicg.github.io/scroll-to-text-fragment/) feature for browsers that don't support it natively.",
"main": "./dist/text-fragments.js",
"browser": "./dist/text-fragments.js",
Expand Down
6 changes: 3 additions & 3 deletions src/fragment-generation-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const isValidRangeForFragmentGeneration = (range) => {
let numIterations = 0;
while (node) {
if (node.nodeType == Node.ELEMENT_NODE) {
if (['TEXTAREA', 'INPUT'].includes(node.tagName)) {
if (['TEXTAREA', 'INPUT'].includes(node.tagName.toUpperCase())) {
return false;
}

Expand Down Expand Up @@ -1720,8 +1720,8 @@ const expandRangeEndToWordBound = (range) => {
*/
const isBlock = (node) => {
return node.nodeType === Node.ELEMENT_NODE &&
(fragments.internal.BLOCK_ELEMENTS.includes(node.tagName) ||
node.tagName === 'HTML' || node.tagName === 'BODY');
(fragments.internal.BLOCK_ELEMENTS.includes(node.tagName.toUpperCase()) ||
node.tagName.toUpperCase() === 'HTML' || node.tagName.toUpperCase() === 'BODY');
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/text-fragment-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export const markRange = (range, documentToProcess = document) => {
acceptNode: function(node) {
if (!range.intersectsNode(node)) return NodeFilter.FILTER_REJECT;

if (BLOCK_ELEMENTS.includes(node.tagName) ||
if (BLOCK_ELEMENTS.includes(node.tagName.toUpperCase()) ||
node.nodeType === Node.TEXT_NODE)
return NodeFilter.FILTER_ACCEPT;
return NodeFilter.FILTER_SKIP;
Expand Down Expand Up @@ -623,7 +623,7 @@ const getAllTextNodes = (root, range) => {
if (node.nodeType === Node.TEXT_NODE) {
tmp.push(node);
} else if (
node instanceof HTMLElement && BLOCK_ELEMENTS.includes(node.tagName) &&
node instanceof HTMLElement && BLOCK_ELEMENTS.includes(node.tagName.toUpperCase()) &&
tmp.length > 0) {
// If this is a block element, the current set of text nodes in |tmp| is
// complete, and we need to move on to a new one.
Expand Down

0 comments on commit def94c5

Please sign in to comment.