@@ -79,6 +79,13 @@ follows it, and create an individual **section** for it.
79
79
save = (docsText , codeText ) ->
80
80
sections .push {docsText, codeText}
81
81
82
+ if language .literate
83
+ for line, i in lines
84
+ lines[i] = if match = (/ ^ ([ ] {4} | \t )/ ).exec line
85
+ line[match[0 ].length .. ]
86
+ else
87
+ ' # ' + line
88
+
82
89
for line in lines
83
90
if line .match (language .commentMatcher ) and not line .match (language .commentFilter )
84
91
if hasCode
@@ -89,6 +96,7 @@ follows it, and create an individual **section** for it.
89
96
hasCode = yes
90
97
codeText += line + ' \n '
91
98
save docsText, codeText
99
+
92
100
sections
93
101
94
102
Highlights parsed sections of code, using **Pygments** over stdio,
@@ -150,7 +158,7 @@ the specified output path.
150
158
151
159
generateHtml = (source , sections , config ) ->
152
160
destination = (filepath ) ->
153
- path .join (config .output , path .basename (filepath, path . extname (filepath) ) + ' .html' )
161
+ path .join (config .output , path .basename (filepath, config . fullExtension ) + ' .html' )
154
162
title = path .basename source
155
163
dest = destination source
156
164
html = config .doccoTemplate {
@@ -170,16 +178,17 @@ Helpers & Setup
170
178
171
179
Require our external dependencies.
172
180
181
+ _ = require ' underscore'
173
182
fs = require ' fs'
174
183
path = require ' path'
175
184
marked = require ' marked'
176
- {spawn , exec } = require ' child_process'
177
185
commander = require ' commander'
186
+ {spawn , exec } = require ' child_process'
178
187
179
188
Read resource file and return its content.
180
189
181
190
getResource = (name ) ->
182
- fullPath = path .join __dirname , ' .. ' , ' resources' , name
191
+ fullPath = path .join __dirname , ' resources' , name
183
192
fs .readFileSync (fullPath).toString ()
184
193
185
194
Languages are stored in JSON format in the file `resources/languages.json`
@@ -218,7 +227,15 @@ Build out the appropriate matchers and delimiters for each language.
218
227
219
228
Get the current language we're documenting, based on the extension.
220
229
221
- getLanguage = (source , config ) -> languages[config .extension or path .extname (source)]
230
+ getLanguage = (source , config ) ->
231
+ ext = config .fullExtension = config .extension or path .extname (source)
232
+ lang = languages[ext]
233
+ if lang .name is ' markdown'
234
+ codeExt = path .extname (path .basename (source, ext))
235
+ if codeExt and codeLang = languages[codeExt]
236
+ config .fullExtension = codeExt + ext
237
+ lang = _ .extend {}, codeLang, {literate : yes }
238
+ lang
222
239
223
240
Ensure that the destination directory exists.
224
241
@@ -231,22 +248,6 @@ Ensure that the destination directory exists.
231
248
if er then cb er, made else ensureDirectory dir, cb, made
232
249
cb er, made
233
250
234
- Micro-templating, originally by John Resig, borrowed by way of
235
- [ Underscore.js ] (http://documentcloud.github.com/underscore/).
236
-
237
- template = (str ) ->
238
- new Function ' obj' ,
239
- ' var p=[],print=function(){p.push.apply(p,arguments);};' +
240
- ' with(obj){p.push(\' ' +
241
- str .replace (/ [\r\t\n ] / g , " " )
242
- .replace (/ '(?=[^ <] * %>)/ g ," \t " )
243
- .split (" '" ).join (" \\ '" )
244
- .split (" \t " ).join (" '" )
245
- .replace (/ <%=(. +? )%>/ g , " ',$1,'" )
246
- .split (' <%' ).join (" ');" )
247
- .split (' %>' ).join (" p.push('" ) +
248
- " ');}return p.join('');"
249
-
250
251
The start of each Pygments highlight block.
251
252
252
253
highlightStart = ' <div class="highlight"><pre>'
@@ -303,7 +304,7 @@ Run Docco over a list of `sources` with the given `options`.
303
304
config .sources = resolved .filter ((source ) -> getLanguage source, config).sort ()
304
305
console .log " docco: skipped unknown type (#{ m} )" for m in resolved when m not in config .sources
305
306
306
- config .doccoTemplate = template fs .readFileSync (config .template ).toString ()
307
+ config .doccoTemplate = _ . template fs .readFileSync (config .template ).toString ()
307
308
doccoStyles = fs .readFileSync (config .css ).toString ()
308
309
309
310
ensureDirectory config .output , ->
@@ -333,5 +334,5 @@ Resolve a wildcard `source` input to the files it matches.
333
334
Public API
334
335
----------
335
336
336
- module.exports = {run, document, parse, resolveSource, version, defaults,
337
- languages, ensureDirectory}
337
+ module .exports = {run, document , parse, resolveSource, version, defaults,
338
+ languages, ensureDirectory}
0 commit comments