UNPKG

yoastseo

Version:

Yoast client-side content analysis

73 lines (71 loc) 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _SourceCodeLocation = _interopRequireDefault(require("./SourceCodeLocation")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * Represents formatting elements (e.g. link, image, bold text) within a document. * * @memberOf module:parsedPaper/structure */ class FormattingElement { /** * Represents a formatting element (e.g. link, image, bold text) within a document. * * @param {string} type The type of this element ("link", "image", "bold", etc.). * @param {Object} sourceCodeLocation The parse5 formatted location of the element inside of the source code. * @param {Object} [attributes=null] The attributes (as key-value pairs, e.g. `{ href: '...' }` ). */ constructor(type, sourceCodeLocation, attributes = null) { /** * Type of formatting element (e.g. "strong", "a"). * @type {string} */ this.type = type; /** * Attributes of this element (e.g. "href", "id"). * @type {?Object} */ this.attributes = attributes; /** * Location inside of the source code. * @type {SourceCodeLocation} */ this.sourceCodeLocation = new _SourceCodeLocation.default(sourceCodeLocation); /** * Start of this element's content within the parent textContainer's text. * @type {?number} */ this.textStartIndex = null; /** * End of this element's content within the parent textContainer's text. * @type {?number} */ this.textEndIndex = null; /** * This formatting element's parent. * @type {LeafNode} */ this.parent = null; } /** * Returns the attribute with the given name if it exists. * * @param {string} name The name of the attribute. * * @returns {false|*} The attribute or `false` if the attribute does not exist. */ getAttribute(name) { if (!this.attributes) { return false; } if (name in this.attributes) { return this.attributes[name]; } return false; } } var _default = exports.default = FormattingElement; //# sourceMappingURL=FormattingElement.js.map