PHPackages                             candysax/telegraph-node-converter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. candysax/telegraph-node-converter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

candysax/telegraph-node-converter
=================================

Convert HTML to the content of the Telegraph page and back.

1.0.1(2y ago)066MITPHPPHP &gt;=7.3

Since Sep 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/candysax/telegraph-node-converter)[ Packagist](https://packagist.org/packages/candysax/telegraph-node-converter)[ Docs](https://github.com/candysax/telegraph-node-converter)[ RSS](/packages/candysax-telegraph-node-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (3)Used By (0)

Telegraph Node Converter
========================

[](#telegraph-node-converter)

This library helps with the content field of the Page Telegraph API object. It converts an HTML string or a DOMDocument into the format required by the Telegraph API, and also converts it back to an HTML string or a DOMDocument.

- Telegraph API Docs:

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

[](#installation)

To install this library run the command:

```
composer require candysax/telegraph-node-converter

```

Usage
-----

[](#usage)

### Converting from HTML to an array of Node

[](#converting-from-html-to-an-array-of-node)

As the source data for conversion, the `convertToNode` method accepts a string containing html tags or a DOMDocument object. The result can be obtained as an array of Node or its representation as a JSON string.

```
$nodes = HTML::convertToNode('Hello world');
```

Get as array:

```
$nodes->array();
```

```
Array
(
    [0] => Array
        (
            [tag] => p
            [children] => Array
                (
                    [0] => Hello
                    [1] => Array
                        (
                            [tag] => b
                            [children] => Array
                                (
                                    [0] => world
                                )

                        )

                )

        )

)

```

Get as JSON:

```
$nodes->json();
```

```
'[{"tag":"p","children":["Hello ",{"tag":"b","children":["world"]}]}]'

```

Passing the DOMDocument object as a data source for conversion:

```
$dom = new DOMDocument();
$dom->loadHTML('Hello world link');

$nodes = HTML::convertToNode($dom)->json();
```

### Converting from an array of Node to HTML

[](#converting-from-an-array-of-node-to-html)

As the source data for the conversion, the `convertToHtml` method accepts an array of Node or a JSON string. The result can be obtained in the form of a string with HTML tags or a DOM object.

```
$html = Node::convertToHtml([
    [
        'tag' => 'p',
        'children' => [
            'Hello ',
            [
                'tag' => 'b',
                'children' => [
                    'world',
                ],

            ],
        ],
    ],
]);
```

Get as string:

```
$html->string();
```

```
'Hello world'

```

Get as DOMDocument:

```
$html->dom();
```

```
DOMDocument Object

```

### Multiple conversions

[](#multiple-conversions)

```
$input = 'Hello world link';

HTML::convertToNode($input)->convertToHtml()->convertToNode()->convertToHtml()->string();
```

### Examples

[](#examples)

Creating a Telegraph page:

```
use GuzzleHttp\Client;
use Candysax\TelegraphNodeConverter\HTML;

function createPage() {
    $client = new Client();
    $client->request('POST', 'https://api.telegra.ph/createPage', [
        'form_params' => [
            'access_token' => 'your_telegraph_token',
            'title' => 'Example',
            'content' => HTML::convertToNode(
                'Hello world link'
            )->json(),
        ],
    ]);
}
```

Getting the content of the Telegraph page:

```
use GuzzleHttp\Client;
use Candysax\TelegraphNodeConverter\HTML;

function getPageContent() {
    $client = new Client();
    $response = $client->request('POST', 'https://api.telegra.ph/getPage', [
        'form_params' => [
            'path' => 'path_to_the_telegraph_page',
            'return_content' => true,
        ],
    ])->getBody();
    $data = json_decode($response, true);

    return Node::convertToHtml($data['result']['content'])->string();
}
```

Testing
-------

[](#testing)

Tests can be launched by running the following:

```
composer test

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/candysax/telegraph-node-converter/blob/main/LICENSE) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~179 days

Total

2

Last Release

796d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.2

1.0.1PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/87489f486bef796a92658557f922599f0667bd2e910920b72e76c1380d516587?d=identicon)[candysax](/maintainers/candysax)

---

Top Contributors

[![candysax](https://avatars.githubusercontent.com/u/142925983?v=4)](https://github.com/candysax "candysax (25 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/candysax-telegraph-node-converter/health.svg)

```
[![Health](https://phpackages.com/badges/candysax-telegraph-node-converter/health.svg)](https://phpackages.com/packages/candysax-telegraph-node-converter)
```

###  Alternatives

[razonyang/yii2-rate-limiter

Yii2 Rate Limiter

1025.0k1](/packages/razonyang-yii2-rate-limiter)

PHPackages © 2026

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