PHPackages                             shengkung/mdify - 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. shengkung/mdify

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

shengkung/mdify
===============

HTML ↔ Markdown bidirectional converter. A PHP class that converts between HTML and Markdown formats with support for tables, nested lists, images, and links.

60PHP

Since Dec 10Pushed 5mo agoCompare

[ Source](https://github.com/shengkung/mdify)[ Packagist](https://packagist.org/packages/shengkung/mdify)[ RSS](/packages/shengkung-mdify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

mdify
=====

[](#mdify)

**HTML ↔ Markdown Bidirectional Converter** (HTML ↔ Markdown 雙向轉換工具)

---

Introduction
------------

[](#introduction)

`mdify` is a PHP class that provides bidirectional conversion between HTML and Markdown formats. It supports common formats such as headings, bold, italic, images, links, tables, and nested lists.

`mdify` 是一個 PHP 類別，提供 HTML 與 Markdown 格式之間的雙向轉換功能。支援標題、粗體、斜體、圖片、連結、表格和巢狀列表等常見格式。

---

Features
--------

[](#features)

### HTML → Markdown

[](#html--markdown)

- ✅ Heading conversion (H1-H6) - 標題轉換
- ✅ Text formatting (bold, italic) - 文字格式（粗體、斜體）
- ✅ Image conversion - 圖片轉換
- ✅ Link conversion - 連結轉換
- ✅ Table conversion - 表格轉換
- ✅ Nested list conversion - 巢狀列表轉換
- ✅ Automatic empty tag cleanup - 自動清理空白標籤

### Markdown → HTML

[](#markdown--html)

- ✅ Heading conversion (# to ######) - 標題轉換
- ✅ Text formatting (**bold**, *italic*) - 文字格式
- ✅ Image conversion - 圖片轉換
- ✅ Link conversion - 連結轉換
- ✅ Table conversion (with alignment support) - 表格轉換（支援對齊）
- ✅ Nested list conversion - 巢狀列表轉換

---

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

[](#installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

```
composer require shengkung/mdify
```

### Manual Installation

[](#manual-installation)

Include the `mdify.php` file in your project:

將 `mdify.php` 檔案包含到您的專案中：

```
require_once 'mdify/mdify.php';
```

---

Usage
-----

[](#usage)

### HTML → Markdown

[](#html--markdown-1)

```
$sHtmlContent = 'TitleThis is bold text.';
$sMarkdown = mdify::htmlToMarkdown($sHtmlContent);
echo $sMarkdown;
// Output: # Title
//
// This is **bold** text.
```

### Markdown → HTML

[](#markdown--html-1)

```
$sMarkdown = '# Title\n\nThis is **bold** text.';
$sHtml = mdify::markdownToHtml($sMarkdown);
echo $sHtml;
// Output: Title
//         This is bold text.
```

---

API Reference
-------------

[](#api-reference)

### `htmlToMarkdown($sHtmlContent)`

[](#htmltomarkdownshtmlcontent)

Converts HTML content to Markdown format.

將 HTML 內容轉換為 Markdown 格式。

**Parameters:**

- `$sHtmlContent` (string) - HTML content (HTML 內容)

**Returns:**

- (string) - Markdown formatted text (Markdown 格式文字)

**Example:**

```
$sHtml = 'SubtitleContent';
$sMarkdown = mdify::htmlToMarkdown($sHtml);
```

---

### `markdownToHtml($sMarkdownContent)`

[](#markdowntohtmlsmarkdowncontent)

Converts Markdown content to HTML format.

將 Markdown 內容轉換為 HTML 格式。

**Parameters:**

- `$sMarkdownContent` (string) - Markdown content (Markdown 內容)

**Returns:**

- (string) - HTML formatted text (HTML 格式文字)

**Example:**

```
$sMarkdown = '## Subtitle\n\nContent';
$sHtml = mdify::markdownToHtml($sMarkdown);
```

---

Supported Formats
-----------------

[](#supported-formats)

### HTML → Markdown Support

[](#html--markdown-support)

HTML TagMarkdown Syntax`` ~ ```#` ~ `######```, ```**text**```, ```*text*````![alt](src)``text``[text](href)``...`Markdown table``, ```- ` or `1. `### Markdown → HTML Support

[](#markdown--html-support)

Markdown SyntaxHTML Tag`#` ~ `######``` ~ ```**text**``text``*text*``text``![alt](url)````[text](url)``text`Markdown table`...``- ` or `1. ```, ``---

Notes
-----

[](#notes)

1. **Nested Lists**: Supports multi-level nested structures, using 2 spaces for each indentation level. 支援多層巢狀結構，使用 2 個空格縮排表示一個層級。
2. **Table Alignment**: When converting Markdown → HTML, supports left, center, and right alignment. Markdown → HTML 轉換時，支援左對齊、置中、右對齊。
3. **HTML Entities**: Automatically handles HTML entity decoding. 自動處理 HTML 實體的解碼。
4. **Whitespace Cleanup**: Automatically removes excessive blank lines and empty tags. 自動移除多餘的空白行和空標籤。

---

Version
-------

[](#version)

- **Version**: 2025-07-25
- **License**: MIT License
- **Copyright**: Copyright (C) 2025 Nice Creative Co., Ltd.

---

License
-------

[](#license)

MIT License

---

Author
------

[](#author)

- [簡盛弓 (Carter Chein)](https://www.facebook.com/shengkung)

---

Links
-----

[](#links)

- [奈思創藝網頁設計](http://www.nim.com.tw)

Star History
------------

[](#star-history)

If you find this project useful, please consider giving it a ⭐ on GitHub!

如果你覺得這個專案有用，請考慮在 GitHub 上給它一個星星！⭐

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance49

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/660d292d223212a9dee1b2d197ef9c0b939bb0a6216ba5e6878866a225adb71d?d=identicon)[shengkung](/maintainers/shengkung)

---

Top Contributors

[![shengkung](https://avatars.githubusercontent.com/u/10151286?v=4)](https://github.com/shengkung "shengkung (6 commits)")

### Embed Badge

![Health badge](/badges/shengkung-mdify/health.svg)

```
[![Health](https://phpackages.com/badges/shengkung-mdify/health.svg)](https://phpackages.com/packages/shengkung-mdify)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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