Doxxo#format()
This method has the responsibility of producing the HTML documentation from a source object. This mostly means putting together template data and methods, running the template function, returning the resulting HTML.
Arguments
- source object - The source object to turn into HTML. This should have a
.sections
property with parsed data on it.
Doxxo.prototype.format = function(source) {
var firstSection, first, hasTitle, html,
opts = this.options,
sections = source.sections,
outdir = path.dirname(source.out);
function destination(file) {
if (_.isObject(file)) file = file.out;
return path.relative(outdir, path.resolve(opts.output, file));
}
sections.forEach(function(section) {
var code = highlightjs.highlight("javascript", section.codeText).value;
code = code.replace(/\s+$/, '');
section.codeHtml = "<div class='highlight'><pre>" + code + "</pre></div>";
section.docsHtml = marked(section.docsText, opts.marked);
return section;
});
firstSection = _.find(sections, function(section) {
return section.docsText.length > 0
});
if (firstSection) first = marked.lexer(firstSection.docsText)[0];
hasTitle = first && first.type === 'heading' && first.depth === 1;
return opts.template({
source: source,
sources: this.sources,
title: hasTitle ? first.text : source.name,
hasTitle: hasTitle,
sections: sections,
path: path,
destination: destination,
doxxo: this
});
}