From f1ab90effdfdd51b2dbb8ed46ca5ec654added51 Mon Sep 17 00:00:00 2001 From: stefanp Date: Tue, 13 Apr 2004 08:37:38 +0000 Subject: [PATCH] changed macro sourcecode to work with regexp and added more syntax highlighting --- DocFunction/macros.js | 71 ++++++++++++++++++++++++++----------------- DocFunction/main.skin | 2 +- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/DocFunction/macros.js b/DocFunction/macros.js index 2f674bec..ed2c1354 100644 --- a/DocFunction/macros.js +++ b/DocFunction/macros.js @@ -87,35 +87,50 @@ function type_macro (param) { * macro returning nicely formatted sourcecode of this method. * code is encoded, >% %<-tags are colorcoded, line numbers are added */ -function source_macro(par) { - var str = this.getContent (); - var arr = str.split("<%"); - var str2 = ""; - for ( var i=0; i<%'); + + r = new RegExp("%>","gim"); + sourcecode = sourcecode.replace(r, '%>'); + + // highlight js-comments + r = new RegExp("^([ \\t]*//.*)", "gm"); + sourcecode = sourcecode.replace(r, '$1'); + + // highlight quotation marks, but not for skins + if (this.getTypeName() != "Skin") { + r = new RegExp("(".*?")", "gm"); + sourcecode = sourcecode.replace(r, '$1'); + r = new RegExp("(\'[\']*\')", "gm"); + sourcecode = sourcecode.replace(r, '$1'); + } + + // remove all CR and LF, just
remains + var r = new RegExp("[\\r\\n]","gm"); + sourcecode = sourcecode.replace(r, ""); + + var arr = sourcecode.split("
"); + for (var i=0; i' + (i+1) + ': '); + if (i<99) { + res.write(' '); + } + if (i<9) { + res.write(' '); + } + res.write(arr[i] + "\n"); + } + + } else { + res.write(sourcecode); } - var arr = str2.split("%>"); - var str3 = ""; - for ( var i=0; i"); - var str4 = ""; - for ( var i=0; i ' - if (i<99) str4+=' '; - if (i<9) str4+=' '; - // Hack: remove leading returns/line feeds in each line - while (arr[i].length>0 && - (arr[i][0] == '\n' || arr[i][0] == '\r')) - arr[i] = arr[i].substring(1); - str4 += arr[i] + "
"; - } - return ( str4 ); } diff --git a/DocFunction/main.skin b/DocFunction/main.skin index f9546829..da43ed06 100644 --- a/DocFunction/main.skin +++ b/DocFunction/main.skin @@ -24,7 +24,7 @@
Sourcecode in <% this.location %>: -
<% this.source %>
+
<% this.source as="highlighted" %>