PHPackages                             walter-a-jablonowski/parsedown-user-styles - 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. walter-a-jablonowski/parsedown-user-styles

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

walter-a-jablonowski/parsedown-user-styles
==========================================

User defined syntax for ParsedownExtra

07PHPCI failing

Since Feb 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/walter-a-jablonowski/parsedown-user-styles)[ Packagist](https://packagist.org/packages/walter-a-jablonowski/parsedown-user-styles)[ RSS](/packages/walter-a-jablonowski-parsedown-user-styles/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Parsedown User Styles
=====================

[](#parsedown-user-styles)

**User defined syntax for ParsedownExtra**

Define whatever syntax you want... using a minimalistic PHP class. Also capable of running PHP embedded in md. Use it for calculations, dynamic content, ...

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

> If you like visit my personal homepage: [walter-a-jablonowski.github.io](https://walter-a-jablonowski.github.io)

Usage
-----

[](#usage)

See also running demo in /demo

```
composer require walter-a-jablonowski/parsedown-user-styles

```

Include your stylesheets if you have class names in replace html.

Define whatever syntax you want, these are just for demo. Using [Symfony yaml](https://symfony.com/doc/current/components/yaml) here.

```
$md = new ParsedownUserStyles();  // pass $userdata if needed (see third style below)

// use parsedown's methods as needed

$md->setStyles( Yaml::parse( file_get_contents( ... )) );  // get your styles.yml
$mdString = $md->text( ... );
```

**Define styles**

styles.yml

```
Unique - name:        # Each style can have a name and multiple replacements

  -                   # Simple str replace
    find:    "[["
    replace: ""
  -
    find:    "]]"
    replace: ""

Unique - name 2:     # regex version

  -
    regFind: "\\{Img:\\s*(.*)\\}"
    replace: ""

Unique - name 5:     # Use of anonymous function
                     # $found is result of preg_match_all() with SET ORDER (no OFFSET CAPTURE)
  -
    regFind: "\\{Url:\\s*([^\\s]*)\\s*(.*)\\}"
    do: |

      function( $text, $found, $userdata = [] ) {

        // do something with $found
        // replace in $text

        foreach( $found as $f )
        {
          $fullStr = $f[0];
          $label   = $f[1];
          $url     = $f[2];

          $s = str_replace( "[URL]",   "http://" . $url, "[LABEL]" );
          $s = str_replace( "[LABEL]", $label, $s );

          $text = str_replace( $fullStr, $s, $text );
        }

        return $text;
      }
```

### Embed PHP in md

[](#embed-php-in-md)

Just include PHP code inside normal PHP tags

```
# My markdown
