Commit 8a327508 authored by twanvl's avatar twanvl

Some more tweaks to the website

parent 590955e1
......@@ -105,9 +105,18 @@ function fromfile_page() {
}
// done
drupal_set_title($title);
drupal_set_breadcrumb($breadcrumbs);
return $content;
// view as a node
$node = array(
'title' => $title,
'body' => $content,
'created' => 0,
'links' => FALSE,
'name' => '',
'nid' => ''
);
//return node_view((object)$node, FALSE, TRUE);
return theme('node', (object)$node, FALSE, TRUE);
}
......
......@@ -53,9 +53,12 @@ function autoformat__handle(&$i, $prefix, $first, $fail_same = false) {
$current_prefix .= ' ';
}
//$line = $line . '{' . $current_prefix . '|' . strlen($prefix) . substr($oldline, 0, strlen($prefix)) . '}';
// Determine line type
if (strlen($oldline) < strlen($prefix)) {
// empty line => break out of this level
$i--;
if ($state == '|') $text .= autoformat__table($table);
return $text;
} else if ($line == '') {
......@@ -128,7 +131,15 @@ function autoformat__handle(&$i, $prefix, $first, $fail_same = false) {
// source code
if ($state == '>') $text = substr($text,0,-6);
else $text .= '<pre>';
$text .= syntax_highlight(htmlspecialchars(substr($line, 1)));
if (substr($line,0,4)=='>>>>') { // always code, not escaped
$text .= highlight_script(substr($line, 4));
} else if (substr($line,0,3)=='>>>') { // not escaped
$text .= syntax_highlight(substr($line, 3));
} else if (substr($line,0,2)=='>>') { // always code
$text .= highlight_script(htmlspecialchars(substr($line, 2)));
} else {
$text .= syntax_highlight(htmlspecialchars(substr($line, 1)));
}
$text .= "\n</pre>";
$state = '>';
} elseif ($line{0} == ']') {
......@@ -142,7 +153,7 @@ function autoformat__handle(&$i, $prefix, $first, $fail_same = false) {
// Html
} elseif (preg_match("@^</?(pre|ul|ol|li|div|blockquote|>)@", $line)) {
$line = preg_replace("@^<>@","",$line);
$text .= $line;
$text .= $line . "\n";
$state = '';
// Just text
......
......@@ -54,21 +54,35 @@ function highlight_reader($code) {
function highlight_script($code) {
$ret = '';
$string = '';
while(strlen($code)) {
if (preg_match("@^(if|then|else|for|in|do|and|or|xor|not|rgb)\b@",$code, $matches)) {
if (preg_match("@^<[^>]+>@",$code, $matches)) {
$ret .= $matches[0]; // plain tag
} else if (preg_match("@^(if|then|else|for|in|do|and|or|xor|not|rgb)\b@",$code, $matches)) {
$ret .= "<span class='hl-kw'>" . $matches[0] . "</span>";
} else if (preg_match("@^(include file:)(.*)@",$code, $matches)) {
$ret .= "<span class='hl-key'>" . $matches[1] . "</span>" . $matches[2];
} else if (preg_match("@^([0-9][0-9.]*|true|false)@",$code, $matches)) {
$ret .= "<span class='hl-num'>" . $matches[0] . "</span>";
} else if (preg_match("@^(\"|&quot;)(\\\\.|[^\\\\])*?(\"|&quot;)@",$code, $matches)) {
$ret .= "<span class='hl-str'>" . $matches[0] . "</span>";
// } else if (preg_match("@^(\"|&quot;)(\\\\.|[^\\\\])*?(\"|&quot;)@",$code, $matches)) {
// $ret .= "<span class='hl-str'>" . $matches[0] . "</span>";
} else if (preg_match("@^(\"|&quot;)(\\\\.|[^\\\\{])*?(\"|&quot;|{)@",$code, $matches)) {
$ret .= "<span class='hl-str'>" . highlight_script_string($matches[0]) . "</span>";
if ($matches[3] == '{') $string .= 's';
} else if ($string != '' && $string{strlen($string)-1}=='s' &&
preg_match("@^}(\\\\.|[^\\\\{])*?(\"|&quot;|{)@",$code, $matches)) {
// return from string quote
$ret .= "<span class='hl-str'>" . highlight_script_string($matches[0]) . "</span>";
$string = substr($string,0,-1);
if ($matches[3] == '{') $string .= 's';
} else if (preg_match("@^\\#.*@",$code, $matches)) {
$ret .= "<span class='hl-comment'>" . $matches[0] . "</span>";
} else if (preg_match("@^([-+*/=!.]|&lt;|&gt;)+|^:=@",$code, $matches)) {
$ret .= "<span class='hl-op'>" . $matches[0] . "</span>";
} else if (preg_match("@^[\\(\\)\\[\\]{},]+@",$code, $matches)) {
} else if (preg_match("@^([}]|[\\(\\)\\[\\]{,]+)@",$code, $matches)) {
$ret .= "<span class='hl-paren'>" . $matches[0] . "</span>";
if ($matches[0] == '{') $string .= 'p';
elseif ($matches[0] == '}') $string = substr($string,0,-1);
} else if (preg_match("@^[a-zA-Z_][a-zA-Z0-9_]*:@",$code, $matches)) {
$ret .= "<span class='hl-ckey'>" . $matches[0] . "</span>";
} else if (preg_match("@^([a-zA-Z0-9_]+\s*|\s+|&#?[a-zA-Z0-9]+;)@",$code, $matches)) {
......@@ -84,5 +98,9 @@ function highlight_script($code) {
}
return $ret;
}
function highlight_script_string($code) {
$code = preg_replace("@&lt;.*?(&gt;|>)@", "<span class='hl-tag'>\\0</span>", $code);
return $code;
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment