fastvolt / markdown
A Fast, Simple and Straight-forward Markdown to HTML Converter for PHP.
Installs: 13 416
Dependents: 0
Suggesters: 0
Security: 0
Stars: 27
Watchers: 0
Forks: 2
Open Issues: 1
Requires
- php: ^8.1
- amphp/file: ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.4
This package is not auto-updated.
Last update: 2025-03-22 01:16:54 UTC
README
Markdown Parser For PHP
A Fast, Simple and Straight-forward Markdown to HTML Converter for PHP.
Installation
composer require fastvolt/markdown
Usage
<?php use FastVolt\Helper\Markdown; $sample = " ## Hello, World "; # init Markdown object $mkd = Markdown::new(); # set markdown data to convert $mkd -> setContent( $sample ); # convert data to markdown print $mkd -> toHtml(); // <h2>Hello, World</h2>
Convert Markdown File to Html
Assuming we created a sample.md
file in /assets
folder with the following markdown contents:
file: assets/sample.md
# Topic ## Sub-topic **Author:** __vincent__
file: index.php
<?php use FastVolt\Helper\Markdown; $file_directory = __DIR__ . '/assets/sample.md'; # init markdown object $mkd = Markdown::new(); # set markdown file $mkd -> setFile( $file_directory ); # convert to html print $mkd -> toHtml(); // output: <h1>Topic</h1> <h2> Sub-topic</h2> <b>Author:</b> <i>vincent</i>
Convert Markdown File to Html File
In order to achieve this, you need to create a folder to store the compiled markdown files.
➡️ If we've already set up directories named
pages
andfiles
with a file namedhello.md
in thefiles
directory, let's see how we can convert thehello.md
markdown file into an HTML file. Afterward, we will save the resulting HTML output in a new file namedhello.html
inpages
directory:
file: files/hello.md
### hello
file: index.php
use FastVolt\Helper\Markdown; # convert md file to html file $mkd = Markdown::new() # set markdown file to compile $mkd -> setFile( __DIR__ . '/files/hello.md' ) # set directory to store compiled html files $mkd -> setCompileDir( __DIR__ . '/pages/' ) # convert to html $mkd -> toHtmlFile( filename: 'hello' ); # check if markdown compile to html successfully if ($mkd) { print ("compile successful"); }
After above operation, you will get the following result:
file: pages/hello.html
<h3>hello</h3>
Requirements
- PHP 8.1
- that's all 😇.
Note
FastVolt's Markup Library is an extended/simplified version of Erusev's ParseDown Library.
Released under MIT License by @fastvolt.