{"id":46314876,"url":"https://github.com/fastvolt/markdown","last_synced_at":"2026-03-04T14:02:12.837Z","repository":{"id":205866598,"uuid":"715244986","full_name":"fastvolt/markdown","owner":"fastvolt","description":"A Fast, Simple and Straight-forward Markdown Parser and Markdown to HTML Converter for PHP.","archived":false,"fork":false,"pushed_at":"2025-11-12T00:00:44.000Z","size":146,"stargazers_count":44,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"v0.3.0","last_synced_at":"2025-11-12T00:18:52.871Z","etag":null,"topics":["markdown","markdown-converter","markdown-it","markdown-parser","markdown-to-html","php","php-markdown","php-markdown-parser"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fastvolt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-11-06T18:54:08.000Z","updated_at":"2025-11-12T00:00:48.000Z","dependencies_parsed_at":"2024-08-28T23:25:55.252Z","dependency_job_id":"016719d8-e6b4-4d98-8823-e9ac47eda4ba","html_url":"https://github.com/fastvolt/markdown","commit_stats":null,"previous_names":["fastvolt/markdown"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/fastvolt/markdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastvolt%2Fmarkdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastvolt%2Fmarkdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastvolt%2Fmarkdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastvolt%2Fmarkdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastvolt","download_url":"https://codeload.github.com/fastvolt/markdown/tar.gz/refs/heads/v0.3.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastvolt%2Fmarkdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30083004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T13:22:36.021Z","status":"ssl_error","status_checked_at":"2026-03-04T13:20:45.750Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markdown","markdown-converter","markdown-it","markdown-parser","markdown-to-html","php","php-markdown","php-markdown-parser"],"created_at":"2026-03-04T14:02:12.102Z","updated_at":"2026-03-04T14:02:12.771Z","avatar_url":"https://github.com/fastvolt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/fastvolt/markdown\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://github.com/fastvolt/branding/blob/1c5280745d9c671313f319b7f07d6706a9f75ea9/media/images/fast-mrk.png\" alt=\"Fastvolt\" width=\"160\" height=\"160\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003ch1 align=\"center\"\u003eMarkdown Parser for PHP\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eA fast, simple, and straightforward Markdown to HTML converter for PHP.\u003c/strong\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/fastvolt/markdown/actions/workflows/validator1.yml\"\u003e\n    \u003cimg src=\"https://github.com/fastvolt/markdown/actions/workflows/validator1.yml/badge.svg\" alt=\"PHP Composer\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"#license\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow\" alt=\"License: MIT\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/fastvolt/markdown/issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/fastvolt/markdown\" alt=\"GitHub Issues\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/fastvolt/markdown\"\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=fastvolt\u0026message=markdown\u0026color=yellow\u0026logo=github\" alt=\"Repo\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/maintained-yes-blue\" alt=\"Maintained: Yes\" /\u003e\n\u003c/p\u003e\n\n\n## 🚀 Installation\n\n```sh\ncomposer require fastvolt/markdown\n```\n\n\u003cbr\u003e\n\n## 📦 Basic Usage\n\n```php\nuse FastVolt\\Helper\\Markdown;\n\n$text = \"## Hello, World\";\n\n// Initialize the parser\n$markdown = new Markdown(); // or Markdown::new()\n\n// set markdown content \n$markdown-\u003esetContent($text);\n\n// compile and get as raw HTML\necho $markdown-\u003egetHtml();\n```\n\n#### Output:\n\n```html\n\u003ch2\u003eHello, World\u003c/h2\u003e\n```\n\n\u003cbr\u003e\n\n## 📄 Convert Markdown File to Raw HTML\n\n\u003e ***sample.md:***\n\n```md\n#### Heading 4\n### Heading 3\n## Heading 2\n# Heading 1\n\n- List 1\n- List 2\n\n\u003e THIS IS A BLOCKQUOTE\n\n[A LINK](https://github.com/fastvolt)\n```\n\n\n\u003e ***index.php:***\n\n```php\n$markdown = Markdown::new();\n\n// add markdown file to parse \n$markdown-\u003eaddFile(__DIR__ . '/sample.md');\n\n// compile and get as raw html\necho $markdown-\u003egetHtml();\n```\n\n\u003e ***Output:***\n\n```html\n\u003ch4\u003eHeading 4\u003c/h4\u003e\n\u003ch3\u003eHeading 3\u003c/h3\u003e\n\u003ch2\u003eHeading 2\u003c/h2\u003e\n\u003ch1\u003eHeading 1\u003c/h1\u003e\n\u003cul\u003e\n  \u003cli\u003eList 1\u003c/li\u003e\n  \u003cli\u003eList 2\u003c/li\u003e\n\u003c/ul\u003e\n\u003cblockquote\u003e\u003cp\u003eTHIS IS A BLOCKQUOTE\u003c/p\u003e\u003c/blockquote\u003e\n\u003ca href=\"https://github.com/fastvolt\"\u003eA LINK\u003c/a\u003e\n```\n\n\u003cbr\u003e\n\n## 📝 Convert Markdown File to An HTML File\n\n\u003e ***blogPost.md:***\n\n```md\nHere is a Markdown File Waiting To Be Compiled To an HTML File\n```\n\n\u003e ***index.php:***\n\n```php\n\n$markdown = Markdown::new()\n    // add markdown file\n    -\u003eaddFile(__DIR__ . '/blogPost.md')\n\n    // add output directory\n    -\u003eaddOutputDirectory(__DIR__ . '/pages/')\n\n    // compile as an html file\n    -\u003esaveToHtmlFile(filename: 'index.html');\n\nif ($markdown) {\n  echo \"Compiled to ./pages/index.html\";\n}\n\n```\n\n\u003cbr\u003e\n\n## Convert Directory to HTML Directory Structure\n\nThis compiles all `.md` files in a source directory into a mirrored structure of `.html` files in an output directory.\n\n```php\nuse FastVolt\\Helper\\Markdown;\nuse FastVolt\\Helper\\Markdown\\Enums\\MarkdownEnum;\n\n$markdown = Markdown::new()\n    // Set the source directory to read all .md files from (including sub-directories)\n    -\u003esetSourceDirectory(__DIR__ . '/docs/')\n    \n    // Set the output directory to compile the mirrored HTML structure to (Alias: -\u003esetCompileDir())\n    -\u003eaddOutputDirectory(__DIR__ . '/public/')\n    \n    // Run the directory conversion process\n    -\u003erun(MarkdownEnum::TO_HTML_DIRECTORY);\n\nif ($markdown) {\n    echo \"Directory conversion successful!\";\n}\n\n// If '/docs/guide/*.md' exists, it creates '/public/guide/*.html'.\n```\n\n\u003cbr\u003e\n\n## Single Point Execution\n\nThis is the universal executor that can operate in three different modes using the `MarkdownEnum` enum and `run` method.\n\n### Interface\n\n```php\n  run(\n    MarkdownEnum $as, \n    ?string $fileName\n  ): mixed;\n```\n\n### MarkdownEnum Interface\n\n```php\nenum MarkdownEnum \n{\n  // convert markdown source to raw html (raw/file =\u003e raw html)\n  case TO_HTML;\n\n  // convert markdown source to an html file (markdown raw/file =\u003e html file)\n  case TO_HTML_FILE;\n\n  // convert markdown source directory to html directory (markdown directory =\u003e html directory)\n  case TO_HTML_DIRECTORY;\n}\n```\n\n### Usage Examples\n\n#### Using The `MarkdownEnum::TO_HTML` Enum\n\u003e This is an alternative way to call `getHtml()`.\n\n```php\nMarkdown::new()\n    -\u003esetContent('# Heading 1')\n    -\u003erun(MarkdownEnum::TO_HTML);\n```\n\n#### Using The `MarkdownEnum::TO_HTML_FILE` Enum\n\u003e This is an alternative way to call `saveToHtmlFile()`.\n\n```php\nMarkdown::new()\n    -\u003eaddOutputDirectory(__DIR__ . '/build')\n    -\u003erun(MarkdownEnum::TO_HTML_FILE, 'index.html');\n```\n\n#### Using The `MarkdownEnum::TO_HTML_DIRECTORY` Enum\n\u003e This is the only method that uses `setSourceDirectory()`. It crawls the source directory, converts all .md files, and saves them (preserving the folder structure) to the output directory.\n\n```php\nMarkdown::new()\n    -\u003esetSourceDirectory(__DIR__ . '/src/my-docs')\n    -\u003eaddOutputDirectory(__DIR__ . '/public/docs')\n    -\u003erun(MarkdownEnum::TO_HTML_DIRECTORY);\n```\n\n\u003cbr\u003e\n\n## 🔒 Sanitizing HTML Output (XSS Protection)\n\nYou can sanitize input HTML and prevent cross-site scripting (XSS) attack using the `sanitize` flag.\n\n\u003e `$sanitize`: Set to `true` (default) to escape HTML tags in the Markdown. Set to `false` only if you completely trust the source of your Markdown and need raw HTML to be rendered.\n\n```php\n$markdown = Markdown::new(\n  sanitize: true\n);\n\n$markdown_unsafe = Markdown::new(\n  sanitize: false\n);\n\n$content = '\u003ch1\u003eHello World\u003c/h1\u003e';\n\necho $markdown\n  -\u003esetContent($content)\n  -\u003egetHtml();\n\necho $markdown_unsafe\n  -\u003esetContent($content)\n  -\u003egetHtml();\n```\n\n\u003e ***Output:***\n\n```html\nSanitize Enabled: \u003cp\u003e\u0026lt;h1\u0026gt;Hello World\u0026lt;/h1\u0026gt;\u003c/p\u003e\n\nSanitize Disabled: \u003ch1\u003eHello World\u003c/h1\u003e\n```\n\n\u003cbr\u003e\n\n## ⚙️ Advanced Use Case\n\n### Inline Markdown\n```php\n$markdown = Markdown::new();\n\n$markdown-\u003esetInlineContent('_My name is **vincent**, the co-author of this blog_');\n\necho $markdown-\u003egetHtml();\n```\n\n\u003e ***Output:***\n\n```html\n\u003ci\u003eMy name is \u003cstrong\u003evincent\u003c/strong\u003e, the co-author of this blog\u003c/i\u003e\n```\n\n\u003e ***NOTE:*** Some markdown symbols are not supported with this method\n\n\u003cbr\u003e\n\n### Example #1\nCombine multiple markdown files, contents and compile them in multiple directories:\n\n\u003e ***Header.md***\n```md\n# Blog Title  \n### Here is the Blog Sub-title\n```\n\n\u003e ***Footer.md***\n```md\n### Thanks for Visiting My BlogPage\n```\n\n\u003e ***index.php***\n\n```php\n$markdown = Markdown::new(sanitize: true)\n    // include header file's markdown contents\n    -\u003eaddFile('./Header.md')\n    // body contents\n    -\u003esetInlineContent('_My name is **vincent**, the co-author of this blog_')\n    -\u003esetContent('Kindly follow me on my GitHub page via: [@vincent](https://github.com/oladoyinbov).')\n    -\u003esetContent('Here are the lists of my projects:')\n    -\u003esetContent('\n- Dragon CMS\n- Fastvolt Framework.\n  + Fastvolt Router\n  + Markdown Parser.\n    ')\n    // include footer file's markdown contents\n    -\u003eaddFile(__DIR__ . '/Footer.md')\n    \n    // add the main compilation directory \n    -\u003eaddOutputDirectory(__DIR__ . '/pages/')\n    \n    // add another compilation directory to backup the result\n    -\u003eaddOutputDirectory(__DIR__ . '/backup/pages/')\n\n    // compile and store as 'index.html'\n    -\u003esaveToHtmlFile(file_name: 'index.html');\n\nif ($markdown) {\n  echo \"Compile Successful. Files created in /pages/ and /backup/pages/\";\n}\n```\n\n\u003e ***Output:*** `pages/index.html`, `backup/pages/index.html`\n\n```html\n\u003ch1\u003eBlog Title\u003c/h1\u003e\n\u003ch3\u003eHere is the Blog Sub-title\u003c/h3\u003e\n\u003ci\u003eMy name is \u003cstrong\u003evincent\u003c/strong\u003e, the co-author of this blog\u003c/i\u003e\n\u003cp\u003eKindly follow me on my github page via: \u003ca href=\"https://github.com/oladoyinbov\"\u003e@vincent\u003c/a\u003e.\u003c/p\u003e\n\u003cp\u003eHere are the lists of my projects:\u003c/p\u003e\n\u003cul\u003e\n  \u003cli\u003eDragon CMS\u003c/li\u003e\n  \u003cli\u003eFastvolt Framework.\n    \u003cul\u003e\n      \u003cli\u003eFastvolt Router\u003c/li\u003e\n      \u003cli\u003eMarkdown Parser.\u003c/li\u003e\n    \u003c/ul\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n\u003ch3\u003eThanks for Visiting My BlogPage\u003c/h3\u003e\n```\n\n\u003cbr\u003e\n\n## Error Handling\nThe parser uses custom exceptions for clarity:\n\n- `MarkdownFileNotFound`: Thrown when a file specified in `addFile()` or a directory in `setSourceDirectory()` does not exist.\n- `LogicException`: Thrown if you try to execute a conversion (`getHtml()` or `saveToHtmlFile()`) before any content (setContent, addFile, etc.) has been added to the queue.\n- `RuntimeException`: Thrown if the system fails to create an output directory (mkdir fails) or if a required directory is missing during run() execution.\n\n\u003cbr\u003e\n\n\n## 🧠 Interface Method Reference\n\nThe parser uses a fluent (chainable) API. This is your command cheatsheet for configuration and execution:\n\n| Method Name | Return Type | Description |\n| :--- | :--- | :--- |\n| `::new(bool $sanitize = true)` | `self` | **Initialize** the parser instance. The preferred static factory method. |\n| `-\u003esetSourceDirectory(string $name)` | `static` | Sets the **input root directory** for whole-directory compilation. |\n| `-\u003esetContent(string $content)` | `static` | Adds **multi-line** Markdown content (supports lists, headings, etc.) to the queue. |\n| `-\u003esetInlineContent(string $content)` | `static` | Adds **single-line** Markdown content (*bold*, **italic**) to the queue. |\n| `-\u003eaddFile(string $fileName)` | `static` | Adds a single Markdown file path to the compilation queue. *(Alias: `-\u003esetFile()`)* |\n| `-\u003eaddMultipleFiles(array $names)` | `static` | Adds an array of Markdown file paths to the compilation queue. |\n| `-\u003eaddOutputDirectory(string $dir)` | `static` | Adds a directory where the compiled HTML will be saved. Allows multiple targets. *(Alias: `-\u003esetCompileDir()`)* |\n| `-\u003eaddMultipleOutputDirectories(array $dirs)` | `static` | Adds an array of directories where the compiled HTML will be saved. |\n| `-\u003egetHtml()` | `string\\|null` | **Execute** compilation and return the raw HTML string. *(Alias: `-\u003etoHtml()`)* |\n| `-\u003esaveToHtmlFile(string $name)` | `bool` | **Execute** compilation and write the output to the specified HTML file(s). *(Alias: `-\u003etoHtmlFile()`)* |\n| `-\u003erun(MarkdownEnum $as, ?string $file)` | `mixed` | Universal command to execute conversion based on the specified `MarkdownEnum` target. |\n\n\u003cbr\u003e\n\n## Supported Formatting Symbols \n\n| Markdown Syntax              | Description                 | Example Syntax                           | Rendered Output                        |\n|-----------------------------|-----------------------------|-------------------------------------------|----------------------------------------|\n| `#` to `######`             | Headings (H1–H6)            | `## Heading 2`                            | \u003ch2\u003eHeading 2\u003c/h2\u003e                     |\n| `**text**` or `__text__`    | Bold                        | `**bold**`                                | \u003cstrong\u003ebold\u003c/strong\u003e                  |\n| `*text*` or `_text_`        | Italic                      | `*italic*`                                | \u003cem\u003eitalic\u003c/em\u003e                        |\n| `~~text~~`                  | Strikethrough               | `~~strike~~`                              | \u003cdel\u003estrike\u003c/del\u003e                      |\n| `` `code` ``                | Inline code                 | `` `echo` ``                              | \u003ccode\u003eecho\u003c/code\u003e                      |\n| \u003ccode\u003e```\u003cbr\u003ecode block\u003cbr\u003e```\u003c/code\u003e | Code block              | ```` ```php\\n echo \"Hi\"; \\n``` ````       | `\u003cpre\u003e\u003ccode\u003e...\u003c/code\u003e\u003c/pre\u003e`          |\n| `-`, `+`, or `*`            | Unordered list              | `- Item 1`\u003cbr\u003e`* Item 2`                  | `\u003cul\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ul\u003e`              |\n| `1.` `2.`                   | Ordered list                | `1. Item`\u003cbr\u003e`2. Item`                    | `\u003col\u003e\u003cli\u003eItem\u003c/li\u003e\u003c/ol\u003e`              |\n| `[text](url)`               | Hyperlink                   | `[GitHub](https://github.com)`           | \u003ca href=\"https://github.com\"\u003eGitHub\u003c/a\u003e |\n| `\u003e blockquote`              | Blockquote                  | `\u003e This is a quote`                      | \u003cblockquote\u003eThis is a quote\u003c/blockquote\u003e |\n| `---`, `***`, `___`         | Horizontal Rule             | `---`                                     | `\u003chr\u003e`                                |\n| `![alt](image.jpg)`         | Image                       | `![Logo](logo.png)`                      | `\u003cimg src=\"logo.png\" alt=\"Logo\"\u003e`     |\n| `\\`                         | Escape special character    | `\\*not italic\\*`                          | *not italic* (as text)                |\n\n\u003cbr\u003e\n\n## ✅ Requirements\n\nPHP 8.1 or newer.\n\n\u003cbr\u003e\n\n## ℹ️ Notes\n\n\u003e This library is an extended and simplified version of the excellent [Parsedown](https://github.com/erusev/parsedown/) by Erusev.\n\n\u003cbr\u003e\n\n## 📄 License\n\nThis project is open-source and licensed under the MIT License by @fastvolt.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastvolt%2Fmarkdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastvolt%2Fmarkdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastvolt%2Fmarkdown/lists"}