PHP code example of helgesverre / markdown

1. Go to this page and download the library: Download helgesverre/markdown library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

helgesverre / markdown example snippets


use HelgeSverre\Markdown\Markdown;

$html = Markdown::toHtml("# Hello\n\n- a\n- b\n");

$htmls = Markdown::toHtmlBatch([
    "# One\n",
    "# Two\n",
]);

use HelgeSverre\Markdown\Data\Dialect;
use HelgeSverre\Markdown\Parser;

$parser = new Parser(
    dialect: Dialect::GitHub,
    safe: false,
    xhtml: false,
);

$html = $parser->toHtml("# Hello\n");

use HelgeSverre\Markdown\Markdown;

$doc = <<<MD
---
title: Hello World
tags: [php, markdown]
---
# Introduction

## Getting started
MD;

$result = Markdown::parse($doc);

$result->html;
$result->frontmatter; // ['title' => 'Hello World', 'tags' => ['php', 'markdown']]
$result->toc;         // [['level' => 1, 'text' => 'Introduction', 'slug' => 'introduction'], ...]
(string) $result;     // same as $result->html

use HelgeSverre\Markdown\Data\Dialect;
use HelgeSverre\Markdown\Parser;

new Parser(
    dialect: Dialect::GitHub, // or Dialect::CommonMark
    safe: true,               // strip raw HTML
    xhtml: true,              // emit <br /> / <hr />
);