public
Fork of sr/git-wiki
Description: A wiki engine that uses a Git repository as its data store.
Homepage: http://atonie.org/2008/02/git-wiki
Clone URL: git://github.com/al3x/git-wiki.git
Search Repo:
clean up some templates, add JavaScript-based syntax highlighting of diffs
al3x (author)
Thu Mar 20 00:28:25 -0700 2008
commit  dc304d822c7144e55d1f05123d86b538f3bac337
tree    b38b8920b46828a5219f391df4b74ea2db370069
parent  41cdf8340352786ab24bdd645c1e7497a134467f
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+
0
+if(!this.sh_languages){this.sh_languages={};}
0
+sh_languages['diff']=[[{'next':1,'regex':/(?=^[-]{3})/g,'state':1,'style':'sh_oldfile'},{'next':6,'regex':/(?=^[*]{3})/g,'state':1,'style':'sh_oldfile'},{'next':14,'regex':/(?=^[\d])/g,'state':1,'style':'sh_difflines'}],[{'next':2,'regex':/^[-]{3}/g,'style':'sh_oldfile'},{'next':3,'regex':/^[-]/g,'style':'sh_oldfile'},{'next':4,'regex':/^[+]/g,'style':'sh_newfile'},{'next':5,'regex':/^@@/g,'style':'sh_difflines'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':7,'regex':/^[*]{3}[ \t]+[\d]/g,'style':'sh_oldfile'},{'next':9,'regex':/^[*]{3}/g,'style':'sh_oldfile'},{'next':10,'regex':/^[-]{3}[ \t]+[\d]/g,'style':'sh_newfile'},{'next':13,'regex':/^[-]{3}/g,'style':'sh_newfile'}],[{'next':8,'regex':/^[\s]/g,'style':'sh_normal'},{'exit':true,'regex':/(?=^[-]{3})/g,'style':'sh_newfile'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':11,'regex':/^[\s]/g,'style':'sh_normal'},{'exit':true,'regex':/(?=^[*]{3})/g,'style':'sh_newfile'},{'exit':true,'next':12,'regex':/^diff/g,'style':'sh_normal'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'next':15,'regex':/^[\d]/g,'style':'sh_difflines'},{'next':16,'regex':/^[<]/g,'style':'sh_oldfile'},{'next':17,'regex':/^[>]/g,'style':'sh_newfile'}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}],[{'exit':true,'regex':/$/g}]];
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -1 +1,53 @@
0
+/* Copyright (C) 2007 gnombat@users.sourceforge.net */
0
+/* License: http://shjs.sourceforge.net/doc/license.html */
0
+
0
+function sh_highlightString(inputString,language,builder){var patternStack={_stack:[],getLength:function(){return this._stack.length;},getTop:function(){var stack=this._stack;var length=stack.length;if(length===0){return undefined;}
0
+return stack[length-1];},push:function(state){this._stack.push(state);},pop:function(){if(this._stack.length===0){throw"pop on empty stack";}
0
+this._stack.pop();}};var pos=0;var currentStyle=undefined;var output=function(s,style){var length=s.length;if(length===0){return;}
0
+if(!style){var pattern=patternStack.getTop();if(pattern!==undefined&&!('state'in pattern)){style=pattern.style;}}
0
+if(currentStyle!==style){if(currentStyle){builder.endElement();}
0
+if(style){builder.startElement(style);}}
0
+builder.text(s);pos+=length;currentStyle=style;};var endOfLinePattern=/\r\n|\r|\n/g;endOfLinePattern.lastIndex=0;var inputStringLength=inputString.length;while(pos<inputStringLength){var start=pos;var end;var startOfNextLine;var endOfLineMatch=endOfLinePattern.exec(inputString);if(endOfLineMatch===null){end=inputStringLength;startOfNextLine=inputStringLength;}
0
+else{end=endOfLineMatch.index;startOfNextLine=endOfLinePattern.lastIndex;}
0
+var line=inputString.substring(start,end);var matchCache=null;var matchCacheState=-1;for(;;){var posWithinLine=pos-start;var pattern=patternStack.getTop();var stateIndex=pattern===undefined?0:pattern.next;var state=language[stateIndex];var numPatterns=state.length;if(stateIndex!==matchCacheState){matchCache=[];}
0
+var bestMatch=null;var bestMatchIndex=-1;for(var i=0;i<numPatterns;i++){var match;if(stateIndex===matchCacheState&&(matchCache[i]===null||posWithinLine<=matchCache[i].index)){match=matchCache[i];}
0
+else{var regex=state[i].regex;regex.lastIndex=posWithinLine;match=regex.exec(line);matchCache[i]=match;}
0
+if(match!==null&&(bestMatch===null||match.index<bestMatch.index)){bestMatch=match;bestMatchIndex=i;}}
0
+matchCacheState=stateIndex;if(bestMatch===null){output(line.substring(posWithinLine),null);break;}
0
+else{if(bestMatch.index>posWithinLine){output(line.substring(posWithinLine,bestMatch.index),null);}
0
+pattern=state[bestMatchIndex];var newStyle=pattern.style;var matchedString;if(newStyle instanceof Array){for(var subexpression=0;subexpression<newStyle.length;subexpression++){matchedString=bestMatch[subexpression+1];output(matchedString,newStyle[subexpression]);}}
0
+else{matchedString=bestMatch[0];output(matchedString,newStyle);}
0
+if('next'in pattern){patternStack.push(pattern);}
0
+else{if('exit'in pattern){patternStack.pop();}
0
+if('exitall'in pattern){while(patternStack.getLength()>0){patternStack.pop();}}}}}
0
+if(currentStyle){builder.endElement();}
0
+currentStyle=undefined;if(endOfLineMatch){builder.text(endOfLineMatch[0]);}
0
+pos=startOfNextLine;}}
0
+function sh_getClasses(element){var result=[];var htmlClass=element.className;if(htmlClass&&htmlClass.length>0){var htmlClasses=htmlClass.split(" ");for(var i=0;i<htmlClasses.length;i++){if(htmlClasses[i].length>0){result.push(htmlClasses[i]);}}}
0
+return result;}
0
+function sh_addClass(element,name){var htmlClasses=sh_getClasses(element);for(var i=0;i<htmlClasses.length;i++){if(name.toLowerCase()===htmlClasses[i].toLowerCase()){return;}}
0
+htmlClasses.push(name);element.className=htmlClasses.join(" ");}
0
+function sh_getText(element){if(element.nodeType===3||element.nodeType===4){return element.data;}
0
+else if(element.childNodes.length===1){return sh_getText(element.firstChild);}
0
+else{var result='';for(var i=0;i<element.childNodes.length;i++){result+=sh_getText(element.childNodes.item(i));}
0
+return result;}}
0
+function sh_isEmailAddress(url){if(/^mailto:/.test(url)){return false;}
0
+return url.indexOf('@')!==-1;}
0
+var sh_builder={init:function(htmlDocument,element){while(element.hasChildNodes()){element.removeChild(element.firstChild);}
0
+this._document=htmlDocument;this._element=element;this._currentText=null;this._documentFragment=htmlDocument.createDocumentFragment();this._currentParent=this._documentFragment;this._span=htmlDocument.createElement("span");this._a=htmlDocument.createElement("a");},startElement:function(style){if(this._currentText!==null){this._currentParent.appendChild(this._document.createTextNode(this._currentText));this._currentText=null;}
0
+var span=this._span.cloneNode(true);span.className=style;this._currentParent.appendChild(span);this._currentParent=span;},endElement:function(){if(this._currentText!==null){if(this._currentParent.className==='sh_url'){var a=this._a.cloneNode(true);a.className='sh_url';var url=this._currentText;if(url.length>0&&url.charAt(0)==='<'&&url.charAt(url.length-1)==='>'){url=url.substr(1,url.length-2);}
0
+if(sh_isEmailAddress(url)){url='mailto:'+url;}
0
+a.setAttribute('href',url);a.appendChild(this._document.createTextNode(this._currentText));this._currentParent.appendChild(a);}
0
+else{this._currentParent.appendChild(this._document.createTextNode(this._currentText));}
0
+this._currentText=null;}
0
+this._currentParent=this._currentParent.parentNode;},text:function(s){if(this._currentText===null){this._currentText=s;}
0
+else{this._currentText+=s;}},close:function(){if(this._currentText!==null){this._currentParent.appendChild(this._document.createTextNode(this._currentText));this._currentText=null;}
0
+this._element.appendChild(this._documentFragment);}};function sh_highlightElement(htmlDocument,element,language){sh_addClass(element,"sh_sourceCode");var inputString;if(element.childNodes.length===0){return;}
0
+else{inputString=sh_getText(element);}
0
+sh_builder.init(htmlDocument,element);sh_highlightString(inputString,language,sh_builder);sh_builder.close();}
0
+function sh_highlightHTMLDocument(htmlDocument){if(!window.sh_languages){return;}
0
+var nodeList=htmlDocument.getElementsByTagName("pre");for(var i=0;i<nodeList.length;i++){var element=nodeList.item(i);var htmlClasses=sh_getClasses(element);for(var j=0;j<htmlClasses.length;j++){var htmlClass=htmlClasses[j].toLowerCase();if(htmlClass==="sh_sourcecode"){continue;}
0
+var prefix=htmlClass.substr(0,3);if(prefix==="sh_"){var language=htmlClass.substring(3);if(language in sh_languages){sh_highlightElement(htmlDocument,element,sh_languages[language]);}
0
+else{throw"Found <pre> element with class='"+htmlClass+"', but no such language exists";}}}}}
0
+function sh_highlightDocument(){sh_highlightHTMLDocument(document);}
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
0
@@ -1 +1,139 @@
0
+pre.sh_sourceCode {
0
+ background-color: #ffffff;
0
+ color: #000000;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_keyword {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_type {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_string {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_regexp {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_specialchar {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_comment {
0
+ color: #717ab3;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_number {
0
+ color: #000000;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_preproc {
0
+ color: #3f5fbf;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_function {
0
+ color: #000000;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_url {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_date {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_time {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_file {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_ip {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_name {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_variable {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_oldfile {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_newfile {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_difflines {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_selector {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_property {
0
+ color: #7f0055;
0
+ font-weight: bold;
0
+ font-style: normal;
0
+}
0
+
0
+pre.sh_sourceCode .sh_value {
0
+ color: #0000ff;
0
+ font-weight: normal;
0
+ font-style: normal;
0
+}
...
16
17
18
19
 
20
21
22
...
16
17
18
 
19
20
21
22
0
@@ -16,7 +16,7 @@
0
 a:visited { color: #7b69b0; }
0
 a:hover { text-decoration: underline; }
0
 
0
-code, pre, .delta {
0
+code, pre {
0
   font-family: "Deja Vu Sans Mono", "Bitstream Vera Sans Mono", "Inconsolata", "Consolas", monospace;
0
 }
0
 
...
13
14
15
16
 
17
18
19
20
21
 
22
23
 
24
25
26
...
13
14
15
 
16
17
18
19
20
 
21
22
23
24
25
26
27
0
@@ -13,14 +13,15 @@
0
       <% if commit != @history.first %>
0
         <a href="/a/revert_branch/<%= commit.sha %>" title="Click to revert to this revision." onclick="return confirm('Are you sure you want to revert to this revision?');">
0
           <script type="text/javascript">
0
- document.write(time_ago_in_words(<%= commit.date.for_time_ago_in_words %>) + ' ago:');
0
+ document.write(time_ago_in_words(<%= commit.date.for_time_ago_in_words %>) + ' ago');
0
           </script>
0
         </a>
0
       <% else %>
0
         <script type="text/javascript">
0
- document.write(time_ago_in_words(<%= commit.date.for_time_ago_in_words %>) + ' ago:');
0
+ document.write(time_ago_in_words(<%= commit.date.for_time_ago_in_words %>) + ' ago');
0
         </script>
0
       <% end %>
0
+ &mdash;
0
       <%= commit.message %>
0
     </li>
0
   <% end %>
...
 
 
 
 
1
2
3
4
...
7
8
9
10
11
12
 
13
 
 
 
 
...
1
2
3
4
5
6
7
8
...
11
12
13
 
 
 
14
15
16
17
18
19
0
@@ -1,3 +1,7 @@
0
+<script language="javascript" type="text/javascript" src="/sh_main.min.js"></script>
0
+<script language="javascript" type="text/javascript" src="/sh_diff.min.js"></script>
0
+<link rel="stylesheet" href="/sh_style.css" type="text/css" media="screen" />
0
+
0
 <h1>Diff of <a href="/<%= @page.name %>"><%= @page.name %></a></h1>
0
 
0
 <div class="sub_nav">
0
0
@@ -7,8 +11,10 @@
0
 </div>
0
 
0
 <div class="content">
0
- <div class="delta">
0
- <%= Uv.parse(@page.delta(params[:rev]), "xhtml", "diff", false, UV_THEME) %>
0
- </div>
0
+ <pre class="sh_diff"><%= @page.delta(params[:rev]) %></pre>
0
 </div>
0
+
0
+<script type="text/javascript">
0
+ sh_highlightDocument();
0
+</script>
...
9
10
11
12
 
 
 
 
13
14
15
...
9
10
11
 
12
13
14
15
16
17
18
0
@@ -9,7 +9,10 @@
0
   <ul>
0
     <% @page.history.each do |c| %>
0
       <li>
0
- <%= c.committer_date %> &mdash;
0
+ <script type="text/javascript">
0
+ document.write(time_ago_in_words(<%= c.committer_date.for_time_ago_in_words %>) + ' ago');
0
+ </script>
0
+ &mdash;
0
         <a href="/h/<%= @page.name %>/<%= c.sha %>"><%= c.message %></a>
0
         <% unless @page.history.first == c %>
0
          &bull; <a href="/d/<%= @page.name %>/<%= c.sha %>">diff</a>

Comments

    No one has commented yet.