UNPKG

@wordpress/block-library

Version:
39 lines (38 loc) • 1.6 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_url = require("@wordpress/url"); let __constants_js = require("./constants.cjs"); // packages/block-library/src/button/get-updated-link-attributes.js /** * Updates the link attributes. * * @param {Object} attributes The current block attributes. * @param {string} attributes.rel The current link rel attribute. * @param {string} attributes.url The current link url. * @param {boolean} attributes.opensInNewTab Whether the link should open in a new window. * @param {boolean} attributes.nofollow Whether the link should be marked as nofollow. */ function getUpdatedLinkAttributes({ rel = "", url = "", opensInNewTab, nofollow }) { let newLinkTarget; let updatedRel = rel; if (opensInNewTab) newLinkTarget = __constants_js.NEW_TAB_TARGET; else { const relRegex = new RegExp(`\\b${__constants_js.NEW_TAB_REL}\\s*`, "g"); updatedRel = updatedRel?.replace(relRegex, "").trim(); } if (nofollow) updatedRel = updatedRel?.includes(__constants_js.NOFOLLOW_REL) ? updatedRel : (updatedRel + ` ${__constants_js.NOFOLLOW_REL}`).trim(); else { const relRegex = new RegExp(`\\b${__constants_js.NOFOLLOW_REL}\\s*`, "g"); updatedRel = updatedRel?.replace(relRegex, "").trim(); } return { url: (0, _wordpress_url.prependHTTPS)(url), linkTarget: newLinkTarget, rel: updatedRel || void 0 }; } exports.getUpdatedLinkAttributes = getUpdatedLinkAttributes; //# sourceMappingURL=get-updated-link-attributes.cjs.map