1. Download PHP Markdown Libraries, uncompress and into directory.
1. Add plugin file “markdown-wb.php”.
1. Be placed to plugins folder and activate.
Use three libraries:
Name | Version
-|-
[PHP Markdown Lib](https://michelf.ca/projects/php-markdown/) | 1.7.0
[cebe/markdown](http://markdown.cebe.cc/) | 1.1.3
[Parsedown](http://parsedown.org/) | 1.6.0
markdown-wb.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
<?php /* Plugin Name: Markdown-WB Plugin URI: Description: Call PHP Markdown Library from WordPress. Author: Donate link: Version: 1.0.0 Author URI: */ define('MDLIB_PHP', 101); define('MDLIB_CEBE', 102); define('MDLIB_PD', 103); define('MDTYPE_MD', 201); define('MDTYPE_EX', 202); define('MDTYPE_GIT', 203); function markdownWb($content) { // select library and markdown type /* $lib = MDLIB_PHP; $lib = MDLIB_CEBE; */ $lib = MDLIB_PD; /* $type = MDTYPE_MD; $type = MDTYPE_EX; */ $type = MDTYPE_GIT; //$use_nbsp = true; $use_nbsp = false; return markdownWbBranch($content, $lib, $type, $use_nbsp); } function markdownWbBranch($content, $lib = MDLIB_PD, $type = MDTYPE_EX, $use_nbsp = true) { if ($use_nbsp) { $content = leadingSpaceToNbsp($content); } if ($lib == MDLIB_PHP) { if ($type == MDTYPE_MD) { require_once 'Michelf/Markdown.inc.php'; $parser = new Michelf\Markdown; } else if ($type == MDTYPE_EX) { require_once 'Michelf/MarkdownExtra.inc.php'; $parser = new Michelf\MarkdownExtra; } $content = $parser->transform($content); } else if ($lib == MDLIB_CEBE) { require_once 'cebe/Parser.php'; require_once 'cebe/block/CodeTrait.php'; require_once 'cebe/block/HeadlineTrait.php'; require_once 'cebe/block/HtmlTrait.php'; require_once 'cebe/block/ListTrait.php'; require_once 'cebe/block/QuoteTrait.php'; require_once 'cebe/block/RuleTrait.php'; require_once 'cebe/inline/CodeTrait.php'; require_once 'cebe/inline/EmphStrongTrait.php'; require_once 'cebe/inline/LinkTrait.php'; require_once 'cebe/block/TableTrait.php'; require_once 'cebe/block/FencedCodeTrait.php'; require_once 'cebe/inline/StrikeoutTrait.php'; require_once 'cebe/inline/UrlLinkTrait.php'; require_once 'cebe/Markdown.php'; if ($type == MDTYPE_MD) { $parser = new cebe\markdown\Markdown; } else if ($type == MDTYPE_EX) { require_once 'cebe/MarkdownExtra.php'; $parser = new cebe\markdown\MarkdownExtra; } else if ($type == MDTYPE_GIT) { require_once 'cebe/GithubMarkdown.php'; $parser = new cebe\markdown\GithubMarkdown; } $content = $parser->parse($content); } else if ($lib == MDLIB_PD) { require_once 'Parsedown/Parsedown.php'; $parser = new Parsedown; $content = $parser->text($content); } return $content; } function leadingSpaceToNbsp($content) { preg_match_all('/^\s+/um', $content, $matches, PREG_OFFSET_CAPTURE); if ($matches) { $matches0 = $matches[0]; $len = count($matches0) - 1; for ($i = $len; $i >= 0; $i--) { $match = $matches0[$i]; $content = substr_replace($content, str_replace(' ', "\xc2\xa0", $match[0]), $match[1], strlen($match[0])); // replace leading spaces to } } return $content; } add_filter('the_content', 'markdownWb', 2); add_filter('get_the_excerpt', 'markdownWb', 2); // if you need? |
—
Directory Tree:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/wp-content/plugins/markdown-wb/ ├── Michelf │ ├── Markdown.inc.php │ ├── Markdown.php │ ├── MarkdownExtra.inc.php │ ├── MarkdownExtra.php │ ├── MarkdownInterface.inc.php │ └── MarkdownInterface.php ├── Parsedown │ ├── LICENSE.txt │ ├── Parsedown.php │ ├── README.md │ └── composer.json ├── cebe │ ├── GithubMarkdown.php │ ├── Markdown.php │ ├── MarkdownExtra.php │ ├── Parser.php │ ├── bin │ │ └── markdown │ ├── block │ │ ├── CodeTrait.php │ │ ├── FencedCodeTrait.php │ │ ├── HeadlineTrait.php │ │ ├── HtmlTrait.php │ │ ├── ListTrait.php │ │ ├── QuoteTrait.php │ │ ├── RuleTrait.php │ │ └── TableTrait.php │ ├── inline │ │ ├── CodeTrait.php │ │ ├── EmphStrongTrait.php │ │ ├── LinkTrait.php │ │ ├── StrikeoutTrait.php │ │ └── UrlLinkTrait.php └── markdown-wb.php |