PHPackages                             gusvasconcelos/markdown-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. gusvasconcelos/markdown-converter

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

gusvasconcelos/markdown-converter
=================================

A PHP library for generating structured content in Markdown format with support for various elements and customization options

v2.0.1(7mo ago)3300MITPHPPHP &gt;=7.4

Since Sep 18Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/gusvasconcelos/php-markdown-converter)[ Packagist](https://packagist.org/packages/gusvasconcelos/markdown-converter)[ RSS](/packages/gusvasconcelos-markdown-converter/feed)WikiDiscussions main Synced today

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

PHP Markdown Converter
======================

[](#php-markdown-converter)

[![PHP Version](https://camo.githubusercontent.com/b730286e78a11a799fff43434e6ed91ea30b031671f07ad39f83c930e41811c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f677573766173636f6e63656c6f732f6d61726b646f776e2d636f6e766572746572)](https://packagist.org/packages/gusvasconcelos/markdown-converter)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Latest Stable Version](https://camo.githubusercontent.com/bfdbf7a73262a93b1a30f77e2146dde1e03f7770ab0249e90e524e690e02eb54/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f677573766173636f6e63656c6f732f6d61726b646f776e2d636f6e766572746572)](https://packagist.org/packages/gusvasconcelos/markdown-converter)[![Downloads](https://camo.githubusercontent.com/2b60e66b9c3efe3521f62449f1346150cc8fb3bc8e21f6801efcebd60ddb85ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677573766173636f6e63656c6f732f6d61726b646f776e2d636f6e766572746572)](https://camo.githubusercontent.com/2b60e66b9c3efe3521f62449f1346150cc8fb3bc8e21f6801efcebd60ddb85ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f677573766173636f6e63656c6f732f6d61726b646f776e2d636f6e766572746572)

An elegant and fluent PHP library for generating structured Markdown content with support for all essential elements and advanced customization options.

✨ Features
----------

[](#-features)

- **Fluent Interface**: Chainable methods for intuitive document construction
- **Complete Support**: All essential Markdown elements supported
- **Element Management**: Easily manipulate, replace, and remove elements
- **Extensible Architecture**: Based on design patterns and SOLID principles
- **Zero Dependencies**: Independent and lightweight library
- **PSR-4 Compatible**: Standard autoloading

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require gusvasconcelos/markdown-converter
```

⚡ Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Composer

🚀 Basic Usage
-------------

[](#-basic-usage)

```
use GusVasconcelos\MarkdownConverter\MarkdownConverter;

// Initialize the converter
$converter = new MarkdownConverter();

// Create markdown content
$converter
    ->heading('API Request Log')
    ->paragraph('Request ID: 1234567890')
    ->horizontalRule()
    ->codeBlock('{"name":"John","age":30,"email":"john@example.com"}', "json")
    ->link('https://api.example.com', 'API Documentation')
    ->write(__DIR__, "example"); // Writes to example.md file
```

### Fluent Interface

[](#fluent-interface)

All methods return the converter instance, allowing method chaining:

```
$document = (new MarkdownConverter())
    ->heading('System Log', 2)
    ->paragraph('Timestamp: ' . date('Y-m-d H:i:s'))
    ->horizontalRule()
    ->codeBlock($errorDetails, 'php')
    ->bold('Status: ')
    ->code('ERROR')
    ->paragraph('')
    ->blockquote('This is an important system message')
    ->link('https://support.example.com', 'Get Support')
    ->write(__DIR__, "system-log");
```

📋 Available Methods
-------------------

[](#-available-methods)

### Text Elements

[](#text-elements)

#### `heading(string $text, int $level = 1)`

[](#headingstring-text-int-level--1)

Creates a heading with the specified text and level (1-6).

```
$converter->heading('Main Title'); // # Main Title
$converter->heading('Subtitle', 2); // ## Subtitle
```

#### `paragraph(string $text)`

[](#paragraphstring-text)

Adds a paragraph with the specified text.

```
$converter->paragraph('This is an example paragraph.');
// This is an example paragraph.
```

#### `bold(string $text)`

[](#boldstring-text)

Adds bold text.

```
$converter->bold('Bold text'); // **Bold text**
```

#### `italic(string $text)`

[](#italicstring-text)

Adds italic text.

```
$converter->italic('Italic text'); // *Italic text*
```

#### `blockquote(string $text)`

[](#blockquotestring-text)

Adds a block quote.

```
$converter->blockquote('This is an important quote');
// > This is an important quote
```

### Code Elements

[](#code-elements)

#### `code(string $code)`

[](#codestring-code)

Adds inline code.

```
$converter->code('$variable = "value"'); // `$variable = "value"`
```

#### `codeBlock(string $code, string $language = "")`

[](#codeblockstring-code-string-language--)

Adds a code block with optional language.

```
$converter->codeBlock('{"name":"John","age":30}', 'json');
// ```json
// {"name":"John","age":30}
// ```
```

### Media Elements

[](#media-elements)

#### `image(string $url, string $altText, ?string $title = null)`

[](#imagestring-url-string-alttext-string-title--null)

Adds an image with URL, alternative text and optional title.

```
$converter->image('https://example.com/image.jpg', 'Alternative text', 'Title');
// ![Alternative text](https://example.com/image.jpg "Title")
```

#### `link(string $url, string $text, ?string $title = null)`

[](#linkstring-url-string-text-string-title--null)

Adds a link with URL, text and optional title.

```
$converter->link('https://example.com', 'Example Site', 'Visit our site');
// [Example Site](https://example.com "Visit our site")
```

### List Elements

[](#list-elements)

#### `orderedList(array $items)`

[](#orderedlistarray-items)

Adds an ordered list with the specified items.

```
$converter->orderedList(['Item 1', 'Item 2', 'Item 3']);
// 1. Item 1
// 2. Item 2
// 3. Item 3
```

#### `unorderedList(array $items)`

[](#unorderedlistarray-items)

Adds an unordered list with the specified items.

```
$converter->unorderedList(['Item 1', 'Item 2', 'Item 3']);
// - Item 1
// - Item 2
// - Item 3
```

### Structural Elements

[](#structural-elements)

#### `horizontalRule()`

[](#horizontalrule)

Adds a horizontal rule (divider).

```
$converter->horizontalRule(); // ---
```

#### `emoji(string $emoji)`

[](#emojistring-emoji)

Adds an emoji to the content.

```
$converter->emoji('😀'); // 😀
```

### Output Methods

[](#output-methods)

#### `write(string $directory, string $filename)`

[](#writestring-directory-string-filename)

Writes the markdown content to a file.

```
$converter->write(__DIR__, "document"); // Creates document.md
```

#### `__toString()`

[](#__tostring)

Returns the markdown content as a string.

```
$content = (string) $converter; // Gets all content
```

🔧 Element Management
--------------------

[](#-element-management)

The library provides advanced methods for manipulating individual elements:

### Manipulation Methods

[](#manipulation-methods)

#### `get(int $position)`

[](#getint-position)

Gets an element by position.

```
$converter->heading('Title')->paragraph('Text');
$element = $converter->get(0); // Gets the first element (heading)
```

#### `removeAt(int $position)`

[](#removeatint-position)

Removes an element by position.

```
$converter->heading('Title')->paragraph('Text 1')->paragraph('Text 2');
$converter->removeAt(1); // Removes "Text 1"
```

#### `replace(int $position, MarkdownSyntaxInterface $element)`

[](#replaceint-position-markdownsyntaxinterface-element)

Replaces an element at a specific position.

```
use GusVasconcelos\MarkdownConverter\Syntax\BoldSyntax;

$converter->heading('Title')->paragraph('Text');
$converter->replace(1, new BoldSyntax('Bold Text')); // Replaces the paragraph
```

#### `count()`

[](#count)

Returns the total number of elements.

```
$converter->heading('Title')->paragraph('Text');
$total = $converter->count(); // Returns 2
```

#### `clear()`

[](#clear)

Removes all elements from the collection.

```
$converter->heading('Title')->paragraph('Text');
$converter->clear(); // Removes everything
```

#### `all()`

[](#all)

Returns the complete collection of elements.

```
$elements = $converter->all(); // Gets MarkdownSyntaxCollection
```

### Practical Management Example

[](#practical-management-example)

```
$document = new MarkdownConverter();

// Build document
$document
    ->heading('Sales Report')
    ->paragraph('First quarter data')
    ->codeBlock('// Example code', 'php')
    ->paragraph('Detailed analysis');

// Check number of elements
echo "Total elements: " . $document->count(); // 4

// Replace code with a list
use GusVasconcelos\MarkdownConverter\Syntax\UnorderedListSyntax;
$list = new UnorderedListSyntax(['Sales: 100k', 'Profit: 25k', 'Customers: 500']);
$document->replace(2, $list);

// Remove last paragraph
$document->removeAt(3);

// Get final result
$finalContent = (string) $document;
```

💡 Use Cases
-----------

[](#-use-cases)

### 📋 Automated Reports

[](#-automated-reports)

Create structured reports from system data:

```
$report = new MarkdownConverter();

// Data from database
$sales = ['January' => 15000, 'February' => 18000, 'March' => 22000];
$topProducts = ['Product A', 'Product B', 'Product C'];

$report
    ->heading('Monthly Sales Report', 1)
    ->paragraph('Period: ' . date('Y-m-d'))
    ->emoji('📈')
    ->horizontalRule()

    ->heading('Executive Summary', 2)
    ->paragraph('Total quarterly sales: $' . number_format(array_sum($sales), 2))
    ->blockquote('Quarterly target achieved successfully!')

    ->heading('Sales by Month', 2)
    ->orderedList(array_map(function($month, $value) {
        return "$month: $" . number_format($value, 2);
    }, array_keys($sales), $sales))

    ->heading('Top Products', 2)
    ->unorderedList($topProducts)

    ->horizontalRule()
    ->italic('Report automatically generated on ' . date('m/d/Y H:i'))

    ->write(__DIR__, 'sales-report');
```

### 🐛 System Logs

[](#-system-logs)

Structure error and debug logs:

```
$logger = new MarkdownConverter();

$logger
    ->heading('System Error Log', 1)
    ->paragraph('Timestamp: ' . date('Y-m-d H:i:s'))
    ->horizontalRule()

    ->heading('Critical Error', 2)
    ->bold('Level: ')
    ->code('CRITICAL')
    ->paragraph('Database connection failure.')
    ->codeBlock('PDOException: Connection refused', 'text')

    ->heading('Stack Trace', 3)
    ->codeBlock($stackTrace ?? 'Stack trace not available', 'php')

    ->heading('Recommended Action', 2)
    ->blockquote('Check connection settings and MySQL server status')

    ->write('/var/log/app/', 'error-' . date('Y-m-d'));
```

### 📧 Email Templates

[](#-email-templates)

Generate content for transactional emails:

```
$emailTemplate = new MarkdownConverter();

$emailTemplate
    ->heading('Welcome to our platform!', 1)
    ->emoji('🎉')
    ->paragraph('Hello John, we\'re happy to have you with us!')

    ->heading('Next Steps', 2)
    ->orderedList([
        'Complete your profile',
        'Explore our features',
        'Contact us if you need help'
    ])

    ->horizontalRule()
    ->paragraph('Need help?')
    ->link('https://support.example.com', 'Help Center')

    ->paragraph('')
    ->italic('Example Team');

// Convert to HTML via Markdown parser
$htmlContent = $markdownParser->parse((string) $emailTemplate);
```

🧪 Testing
---------

[](#-testing)

Run the test suite to ensure everything works correctly:

```
composer test
```

The library includes comprehensive tests covering:

- All Markdown syntax elements
- Element management operations
- File writing functionality
- Method chaining behavior
- Edge cases and error conditions

📄 License
---------

[](#-license)

This project is open-sourced under the MIT License - see the [LICENSE](LICENSE) file for details.

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

### Contributing Guidelines

[](#contributing-guidelines)

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass (`composer test`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

Please make sure to update tests as appropriate and follow the existing code style.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance64

Regular maintenance activity

Popularity15

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

Total

4

Last Release

218d ago

Major Versions

1.0.0 → 2.0.02025-09-20

v1.0.1 → v2.0.12025-11-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/103261186?v=4)[Gustavo Vasconcelos](/maintainers/gusvasconcelos)[@gusvasconcelos](https://github.com/gusvasconcelos)

---

Top Contributors

[![gusvasconcelos](https://avatars.githubusercontent.com/u/103261186?v=4)](https://github.com/gusvasconcelos "gusvasconcelos (23 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gusvasconcelos-markdown-converter/health.svg)

```
[![Health](https://phpackages.com/badges/gusvasconcelos-markdown-converter/health.svg)](https://phpackages.com/packages/gusvasconcelos-markdown-converter)
```

###  Alternatives

[milkyway-multimedia/ss-gridfield-utils

A collection of GridField components that you can use with any GridField, including Editable Rows and amy more

207.3k2](/packages/milkyway-multimedia-ss-gridfield-utils)

PHPackages © 2026

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