PHPackages                             atk14/drink-markdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. atk14/drink-markdown

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

atk14/drink-markdown
====================

Extended PHP Markdown parser tuned for usage in ATK14 projects

v0.8.10(3mo ago)135.6k—0%14MITPHPPHP &gt;=5.3.0

Since Mar 2Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/atk14/DrinkMarkdown)[ Packagist](https://packagist.org/packages/atk14/drink-markdown)[ Docs](https://github.com/atk14/DrinkMarkdown)[ RSS](/packages/atk14-drink-markdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (33)Used By (4)

DrinkMarkdown
=============

[](#drinkmarkdown)

Extended PHP Markdown parser tuned for usage in ATK14 projects. It's built on Michel Fortin's PHP Markdown Extra.

Originally it was developed for the project "Doctor Ink" (shortly "Drink").

Beware! It is in alpha state. It has some interconnections to the ATK14 Framework thus it can't be easily used in other projects.

Features
--------

[](#features)

DrinkMarkdown extends PHP Markdown Extra to:

- automatically converting URL and email text to clickable links
- providing optional HTML purification
- providing source code syntax highlighting
- table rendering improved
- iobjects (to be explained)

Basic Usage
-----------

[](#basic-usage)

```
$dm = new DrinkMarkdown([
  "table_class" => "table", // the CSS class for tables, default is "table table-bordered table-hover"
  "html_purification_enabled" => true, // default is true
  "temp_dir" => "/path/to/temp", // default is constant TEMP or sys_get_temp_dir()
  "iobjects_processing_enabled" => true, // insertable objects processing, default is true
  "urlize_text" => true, // reconstruct missing links to urls or emails? default is true
  "shortcodes_enabled" => true, // whether to enable or disable processing of shortcodes, default is true
  "shortcode_autowiring_enabled" => true, // Smarty shortcodes are being registered automatically
]);

$html = $dm->transform($markdown);

```

Usage in a ATK14 template
-------------------------

[](#usage-in-a-atk14-template)

DrinkMarkdown package comes with two helpers usables in ATK14 templates.

If you have a trusted content:

```
{$text|markdown nofilter} {* or *}
{!$text|markdown}

```

If you have an insecure content, e.g. a comment from a user:

```
{$comment|safe_markdown nofilter} {* or *}
{!$comment|safe_markdown}

```

Shortcodes
----------

[](#shortcodes)

DrinkMarkdown can be extended with extensions: so called shortcodes.

There are three types of shortcodes:

- block shortcodes,
- inline block shortcodes and
- function shortcodes.

Rendering of shortcodes is either provided callback functions or by Smarty (template engine used in ATK14 framework) plugins. Block shortcodes corresponds to Smarty block plugins, function shortcodes corresponds to Smarty function plugins. The difference between block and inline block shortcodes is that block shortcodes affect whole paragraphs, but inline block shortcodes can operate inside paragraphs or sentences.

### Built-in shortcodes

[](#built-in-shortcodes)

DrinkMarkdown contains block shortcodes for organizing text into columns.

```
[row]

[col]
### Column 1
This is text of the first column.
[/col]

[col]
### Column 2
This is text of the second column.
[/col]

[col]
### Column 3
This is text of the third column.
[/col]

[/row]

```

See a living example at

Shortcode *div* renders

 element with given attributes. Unlike direct usage of the HTML element div, markdown syntax is being interpreted inside the shortcode.```
[div class="teaser" id="id_teaser"]

## Hello World!

Welcome to this very nice place.

[/div]

```

Inline block shortcode *span* renders  element with given attributes. Again, markdown syntax is being interpreted inside the shortcode.

```
## Hello [span class="world"]World[/span]!

Welcome to this very nice place.

```

### Custom shortcodes

[](#custom-shortcodes)

```
$dm = new DrinkMarkdown();

```

#### 1. Callbacks

[](#1-callbacks)

```
$dm->registerBlockShortcode("alert", function($columns,$params){
  $params += [
    "type" => "primary"
  ];
  return "$content";
});

$dm->registerInlineBlockShortcode("upper", function($content,$params){ return strtoupper($content); });

$dm->registerFunctionShortcode("name", function($params){
  $params += [
    "gender" => "male"
  ];
  return $params["gender"]=="female" ? "Samantha Doe" : "John Doe";
});

```

#### 2. Smarty plugins

[](#2-smarty-plugins)

```
$dm->registerBlockShortcode("alert");
$dm->registerInlineBlockShortcode("upper");
$dm->registerFunctionShortcode("name");

```

If no callback is specified during a shortcode registration, an appropriate Smarty plugin is required. Note the naming conventions of plugins.

```
