-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathminiMarkdown.php
More file actions
53 lines (37 loc) · 1.05 KB
/
miniMarkdown.php
File metadata and controls
53 lines (37 loc) · 1.05 KB
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
<?php
/**
*
* miniMarkdown
* author: STNDC
* web: https://stndc.github.io
* version: 2.0.x
*
* @param string $text
*
*/
function minimarkdown($text){
// H1
$text = preg_replace('/^# (.+)$/m', '<h1>$1</h1>', $text);
// H2
$text = preg_replace('/^## (.+)$/m', '<h2>$1</h2>', $text);
// H3
$text = preg_replace('/^### (.+)$/m', '<h3>$1</h3>', $text);
// Italic
$text = preg_replace('/\_(.+)\_/', '<em>$1</em>', $text);
// Bold
$text = preg_replace('/\*\*(.+)\*\*/', '<strong>$1</strong>', $text);
// Code
$text = preg_replace('/`(.+)`/', '<code>$1</code>', $text);
// Positive
$text = preg_replace('/\+\+(.+)\+\+/', '<span class="positive">$1</span>', $text);
// Negative
$text = preg_replace('/\-\-(.+)\-\-/', '<span class="negative">$1</span>', $text);
// Image
$text = preg_replace('/\!\[(.+)\]\((.+)\)/', '<img src="$2" alt="$1">', $text);
// Link
$text = preg_replace('/\[(.+)\]\((.+)\)/', '<a href="$2">$1</a>', $text);
// Email
$text = preg_replace('/\[email\](.+)\[\/email\]/', '<a href="mailto:$1">$1</a>', $text);
return $text;
}
?>