[code] tag support

This commit is contained in:
czaks 2015-04-12 00:32:58 +02:00
parent 4131a6e563
commit 197d5f236f
2 changed files with 28 additions and 10 deletions

View File

@ -624,13 +624,10 @@
$config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
$config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>");
// Highlight PHP code wrapped in <code> tags (PHP 5.3+)
// $config['markup'][] = array(
// '/^&lt;code&gt;(.+)&lt;\/code&gt;/ms',
// function($matches) {
// return highlight_string(html_entity_decode($matches[1]), true);
// }
// );
// Code markup. This should be set to a regular expression, using tags you want to use. Examples:
// "/\[code\](.*?)[\/code]/is"
// "/```([a-z0-9-]{0,20})\n(.*?)\n?```/s"
$config['markup_code'] = false;
// Repair markup with HTML Tidy. This may be slower, but it solves nesting mistakes. Tinyboad, at the
// time of writing this, can not prevent out-of-order markup tags (eg. "**''test**'') without help from

View File

@ -1857,6 +1857,15 @@ function markup(&$body, $track_cites = false) {
if (mysql_version() < 50503)
$body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8');
if ($config['markup_code']) {
$code_markup = array();
$body = preg_replace_callback($config['markup_code'], function($matches) use (&$code_markup) {
$d = count($code_markup);
$code_markup[] = $matches;
return "<code $d>";
}, $body);
}
foreach ($config['markup'] as $markup) {
if (is_string($markup[1])) {
$body = preg_replace($markup[0], $markup[1], $body);
@ -2055,6 +2064,18 @@ function markup(&$body, $track_cites = false) {
$body = preg_replace("/\n/", '<br/>', $body);
// Fix code markup
if ($config['markup_code']) {
foreach ($code_markup as $id => $val) {
$code = isset($val[2]) ? $val[2] : $val[1];
$code_lang = isset($val[2]) ? $val[1] : "";
$code = "<pre class='code lang-$code_lang'>".str_replace(array("\n","\t"), array("&#10;","&#9;"), htmlspecialchars($code))."</pre>";
$body = str_replace("<code $id>", $code, $body);
}
}
if ($config['markup_repair_tidy']) {
$tidy = new tidy();
$body = str_replace("\t", '&#09;', $body);