md
This commit is contained in:
parent
a74b3ef90b
commit
62aea1726e
2 changed files with 35 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
require("../libs/page.php");
|
require("../libs/page.php");
|
||||||
require("../libs/form.php");
|
require("../libs/form.php");
|
||||||
|
require("../libs/markdown.php");
|
||||||
|
|
||||||
$ref = 1732684297;
|
$ref = 1732684297;
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@
|
||||||
</b></div>
|
</b></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<pre><?php echo htmlspecialchars($post['content']) ?></pre>
|
<pre><?php echo markdown(htmlspecialchars($post['content'])) ?></pre>
|
||||||
</div>
|
</div>
|
||||||
<?php }
|
<?php }
|
||||||
page_footer();
|
page_footer();
|
||||||
|
|
33
libs/markdown.php
Normal file
33
libs/markdown.php
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
function markdown($text) {
|
||||||
|
$search = array (
|
||||||
|
'~(?:\s|^)(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
|
||||||
|
'~(?:@)([^\s]+)(?:\s|$)~i',
|
||||||
|
'~(\[b\])(.*?)(\[\/b\])~i',
|
||||||
|
'~(\[i\])(.*?)(\[\/i\])~i',
|
||||||
|
'~(\[u\])(.*?)(\[\/u\])~i',
|
||||||
|
'~(\[ul\])(.*?)(\[\/ul\])~i',
|
||||||
|
'~(\[li\])(.*?)(\[\/li\])~i',
|
||||||
|
'~(\[h\])(.*?)(\[\/h\])~i',
|
||||||
|
'~(\[url=)(.*?)(\])(.*?)(\[\/url\])~i',
|
||||||
|
'~(\[url\])(.*?)(\[\/url\])~i'
|
||||||
|
);
|
||||||
|
|
||||||
|
$replace = array (
|
||||||
|
'<a class="link" href="$0" target="_blank">$0</a>',
|
||||||
|
'<a class="link" href="/user.php?id=$1" target="_blank">@$1</a>',
|
||||||
|
'<strong>$2</strong>',
|
||||||
|
'<em>$2</em>',
|
||||||
|
'<u>$2</u>',
|
||||||
|
'<ul>$2</ul>',
|
||||||
|
'<li>$2</li>',
|
||||||
|
'<h2>$2</h2>',
|
||||||
|
'<a class="link" href="$2" target="_blank">$4</a>',
|
||||||
|
'<a class="link" href="$2" target="_blank">$2</a>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$text = preg_replace($search, $replace, $text);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
?>
|
Loading…
Reference in a new issue