fix code white-space

This commit is contained in:
mappu 2014-08-23 22:22:34 +12:00
parent 301d81a637
commit 40a86b41c7
2 changed files with 17 additions and 17 deletions

View File

@ -97,23 +97,6 @@ function hesc($sz) {
function text2html($sz) { function text2html($sz) {
$sectionFmt = function($sz) {
$base = hesc($sz);
$base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base);
$base = preg_replace('~(https?://[^ \\r\\n\\t]+)~i', '<a href="\\1">\\1</a>', $base);
$btparts = explode('`', $base);
if (count($btparts) > 1 && (count($btparts) % 2)) {
for ($i = 1, $e = count($btparts); $i < $e; $i += 2) {
$btparts[$i] = '<span class="code">'.$btparts[$i].'</span>';
}
$base = implode('', $btparts);
}
return nl2br($base);
};
$identity = function($sz) { $identity = function($sz) {
return $sz; return $sz;
}; };
@ -138,6 +121,22 @@ function text2html($sz) {
return implode($join, $ret); return implode($join, $ret);
}; };
$sectionFmt = function($sz) use($oddEven, $identity) {
$base = hesc($sz);
$base = preg_replace('~^=+(.+)=+~m', '<strong>\\1</strong>', $base);
$base = preg_replace('~(https?://[^ \\r\\n\\t]+)~i', '<a href="\\1">\\1</a>', $base);
$btparts = explode('`', $base);
if (count($btparts) > 1 && (count($btparts) % 2)) {
for ($i = 1, $e = count($btparts); $i < $e; $i += 2) {
$btparts[$i] = '<span class="code">'.$btparts[$i].'</span>';
}
}
return $oddEven($btparts, $identity, 'nl2br');
};
$htmlSections = $splitInside('<html>', '</html>', $sz); $htmlSections = $splitInside('<html>', '</html>', $sz);
return $oddEven($htmlSections, $identity, $sectionFmt); return $oddEven($htmlSections, $identity, $sectionFmt);
} }

View File

@ -26,6 +26,7 @@ h1,h2,h3 {
.code { .code {
background: #F8F8F8; background: #F8F8F8;
font-family:Consolas,monospace; font-family:Consolas,monospace;
white-space:pre;
} }
/* */ /* */