yoastseo
Version:
Yoast client-side content analysis
37 lines (34 loc) • 1.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _stripWordBoundaries = require("../languageProcessing/helpers/sanitize/stripWordBoundaries");
var _lodash = require("lodash");
/**
* Marks a text with HTML tags, deals with word boundaries that were matched by regexes, but which should not be marked.
*
* @param {string} text The unmarked text.
*
* @returns {string} The marked text.
*/
function _default(text) {
// Strip the word boundaries at the start of the text.
const strippedTextStart = (0, _stripWordBoundaries.stripWordBoundariesStart)(text);
let wordBoundaryStart = "";
let wordBoundaryEnd = "";
// Get the actual word boundaries from the start of the text.
if (strippedTextStart !== text) {
const wordBoundaryStartIndex = text.search((0, _lodash.escapeRegExp)(strippedTextStart));
wordBoundaryStart = text.substring(0, wordBoundaryStartIndex);
}
// Strip word boundaries at the end of the text.
const strippedTextEnd = (0, _stripWordBoundaries.stripWordBoundariesEnd)(strippedTextStart);
// Get the actual word boundaries from the end of the text.
if (strippedTextEnd !== strippedTextStart) {
const wordBoundaryEndIndex = strippedTextStart.search((0, _lodash.escapeRegExp)(strippedTextEnd)) + strippedTextEnd.length;
wordBoundaryEnd = strippedTextStart.substring(wordBoundaryEndIndex);
}
return wordBoundaryStart + "<yoastmark class='yoast-text-mark'>" + strippedTextEnd + "</yoastmark>" + wordBoundaryEnd;
}
//# sourceMappingURL=addMarkSingleWord.js.map