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

Yoast / wordpress-seo / 49c6ac400595cd61adfaaaf0565ee2b8f420a4f9

12 Jan 2026 04:00PM UTC coverage: 53.331% (+0.02%) from 53.315%
49c6ac400595cd61adfaaaf0565ee2b8f420a4f9

Pull #22877

github

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

8692 of 16060 branches covered (54.12%)

Branch coverage included in aggregate %.

0 of 10 new or added lines in 2 files covered. (0.0%)

145 existing lines in 3 files now uncovered.

32472 of 61126 relevant lines covered (53.12%)

47171.99 hits per line

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

0.0
/packages/js/src/structured-data-blocks/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