Download the PHP package dealnews/datocms-html-to-structured-text without Composer

On this page you can find all versions of the php package dealnews/datocms-html-to-structured-text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package datocms-html-to-structured-text

DatoCMS HTML to Structured Text (PHP)

Convert HTML to DatoCMS Structured Text (DAST format). PHP port of the official JavaScript library.

Requirements

Installation

Basic Usage

Features

Supported Elements

Block Elements

HTML DAST Node Notes
<h1> - <h6> heading Level extracted from tag
<p> paragraph
<ul>, <ol> list Style: bulleted/numbered
<li> listItem
<blockquote> blockquote
<pre>, <code> code Language from class attribute
<hr> thematicBreak

Inline Elements

HTML Mark Notes
<strong>, <b> strong
<em>, <i> emphasis
<u> underline
<s>, <strike> strikethrough
<mark> highlight
<code> (inline) code In paragraph context
<a> link With URL and optional meta
<br> span with \n

Ignored Elements

Scripts, styles, and media elements are ignored: <script>, <style>, <video>, <audio>, <iframe>, <embed>

Advanced Usage

Custom Handlers

Override default conversion for specific elements:

Preprocessing

Modify the DOM before conversion:

Configuring Allowed Blocks

Control which block types are allowed:

Configuring Allowed Marks

Control which text marks are allowed:

Configuring Heading Levels

Control which heading levels are preserved:

Options Reference

Options Class

API Reference

Converter::convert(string $html, ?Options $options = null): ?array

Converts HTML string to DAST document.

Parameters:

Returns: DAST document array or null if empty

Throws: ConversionError if conversion fails

Converter::convertDocument(\DOMDocument $doc, ?Options $options = null): ?array

Converts a DOMDocument to DAST (for pre-parsed HTML).

Parameters:

Returns: DAST document array or null if empty

Throws: ConversionError if conversion fails

Special Features

Code Block Language Detection

The library extracts programming language from code block class names:

Default prefix is language- but can be customized in context.

Link Meta Extraction

Link meta attributes (target, rel, title) are extracted:

Inline Style Mark Extraction

The library can extract marks from inline CSS styles:

Supported style properties:

URL Resolution with Base Tag

The <base> tag is respected for relative URL resolution:

Error Handling

The library throws ConversionError exceptions when conversion fails:

Edge Cases

Whitespace Handling

Nested Lists

Nested lists are fully supported:

Mixed Inline/Block Content

Links and other hybrid elements are handled correctly:

Differences from JavaScript Version

  1. No Promises: PHP handlers return directly (synchronous)
  2. No Hast: Works directly with PHP DOMDocument instead of intermediate tree
  3. Array Structure: DAST nodes are arrays (not objects)
  4. Error Handling: Uses exceptions instead of rejection

Development

Running Tests

Current test coverage: 86%+

Running Examples

License

BSD 3-Clause License - see LICENSE file for details

Credits

This is a PHP port of the official DatoCMS HTML to Structured Text JavaScript library.

Ported and maintained by DealNews.

Related Projects


All versions of datocms-html-to-structured-text with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-dom Version *
ext-libxml Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dealnews/datocms-html-to-structured-text contains the following files

Loading the files please wait ...