Skip to content
Browse files

Added syntax highlighting to docs

  • Loading branch information...
1 parent 0b93aa9 commit f8dd62b99ccc44b0f350bd4c5a112d953cff2481 @assaf committed Dec 6, 2011
Showing with 173 additions and 25 deletions.
  1. +32 −19 Cakefile
  2. +3 −3 doc/API.md
  3. +132 −0 doc/css/github.css
  4. +2 −3 doc/css/print.css
  5. +1 −0 doc/layout/main.html
  6. +2 −0 lib/zombie/history.coffee
  7. +1 −0 package.json
View
51 Cakefile
@@ -1,5 +1,6 @@
-fs = require("fs")
-path = require("path")
+File = require("fs")
+Path = require("path")
+HLJS = require("highlight/lib/vendor/highlight.js/highlight").hljs
{spawn, exec} = require("child_process")
stdout = process.stdout
@@ -27,7 +28,7 @@ onerror = (err)->
# Setup development dependencies, not part of runtime dependencies.
task "setup", "Install development dependencies", ->
- fs.readFile "package.json", "utf8", (err, package)->
+ File.readFile "package.json", "utf8", (err, package)->
install = (dependencies, callback)->
if dep = dependencies.shift()
[name, version] = dep
@@ -79,12 +80,23 @@ task "test", "Run all tests", ->
## Documentation ##
+# HLJS can't guess the language (JavaScript) consistently, so we're going to help by limiting its choice of languages to
+# JavaScript and XML (good pick for one of the dumps).
+require("highlight/lib/vendor/highlight.js/languages/xml")(HLJS)
+require("highlight/lib/vendor/highlight.js/languages/javascript")(HLJS)
+
+# Syntax highlighting
+highlight = (html)->
+ unescape = (html)->
+ return html.replace(/&quot;/g, "\"").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">")
+ return html.replace(/<code>([\s\S]*?)<\/code>/gm, (_, source)-> "<code>#{HLJS.highlightText(unescape(source).replace(/\uffff/g,"\n"))}</code>")
+
# Markdown to HTML.
toHTML = (source, callback)->
- target = "html/#{path.basename(source, ".md").toLowerCase()}.html"
- fs.readFile "doc/layout/main.html", "utf8", (err, layout)->
+ target = "html/#{Path.basename(source, ".md").toLowerCase()}.html"
+ File.readFile "doc/layout/main.html", "utf8", (err, layout)->
onerror err
- fs.readFile source, "utf8", (err, text)->
+ File.readFile source, "utf8", (err, text)->
onerror err
log "Creating #{target}", green
exec "ronn --html #{source}", (err, stdout, stderr)->
@@ -93,24 +105,25 @@ toHTML = (source, callback)->
name = name.replace(/\(\d\)/, "")
body = stdout.replace(/<h1>.*<\/h1>/, "")
html = layout.replace("{{body}}", body).replace(/{{title}}/g, title)
- fs.writeFile target, html, "utf8", (err)->
+ html = highlight(html)
+ File.writeFile target, html, "utf8", (err)->
callback err, target
documentPages = (callback)->
- files = fs.readdirSync(".").filter((file)-> path.extname(file) == ".md").
- concat(fs.readdirSync("doc").filter((file)-> path.extname(file) == ".md").map((file)-> "doc/#{file}"))
- fs.mkdir "html", 0777, ->
+ files = File.readdirSync(".").filter((file)-> Path.extname(file) == ".md").
+ concat(File.readdirSync("doc").filter((file)-> Path.extname(file) == ".md").map((file)-> "doc/#{file}"))
+ File.mkdir "html", 0777, ->
convert = ->
if file = files.pop()
toHTML file, (err)->
onerror err
convert()
else
process.stdout.write "\n"
- fs.readFile "html/readme.html", "utf8", (err, html)->
+ File.readFile "html/readme.html", "utf8", (err, html)->
html = html.replace(/<h1>(.*)<\/h1>/, "<h1>Zombie.js</h1><b>$1</b>")
- fs.writeFile "html/index.html", html, "utf8", onerror
- fs.unlink "html/readme.html", onerror
+ File.writeFile "html/index.html", html, "utf8", onerror
+ File.unlink "html/readme.html", onerror
exec "cp -fr doc/css doc/images html/", callback
convert()
@@ -123,17 +136,17 @@ documentSource = (callback)->
exec "mkdir -p html && cp -rf docs/ html/source && rm -rf docs", callback
generateMan = (callback)->
- files = fs.readdirSync(".").filter((file)-> path.extname(file) == ".md").
- concat(fs.readdirSync("doc").filter((file)-> path.extname(file) == ".md").map((file)-> "doc/#{file}"))
- fs.mkdir "man7", 0777, (err)->
+ files = File.readdirSync(".").filter((file)-> Path.extname(file) == ".md").
+ concat(File.readdirSync("doc").filter((file)-> Path.extname(file) == ".md").map((file)-> "doc/#{file}"))
+ File.mkdir "man7", 0777, (err)->
log "Generating man file ...", green
convert = ->
if file = files.pop()
- target = "man7/#{path.basename(file, ".md").toLowerCase()}.7"
+ target = "man7/#{Path.basename(file, ".md").toLowerCase()}.7"
exec "ronn --roff #{file}", (err, stdout, stderr)->
onerror err
log "Creating #{target}", green
- fs.writeFile target, stdout, "utf8", onerror
+ File.writeFile target, stdout, "utf8", onerror
convert()
else
exec "mv man7/readme.7 man7/zombie.7", onerror
@@ -197,7 +210,7 @@ task "publish", "Publish new version (Git, NPM, site)", ->
onerror err
exec "git push", (err)->
onerror err
- fs.readFile "package.json", "utf8", (err, package)->
+ File.readFile "package.json", "utf8", (err, package)->
package = JSON.parse(package)
# Publish documentation, need these first to generate man pages,
View
6 doc/API.md
@@ -281,7 +281,7 @@ option to select, by value or label.
For example:
- browser.select("Currency", "brain$")
+ browser.select("Currency", "brains")
See also `selectOption`.
@@ -402,7 +402,7 @@ response available, returns false.
For example:
- browser.onconfirm "Are you sure?", true
+ browser.onconfirm("Are you sure?", true)
### browser.onprompt(message, response)
### browser.onprompt(fn)
@@ -416,7 +416,7 @@ The response to a prompt can be any value (converted to a string), false to indi
For example:
- browser.onprompt (message)-> Math.random()
+ browser.onprompt(function(message) { return Math.random() })
### browser.prompted(message) => boolean
View
132 doc/css/github.css
@@ -0,0 +1,132 @@
+/*
+
+github.com style (c) Vasily Polovnyov <vast@whiteants.net>
+
+*/
+
+pre code {
+ font-family: "Menlo", "Consolas", "New Courier", Courier, monospace;
+ font-size: 12pt;
+ line-height: 1.5em;
+ display: block; padding: 0.5em;
+ color: #000;
+ background: #f8f8ff
+}
+
+pre .comment,
+pre .template_comment,
+pre .diff .header,
+pre .javadoc {
+ color: #998;
+ font-style: italic
+}
+
+pre .keyword,
+pre .css .rule .keyword,
+pre .winutils,
+pre .javascript .title,
+pre .lisp .title,
+pre .subst {
+ color: #000;
+ font-weight: bold
+}
+
+pre .number,
+pre .hexcolor {
+ color: #40a070
+}
+
+pre .string,
+pre .tag .value,
+pre .phpdoc,
+pre .tex .formula {
+ color: #d14
+}
+
+pre .title,
+pre .id {
+ color: #900;
+ font-weight: bold
+}
+
+pre .javascript .title,
+pre .lisp .title,
+pre .subst {
+ font-weight: normal
+}
+
+pre .class .title,
+pre .haskell .label,
+pre .tex .command {
+ color: #458;
+ font-weight: bold
+}
+
+pre .tag,
+pre .tag .title,
+pre .rules .property,
+pre .django .tag .keyword {
+ color: #000080;
+ font-weight: normal
+}
+
+pre .attribute,
+pre .variable,
+pre .instancevar,
+pre .lisp .body {
+ color: #008080
+}
+
+pre .regexp {
+ color: #009926
+}
+
+pre .class {
+ color: #458;
+ font-weight: bold
+}
+
+pre .symbol,
+pre .ruby .symbol .string,
+pre .ruby .symbol .keyword,
+pre .ruby .symbol .keymethods,
+pre .lisp .keyword,
+pre .tex .special,
+pre .input_number {
+ color: #990073
+}
+
+pre .builtin,
+pre .built_in,
+pre .lisp .title {
+ color: #0086b3
+}
+
+pre .preprocessor,
+pre .pi,
+pre .doctype,
+pre .shebang,
+pre .cdata {
+ color: #999;
+ font-weight: bold
+}
+
+pre .deletion {
+ background: #fdd
+}
+
+pre .addition {
+ background: #dfd
+}
+
+pre .diff .change {
+ background: #0086b3
+}
+
+pre .chunk {
+ color: #aaa
+}
+
+pre .tex .formula {
+ opacity: 0.5;
+}
View
5 doc/css/print.css
@@ -11,9 +11,8 @@ h2 { font-size: 18pt; }
h3 { font-size: 16pt; }
h4 { font-size: 14pt; }
pre, code {
- font-family: "Menlo", "Consolas", "New Courier", Courier, monospace;
- font-size: 10pt;
- color: #060;
+ font-family: "Monaco", "Consolas", "New Courier", Courier, monospace;
+ font-size: 12pt;
}
.toc {
View
1 doc/layout/main.html
@@ -3,6 +3,7 @@
<head>
<title>{{title}}</title>
<link href="css/screen.css" media="screen,projection" rel="stylesheet" type="text/css">
+ <link href="css/github.css" media="screen,projection,print" rel="stylesheet" type="text/css">
<link href="css/print.css" media="print" rel="stylesheet" type="text/css">
</head>
<body>
View
2 lib/zombie/history.coffee
@@ -164,13 +164,15 @@ class History
#
# Push new state to the stack, do not reload
pushState: (state, title, url)->
+ url = URL.resolve(@_stack[@_index]?.url, url)
@_stack[++@_index] = new Entry(this, url, { state: state, title: title, pop: true })
# ### history.replaceState(state, title, url)
#
# Replace existing state in the stack, do not reload
replaceState: (state, title, url)->
@_index = 0 if @_index < 0
+ url = URL.resolve(@_stack[@_index]?.url, url)
@_stack[@_index] = new Entry(this, url, { state: state, title: title, pop: true })
# Location uses this to move to a new URL.
View
1 package.json
@@ -45,6 +45,7 @@
"devDependencies": {
"docco": "~0.3.0",
"express": "~2.5.1",
+ "highlight": "~0.2.0",
"ronn": "~0.3.8",
"vows": "~0.6.0"
},

0 comments on commit f8dd62b

Please sign in to comment.
Something went wrong with that request. Please try again.