PHP code example of inwebo / markdown

1. Go to this page and download the library: Download inwebo/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/ */

    

inwebo / markdown example snippets




declare(strict_types=1);

use Inwebo\Markdown\Model\Enum\NodeType;
use Inwebo\Markdown\Parser;
use Inwebo\Markdown\Token\Token;
use Inwebo\Markdown\Html\Block\Blockquote;
use Inwebo\Markdown\Html\Block\H1;
use Inwebo\Markdown\Html\Block\H2;
use Inwebo\Markdown\Html\Block\H3;
use Inwebo\Markdown\Html\Block\H4;
use Inwebo\Markdown\Html\Block\H5;
use Inwebo\Markdown\Html\Block\H6;
use Inwebo\Markdown\Html\Block\Hr;
use Inwebo\Markdown\Html\Block\Ol;
use Inwebo\Markdown\Html\Block\Paragraph;
use Inwebo\Markdown\Html\Block\Ul;
use Inwebo\Markdown\Html\Inline\Bold;
use Inwebo\Markdown\Html\Inline\Image;
use Inwebo\Markdown\Html\Inline\Italic;
use Inwebo\Markdown\Html\Inline\Link;
use Inwebo\Markdown\Html\Inline\Strikethrough;
use Inwebo\Markdown\Html\TagFactory;
use Inwebo\Markdown;

        $parser = new Parser(
            new Token(NodeType::PARAGRAPH),
            new Token(NodeType::UL),
            new Token(NodeType::OL),
            new Token(NodeType::HR),
            new Token(NodeType::H1),
            new Token(NodeType::H2),
            new Token(NodeType::H3),
            new Token(NodeType::H4),
            new Token(NodeType::H5),
            new Token(NodeType::H6),
            new Token(NodeType::BLOCKQUOTE),
            new Token(NodeType::BOLD),
            new Token(NodeType::ITALIC),
            new Token(NodeType::STRIKETHROUGH),
            new Token(NodeType::LINK),
            new Token(NodeType::IMAGE),
        );

        $tagFactory = new TagFactory(
            new Paragraph(),
            new H1(),
            new H2(),
            new H3(),
            new H4(),
            new H5(),
            new H6(),
            new Ul(),
            new Ol(),
            new Hr(),
            new Blockquote(),
            new Strikethrough(),
            new Bold(),
            new Italic(),
            new Link(),
            new Image(),
        );

        $factory = new Markdown\Factory($parser, $tagFactory);
        
        $html = $factory->render('# Hello World!');
        echo $html; // <h1>Hello World!</h1>