From 77ed2e7da00b00798bae6ec46b4adb4c15648faa Mon Sep 17 00:00:00 2001 From: Joshua Holbrook Date: Wed, 28 Sep 2011 14:00:24 -0700 Subject: [PATCH 1/5] [ux] "Edit this page on github" button now points to the relevant fork/edit github url --- theme/article.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/theme/article.html b/theme/article.html index f8e31f1..9183afa 100644 --- a/theme/article.html +++ b/theme/article.html @@ -22,6 +22,15 @@ })(); + + +
From a2c9cf2ece3dd545ad2ad7dc2cc9df3041b4b76c Mon Sep 17 00:00:00 2001 From: Joshua Holbrook Date: Mon, 3 Oct 2011 15:56:57 -0700 Subject: [PATCH 2/5] [ux] Using koala instead of the vendored hilight module. Seems to work pretty well for js, but uses filenames to detect language. Either all hilights are done as javascript or we need a better detection system. --- lib/generators/article.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/generators/article.js b/lib/generators/article.js index 4d2fb9b..04cc54d 100644 --- a/lib/generators/article.js +++ b/lib/generators/article.js @@ -6,7 +6,8 @@ var findit = require('findit'), fs = require('fs'), docs = require('../docs'), weld = require('weld').weld, - helpers = require('../helpers'); + helpers = require('../helpers'), + koala = require('koala'); var article = exports; @@ -92,7 +93,11 @@ article.weld = function(dom, articles) { // // TODO: the current code highlighting is slow, very slow. let's try to fix that // - dom.innerHTML = hl(dom.innerHTML, false, true); + Array.prototype.forEach.call( $('code', dom), function (c) { + var rendered = koala.render('snippet.js', $(c, dom).text()); + $(c, dom).html(rendered); + }); + articles[i].content = dom.innerHTML; }); From f8b1023c149804985b75762d812c3ff8a70840a1 Mon Sep 17 00:00:00 2001 From: Joshua Holbrook Date: Mon, 3 Oct 2011 16:47:09 -0700 Subject: [PATCH 3/5] [fix] using $().html() on both sides avoids awkward html entity troubles --- lib/generators/article.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/generators/article.js b/lib/generators/article.js index 04cc54d..f7d4797 100644 --- a/lib/generators/article.js +++ b/lib/generators/article.js @@ -7,7 +7,8 @@ var findit = require('findit'), docs = require('../docs'), weld = require('weld').weld, helpers = require('../helpers'), - koala = require('koala'); + koala = require('koala'), + uglify = require('uglify-js').parser.parse; var article = exports; @@ -94,7 +95,21 @@ article.weld = function(dom, articles) { // TODO: the current code highlighting is slow, very slow. let's try to fix that // Array.prototype.forEach.call( $('code', dom), function (c) { - var rendered = koala.render('snippet.js', $(c, dom).text()); + var src = $(c).html(), + rendered; + + // test to see if uglify thinks the code snippet is javascript + // Makes too many false negatives, imo. + try { + uglify(src); + // "snippet.js" is recognized by koala as a js filename + rendered = koala.render('snippet.js', src); + } catch (e) { + //assume it's not javascript + //console.log(e.message); + rendered = src; + } + $(c, dom).html(rendered); }); From 0bea9839b9fc63c5f1373e715c099fa5aead1293 Mon Sep 17 00:00:00 2001 From: Joshua Holbrook Date: Mon, 3 Oct 2011 17:02:07 -0700 Subject: [PATCH 4/5] [minor] using jquery to do the entity stuff instead of node-ent --- lib/generators/article.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/generators/article.js b/lib/generators/article.js index f7d4797..67d1ee7 100644 --- a/lib/generators/article.js +++ b/lib/generators/article.js @@ -95,7 +95,7 @@ article.weld = function(dom, articles) { // TODO: the current code highlighting is slow, very slow. let's try to fix that // Array.prototype.forEach.call( $('code', dom), function (c) { - var src = $(c).html(), + var src = $(c).text(), rendered; // test to see if uglify thinks the code snippet is javascript @@ -105,9 +105,8 @@ article.weld = function(dom, articles) { // "snippet.js" is recognized by koala as a js filename rendered = koala.render('snippet.js', src); } catch (e) { - //assume it's not javascript - //console.log(e.message); - rendered = src; + //assume it's not javascript. Still have to handle entities though. + rendered = $("
").text(src).html(); } $(c, dom).html(rendered); From c6927f75a7589ca11f8e3ed280ba007cb516e69e Mon Sep 17 00:00:00 2001 From: Joshua Holbrook Date: Mon, 3 Oct 2011 17:03:31 -0700 Subject: [PATCH 5/5] [dist] package.json includes koala and uglify. --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 96d06bf..d409cdd 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "http-server": "0.2.4", "jsdom": "0.2.x", "weld": "0.2.1", - "findit": "0.1.x" + "findit": "0.1.x", + "koala": "0.1.2", + "uglify-js": "1.1.0" } }