[code] tag support
This commit is contained in:
parent
4131a6e563
commit
197d5f236f
@ -624,13 +624,10 @@
|
|||||||
$config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
|
$config['markup'][] = array("/\*\*(.+?)\*\*/", "<span class=\"spoiler\">\$1</span>");
|
||||||
$config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>");
|
$config['markup'][] = array("/^[ |\t]*==(.+?)==[ |\t]*$/m", "<span class=\"heading\">\$1</span>");
|
||||||
|
|
||||||
// Highlight PHP code wrapped in <code> tags (PHP 5.3+)
|
// Code markup. This should be set to a regular expression, using tags you want to use. Examples:
|
||||||
// $config['markup'][] = array(
|
// "/\[code\](.*?)[\/code]/is"
|
||||||
// '/^<code>(.+)<\/code>/ms',
|
// "/```([a-z0-9-]{0,20})\n(.*?)\n?```/s"
|
||||||
// function($matches) {
|
$config['markup_code'] = false;
|
||||||
// return highlight_string(html_entity_decode($matches[1]), true);
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Repair markup with HTML Tidy. This may be slower, but it solves nesting mistakes. Tinyboad, at the
|
// 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
|
// time of writing this, can not prevent out-of-order markup tags (eg. "**''test**'') without help from
|
||||||
|
@ -1857,6 +1857,15 @@ function markup(&$body, $track_cites = false) {
|
|||||||
if (mysql_version() < 50503)
|
if (mysql_version() < 50503)
|
||||||
$body = mb_encode_numericentity($body, array(0x010000, 0xffffff, 0, 0xffffff), 'UTF-8');
|
$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) {
|
foreach ($config['markup'] as $markup) {
|
||||||
if (is_string($markup[1])) {
|
if (is_string($markup[1])) {
|
||||||
$body = preg_replace($markup[0], $markup[1], $body);
|
$body = preg_replace($markup[0], $markup[1], $body);
|
||||||
@ -2054,7 +2063,19 @@ function markup(&$body, $track_cites = false) {
|
|||||||
$body = preg_replace('/\s+$/', '', $body);
|
$body = preg_replace('/\s+$/', '', $body);
|
||||||
|
|
||||||
$body = preg_replace("/\n/", '<br/>', $body);
|
$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(" ","	"), htmlspecialchars($code))."</pre>";
|
||||||
|
|
||||||
|
$body = str_replace("<code $id>", $code, $body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($config['markup_repair_tidy']) {
|
if ($config['markup_repair_tidy']) {
|
||||||
$tidy = new tidy();
|
$tidy = new tidy();
|
||||||
$body = str_replace("\t", '	', $body);
|
$body = str_replace("\t", '	', $body);
|
||||||
@ -2072,10 +2093,10 @@ function markup(&$body, $track_cites = false) {
|
|||||||
), 'utf8');
|
), 'utf8');
|
||||||
$body = str_replace("\n", '', $body);
|
$body = str_replace("\n", '', $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace tabs with 8 spaces
|
// replace tabs with 8 spaces
|
||||||
$body = str_replace("\t", ' ', $body);
|
$body = str_replace("\t", ' ', $body);
|
||||||
|
|
||||||
return $tracked_cites;
|
return $tracked_cites;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user