<commit_before>'use strict';

import GoResultsHighlighter from './lib/wrapper';
import { asArray } from './lib/utils';
import './styles/bookmark.less';

// exactly one result per row is allowed
const CELL_RESULT_REGEXP = /^[^0-9]*([0-9]+[-+=?])[^-+?]*$/;
const RESULT_REGEXP = /[0-9]+[-+?]/g;

/**
 * Applies highlighter to all elements matching given selector if they look like Go results.
 *
 * @param {string} selector - CSS-like selector
 * @param {HighlighterSettings} settings - highlighter settings
 * @param {boolean} [force=false] - whether the check for results should be ignored
 */
function applyHighlighter(selector, settings, force) {
    const elementsWithGoResults = asArray(document.querySelectorAll(selector))
        .filter(/** Element */ element => {

            if (force) {
                return true;
            }

            // table element will be treated as results if any of its cells contain SINGLE result
            // string.
            if (element.nodeName === 'TABLE') {
                const cells = asArray(element.querySelectorAll('td'));
                const count = cells.length;

                for (let i = 0; i < count; i++) {
                    if (CELL_RESULT_REGEXP.test(cells[i].textContent)) {
                        return true;
                    }
                }

                return false;
            }

            // other element will be treated as results if it contains at least 6 Go results strings.<commit_msg>Made sure that only direct cells are checked for Go results<commit_after>'use strict';

import GoResultsHighlighter from './lib/wrapper';
import { asArray } from './lib/utils';
import './styles/bookmark.less';

// exactly one result per row is allowed
const CELL_RESULT_REGEXP = /^[^0-9]*([0-9]+[-+=?])[^-+?]*$/;
const RESULT_REGEXP = /[0-9]+[-+?]/g;

/**
 * Applies highlighter to all elements matching given selector if they look like Go results.
 *
 * @param {string} selector - CSS-like selector
 * @param {HighlighterSettings} settings - highlighter settings
 * @param {boolean} [force=false] - whether the check for results should be ignored
 */
function applyHighlighter(selector, settings, force) {
    const elementsWithGoResults = asArray(document.querySelectorAll(selector))
        .filter(/** Element */ element => {

            if (force) {
                return true;
            }

            // table element will be treated as results if any of its cells contain SINGLE result
            // string.
            if (element.nodeName === 'TABLE') {
                const rowsCount = element.rows.length;

                for (let i = 0; i < rowsCount; i++) {
                    const cellsCount = element.rows[i].cells.length;

                    for (let j = 0; j < cellsCount; j++) {
                        console.log(element.rows[i].cells[j].textContent, CELL_RESULT_REGEXP.test(element.rows[i].cells[j].textContent));
                        if (CELL_RESULT_REGEXP.test(element.rows[i].cells[j].textContent)) {
                            return true;
                        }
                    }
                }

                return false;
            }

            // other element will be treated as results if it contains at least 6 Go results strings.
{'fraction_non_alphanumeric': 0.11863372979566941, 'fraction_numerical': 0.00518450747179018, 'mean_word_length': 2.0483271375464684, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5167930', 'n_tokens_mistral': 898, 'n_tokens_neox': 856, 'n_words': 274}