1. Go to this page and download the library: Download wp-php-toolkit/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/ */
wp-php-toolkit / markdown example snippets
WordPress\Markdown\MarkdownConsumer;
$result = ( new MarkdownConsumer( "# Hello\n\nWelcome to **WordPress**." ) )->consume();
echo $result->get_block_markup();
WordPress\Markdown\MarkdownConsumer;
use WordPress\Markdown\MarkdownProducer;
$md = "## Round trip\n\n- one\n- two\n- three\n";
$blocks = ( new MarkdownConsumer( $md ) )->consume();
$markdown = ( new MarkdownProducer( $blocks ) )->produce();
echo $markdown;
WordPress\Markdown\MarkdownSourceDocument;
$source = <<<MD
# Title #
Keep __bold__ syntax.
Edit this sentence.
MD;
$document = MarkdownSourceDocument::from_markdown( $source );
$blocks = str_replace(
'<p>Edit this sentence.</p>',
'<p>Edit only this sentence.</p>',
$document->get_block_markup()
);
echo $document->patch_markdown( $blocks );
WordPress\Markdown\MarkdownConsumer;
$md = <<<MD
---
post_title: "The Name of the Wind"
post_status: publish
tags: [fantasy, kingkiller]
---
Once upon a time...
MD;
$consumer = new MarkdownConsumer( $md );
$consumer->consume();
echo 'Title: ' . $consumer->get_meta_value( 'post_title' ) . "\n";
echo 'Status: ' . $consumer->get_meta_value( 'post_status' ) . "\n";
$metadata = $consumer->get_all_metadata();
echo 'Tags: ' . implode( ', ', $metadata['tags'][0] ) . "\n";