jbt / docker

Documentation generator
http://jbt.github.com/docker
MIT License
234 stars 56 forks source link

Filename string rendering on Windows #26

Closed draeton closed 11 years ago

draeton commented 11 years ago

When rendering the file name var in the head script, more filtering is needed on Windows platforms. The backslash path separator is operating as the start of an escape sequence when file and/or directory names start with a "u", so the backslash also needs to be escaped.

For example, if my file name is:

c:\home\github\stitches\src\js\util\util.js

It is rendered as:

'c:\home\github\stitches\src\js\util\util.js'

Instead of:

'c:\\home\\github\\stitches\\src\\js\\util\\util.js'

Which causes a syntax error in JavaScript. I imagine the change should be made in the Docker.prototype.renderCodeHtml method. I came up with this, but you may want to be more thorough:

filename = filename.replace(this.inDir,'').replace(/^[\/\\]/,'');
if (pathSeparator === "\\") {
  filename = filename.replace(/\\/g, '\\\\');
}

Very nice tool, by the way. I actually posted a question about this exact thing way back in 2011 - http://stackoverflow.com/questions/7128721/docco-like-tool-that-accommodates-jsdoc-style-comments

jbt commented 11 years ago

Ah good spot - I thought I'd taken care of stuff like this but clearly I forgot about \u happening anywhere. I guess the same would also happen if there was a \x. I think the neatest way to do it would to be use some JSON.stringify in the template - I'll take a look today and see about getting that added and tested.

draeton commented 11 years ago

Perfect!