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

Yoast / wordpress-seo / fd6db97cff09bebe3a97fc4c331c63bd962c9f25

12 Jan 2026 03:36PM UTC coverage: 53.302% (-0.01%) from 53.315%
fd6db97cff09bebe3a97fc4c331c63bd962c9f25

Pull #22877

github

web-flow
Merge 5e4b79ce9 into 3d1950c99
Pull Request #22877: Convert RichText content to HTML string before rendering

8774 of 16284 branches covered (53.88%)

Branch coverage included in aggregate %.

0 of 9 new or added lines in 1 file covered. (0.0%)

117 existing lines in 3 files now uncovered.

32856 of 61818 relevant lines covered (53.15%)

46643.94 hits per line

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

0.0
/packages/js/src/structured-data-blocks/how-to/utils/convertToHTMLString.js
1
import { toHTMLString } from "@wordpress/rich-text";
2
import { renderToString } from "@wordpress/element";
3

4
/**
5
 * Converts an array of contents to an HTML string.
6
 *
7
 * @param {string|[]} contents The contents to convert.
8
 *
9
 * @returns {string} The HTML string.
10
 */
NEW
11
export const convertToHTMLString = ( contents ) => {
×
NEW
12
        if ( ! Array.isArray( contents ) ) {
×
NEW
13
                return contents;
×
14
        }
NEW
15
        return contents.map( ( item ) => {
×
NEW
16
                if ( typeof item === "string" ) {
×
NEW
17
                        return item;
×
18
                }
19
                // Use renderToString for the image elements as toHTMLString does not handle images correctly.
NEW
20
                if ( item && item.type === "img" && item.props ) {
×
NEW
21
                        return renderToString( item );
×
22
                }
23
                // Otherwise, assume it's a RichText format object (which handles br, etc.)
NEW
24
                return toHTMLString( item );
×
25
        } ).join( "" );
26
};
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