PHPackages                             webfoo/html-to-shopify-rich-text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. webfoo/html-to-shopify-rich-text

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

webfoo/html-to-shopify-rich-text
================================

A PHP library to convert HTML to Shopify's Rich Text format

1.0.2(1y ago)5607↑166.7%1[1 issues](https://github.com/webfoo/html-to-shopify-rich-text/issues)MITPHPPHP ^8.3

Since Apr 5Pushed 1y ago1 watchersCompare

[ Source](https://github.com/webfoo/html-to-shopify-rich-text)[ Packagist](https://packagist.org/packages/webfoo/html-to-shopify-rich-text)[ RSS](/packages/webfoo-html-to-shopify-rich-text/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

HtmlToShopifyRichText
=====================

[](#htmltoshopifyrichtext)

A PHP package that converts HTML content to Shopify's Rich Text format. This package provides a simple and reliable way to transform HTML content into the JSON structure that Shopify's Rich Text editor expects.

Features
--------

[](#features)

- Converts common HTML elements to Shopify Rich Text format
- Supports headings (h1-h6)
- Handles paragraphs, lists (ordered and unordered)
- Processes inline elements (bold, italic, links)
- Sanitizes HTML input
- Validates HTML structure
- Handles whitespace normalization
- Provides detailed error handling

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require webfoo/html-to-shopify-rich-text
```

Usage
-----

[](#usage)

```
use Webfoo\HtmlToShopifyRichText\HtmlToShopifyRichText;

$html = 'Hello WorldThis is a test paragraph.';
$richText = HtmlToShopifyRichText::convert($html);

// $richText will contain the JSON representation of the Shopify Rich Text
```

### Supported HTML Elements

[](#supported-html-elements)

- Headings: `` through ``
- Paragraphs: ``
- Lists: ``, ``, ``
- Links: ``
- Bold: ``, ``
- Italic: ``, ``

Error Handling
--------------

[](#error-handling)

The package throws specific exceptions for different error scenarios:

- `InvalidHtmlException`: Thrown when the HTML is invalid or cannot be parsed
- `ConversionException`: Thrown when the conversion process fails
- `JsonEncodingException`: Thrown when the JSON encoding fails

Example error handling:

```
try {
    $richText = HtmlToShopifyRichText::convert($html);
} catch (InvalidHtmlException $e) {
    // Handle invalid HTML
} catch (ConversionException $e) {
    // Handle conversion errors
} catch (JsonEncodingException $e) {
    // Handle JSON encoding errors
}
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer
- Required dependencies:
    - `symfony/dom-crawler`
    - `ezyang/htmlpurifier`

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance42

Moderate activity, may be stable

Popularity24

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

408d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fe50bb7ef33de5b42610cef95460678fb7e1db5decfe9ac8808b17a3846271ef?d=identicon)[webfoo](/maintainers/webfoo)

---

Tags

parserphpshopify

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webfoo-html-to-shopify-rich-text/health.svg)

```
[![Health](https://phpackages.com/badges/webfoo-html-to-shopify-rich-text/health.svg)](https://phpackages.com/packages/webfoo-html-to-shopify-rich-text)
```

###  Alternatives

[spekulatius/phpscraper

PHPScraper, built with simplicity in mind. See tests/ for more examples.

583143.5k3](/packages/spekulatius-phpscraper)[scotteh/php-dom-wrapper

Simple DOM wrapper to select nodes using either CSS or XPath expressions and manipulate results quickly and easily.

1471.9M10](/packages/scotteh-php-dom-wrapper)[chameleon-system/chameleon-base

The Chameleon System core.

1026.5k3](/packages/chameleon-system-chameleon-base)[sproutcms/cms

Enterprise content management and framework

241.6k4](/packages/sproutcms-cms)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
