Markdown
extends BaseMarkdown
in package
Markdown provides an ability to transform markdown into HTML.
Basic usage is the following:
$myHtml = Markdown::process($myText); // use original markdown flavor
$myHtml = Markdown::process($myText, 'gfm'); // use github flavored markdown
$myHtml = Markdown::process($myText, 'extra'); // use markdown extra
You can configure multiple flavors using the [[$flavors]] property.
For more details please refer to the Markdown library documentation.
Note: The Markdown library works with PHPDoc annotations so if you use it together with PHP
opcache
make sure it does not strip comments.
Tags
Table of Contents
Properties
- $defaultFlavor : string
- $flavors : array<string|int, mixed>
Methods
- process() : string
- Converts markdown into HTML.
- processParagraph() : string
- Converts markdown into HTML but only parses inline elements.
- getParser() : Parser
Properties
$defaultFlavor
public
static string
$defaultFlavor
= 'original'
the markdown flavor to use when none is specified explicitly.
Defaults to original
.
Tags
$flavors
public
static array<string|int, mixed>
$flavors
= ['original' => ['class' => 'cebe\markdown\Markdown', 'html5' => true], 'gfm' => ['class' => 'cebe\markdown\GithubMarkdown', 'html5' => true], 'gfm-comment' => ['class' => 'cebe\markdown\GithubMarkdown', 'html5' => true, 'enableNewlines' => true], 'extra' => ['class' => 'cebe\markdown\MarkdownExtra', 'html5' => true]]
a map of markdown flavor names to corresponding parser class configurations.
Methods
process()
Converts markdown into HTML.
public
static process(string $markdown[, string|null $flavor = null ]) : string
Parameters
- $markdown : string
-
the markdown text to parse
- $flavor : string|null = null
-
the markdown flavor to use. See [[$flavors]] for available values. Defaults to [[$defaultFlavor]], if not set.
Tags
Return values
string —the parsed HTML output
processParagraph()
Converts markdown into HTML but only parses inline elements.
public
static processParagraph(string $markdown[, string|null $flavor = null ]) : string
This can be useful for parsing small comments or description lines.
Parameters
- $markdown : string
-
the markdown text to parse
- $flavor : string|null = null
-
the markdown flavor to use. See [[$flavors]] for available values. Defaults to [[$defaultFlavor]], if not set.
Tags
Return values
string —the parsed HTML output
getParser()
protected
static getParser(string|null $flavor) : Parser
Parameters
- $flavor : string|null
-
the markdown flavor to use. See [[$flavors]] for available values. Defaults to [[$defaultFlavor]], if not set.