-
Notifications
You must be signed in to change notification settings - Fork 86
/
MarkdownParser.php
45 lines (40 loc) · 887 Bytes
/
MarkdownParser.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
<?php
/**
* Module Name: MarkdownParser
* Module Description: Parse Markdown plaintext into HTML plaintext.
*
* @author Terry Lin
* @link https://terryl.in/
*
* @package Githuber
* @since 1.0.0
* @version 1.0.0
*/
namespace Githuber\Module;
use ParsedownExtra;
class MarkdownParser extends ParsedownExtra {
/**
* Constructer.
*/
public function __construct() {
parent::__construct();
}
/**
* Remove bare <p> elements. <p>s with attributes will be preserved.
*
* @param string $text HTML content.
* @return string <p>-less content.
*/
public function remove_bare_p_tags( $text ) {
return preg_replace( "#<p>(.*?)</p>(\n|$)#ums", '$1$2', $text );
}
/**
* Teansform Markdown to HTML.
*
* @param string $text Markdown content.
*/
public function transform( $text ) {
$parsed_content = $this->text( $text );
return $parsed_content;
}
}