Skip to content

Commit

Permalink
added ssjs syntax highlighting and fixed date on isNaN article
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Jun 1, 2010
1 parent c21eda1 commit 0074604
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 20 deletions.
15 changes: 10 additions & 5 deletions lib/wtfjs/post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var sd = require("showdown")
, fs = require("fs")
var fs = require("fs")
, sys = require("sys")
, path = require("path")
, md2html = require("showdown").md2html
, prettyfy = require('prettyfy').prettyPrintOne;


Expand Down Expand Up @@ -47,11 +47,16 @@ exports.Post.prototype = {
return '<a href="' + this.url() + '">' + this.title() + '</a>';
},
html: function() {
// read in the post text
var p = path.normalize(path.join(__dirname, "..", "..", "posts", this.filename))
, t = fs.readFileSync(p);

// TODO, replace snippets code = prettyfy(sd.md2html(t));

return sd.md2html(t);
// replace the raw code blocks with prettyfied html
t = t.replace(/<code>[^<]+<\/code>/g, function(code) {
return "<pre><code>" + prettyfy(code.match(/<code>([\s\S]+)<\/code>/)[1]) + "</code></pre>";
});

// return markdown to html
return md2html(t);
}
};
14 changes: 13 additions & 1 deletion lib/wtfjs/public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pre {
border-radius:5px;
-moz-border-radius: 5px;
padding:10px 10px 20px 0;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#000), to(#0F2925));
background:-moz-linear-gradient(top, #000, #0F2925);
}

hr {
Expand Down Expand Up @@ -143,4 +145,14 @@ hr {

.date {
color: #666666;
}
}

/* google code prettyfy classes */
.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun{color:#660}.pln{color:#000}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec{color:#606}pre.prettyprint{padding:2px;border:1px solid #888}@media print{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun{color:#440}.pln{color:#000}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}

/* jacked up google code prettyfy classes */
.lit,.typ {color:#009D57;}
.com { color: #666; }
.pln { color: #C0C0C0; }
.kwd { color: #4169E1; }
.tag { color: #4169E1; }
4 changes: 2 additions & 2 deletions lib/wtfjs/public/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$(function(){
/*$(function(){
// change <code> into <pre class="sh_javascript_dom">
$('code').each(function(){
var node = $(this)
Expand All @@ -16,4 +16,4 @@ $(function(){
// invoke clientside syntax highlighter
sh_highlightDocument();
});
});*/
1 change: 0 additions & 1 deletion lib/wtfjs/public/shjs/sh_darkblue.min.css

This file was deleted.

1 change: 0 additions & 1 deletion lib/wtfjs/public/shjs/sh_javascript_dom.min.js

This file was deleted.

4 changes: 0 additions & 4 deletions lib/wtfjs/public/shjs/sh_main.min.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/wtfjs/public/shjs/sh_sh.min.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/wtfjs/views/layout.html.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<head>
<title>WTFJS</title>
<link rel="stylesheet" href="/public/app.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="/public/shjs/sh_darkblue.min.css" type="text/css" charset="utf-8" />
<link rel="alternate" type="application/rss+xml" title="RSS Feed for http://wtfjs.com" href="/rss/" />
<link rel="icon" href="/public/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/public/favicon.ico" type="image/x-icon" />
Expand Down
8 changes: 4 additions & 4 deletions lib/wtfjs/wtf.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ var paginate = function(page) {
, end = start >= count ? start+count : count;

self.render('index.html.ejs', {locals:{
posts: posts.slice(start, end),
posts: posts.slice(start, end),
page: cur,
max: max,
nextPage: next > max ? max : next,
prevPage: prev == 0 ? 1 : prev,
page: cur,
max: max
prevPage: prev == 0 ? 1 : prev
}});
});
};
Expand Down
4 changes: 4 additions & 0 deletions posts/2010-02-24-messing-with-number-prototype.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

<code>
(1) === 1; // true

Number.prototype.isOne = function () { return this === 1; }

(1).isOne(); // false!

Number.prototype.reallyIsOne = function () { return this - 1 === 0; }

(1).reallyIsOne(); // true
</code>
16 changes: 16 additions & 0 deletions posts/2010-04-31-isNaN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
So, [null is not an object](http://wtfjs.com/2010/02/12/null-is-not-an-object) though sometimes null is a Number.

<code>
isNaN( null ); // false
null === NaN; // false
null == NaN; // false
</code>

isNaN converts null to number.

<code>
Number( null ); // 0
</code>

But WTF. :) - [@oleg008](http://twitter.com/oleg008)

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This is much more awesome. I have to thank the guys at [HowToNode.org](http://howtonode.org) for the idea in thier [WheatJS](http://github.com/creationix/wheat) static site blog engine. Essentially, it all boils down to running the rather awesome [Google Code Prettyfy](http://code.google.com/p/google-code-prettify/) _serverside_.

The only remaining problem with the syntax highlighting is now nested &lt;code&gt; elements have to be escaped to display correctly in the final render.

<code>
// replace the raw code blocks with prettyfied html
t = t.replace(/&lt;code&gt;[^&lt;]+&lt;\/code&gt;/g, function(code) {
return prettyfy(code.match(/&lt;code&gt;([\s\S]+)&lt;\/code&gt;/)[1]);
});
</code>

Perhaps, in the future, a quick routine to fetch only the root code elements rather than blinding fetching all of them. Problem: more solved than before!

0 comments on commit 0074604

Please sign in to comment.