• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / c48b3ac682565214f330b8e3d1658af9054c4f2d

07 May 2025 09:40AM UTC coverage: 52.78% (-0.1%) from 52.897%
c48b3ac682565214f330b8e3d1658af9054c4f2d

push

github

web-flow
Merge pull request #22239 from Yoast/512-increase-safety-around-tag-mismatches-in-translations

implement `safeCreateInterpolateElement` in packages/js

8119 of 14273 branches covered (56.88%)

Branch coverage included in aggregate %.

3 of 46 new or added lines in 20 files covered. (6.52%)

51 existing lines in 1 file now uncovered.

29553 of 57103 relevant lines covered (51.75%)

41795.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.0
/packages/js/src/helpers/stringHelpers.js
1
import { safeCreateInterpolateElement } from "./i18n";
2

3
/**
4
 * Capitalize the first letter of a string.
5
 *
6
 * @param   {string} string The string to capitalize.
7
 *
8
 * @returns {string}        The string with the first letter capitalized.
9
 */
10
export function firstToUpperCase( string ) {
11
        return string.charAt( 0 ).toUpperCase() + string.slice( 1 );
72✔
12
}
13

14
/**
15
 * Strips HTML from a string.
16
 *
17
 * @param {string} string  The string to strip HTML from.
18
 *
19
 * @returns {string} The string with HTML stripped.
20
 */
21
export function stripHTML( string ) {
22
        const tmp = document.createElement( "DIV" );
×
23
        tmp.innerHTML = string;
×
24
        return tmp.textContent || tmp.innerText || "";
×
25
}
26

27
/**
28
 * Adds a link to a string containing anchor tags (in string form).
29
 *
30
 * @example "This is an example text in which <a>this part should be a link</a> and this part shouldn't."
31
 *
32
 * @param {string} text   The text to add links to. Make sure it contains <a> and </a> tags surrounding the link part.
33
 * @param {string} linkTo The target URL for the link (href).
34
 * @param {string} id     The id to attach to the link.
35
 *
36
 * @returns {WPElement} A Fragment with the text and a link.
37
 */
38
export function addLinkToString( text, linkTo, id = "" ) {
×
NEW
39
        return safeCreateInterpolateElement(
×
40
                text,
41
                {
42
                        // eslint-disable-next-line jsx-a11y/anchor-has-content
43
                        a: <a id={ id } href={ linkTo } target="_blank" rel="noopener noreferrer" />,
44
                }
45
        );
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc