-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Usage
ab25 edited this page Oct 30, 2021
·
20 revisions
Basic usage:
echo Parsedown::instance()->text('Hello _Parsedown_!'); # would print <p>Hello <em>Parsedown</em>!</p>
This would also work:
$Parsedown = new Parsedown();
echo $Parsedown->text('Hello _Parsedown_!'); # would print <p>Hello <em>Parsedown</em>!</p>
Parse inline elements (instead of both block-level and inline elements):
echo Parsedown::instance()->line('Hello _Parsedown_!'); # would print Hello <em>Parsedown</em>!
Set options:
echo Parsedown::instance()
->setBreaksEnabled(true) # enables automatic line breaks
->text("1st line \n 2nd line");
# Output:
# <p>1st line <br /> 2nd line</p>
echo Parsedown::instance()
->setMarkupEscaped(true) # escapes markup (HTML)
->text("<div><strong>*Some text*</strong></div>");
# Output:
# <p><div><strong><em>Some text</em><s;/strong></div></p>
echo Parsedown::instance()
->setUrlsLinked(false) # prevents automatic linking of URLs
->text("You can find Parsedown at http://parsedown.org");
# Output:
# <p>You can find Parsedown at http://parsedown.org</p>
To open a file:
include('Parsedown.php');
$file = file_get_contents('FILE.md');
$Parsedown = new Parsedown();
echo $Parsedown->text($file);
# Output: *Whatever content your file has inside!*
# *I used this tutorial to learn this: (https://dcblog.dev/reading-markdown-files-with-parsedown) *