Skip to content

Instantly share code, notes, and snippets.

@muratpurc
Created September 22, 2011 09:02
Show Gist options
  • Save muratpurc/1234383 to your computer and use it in GitHub Desktop.
Save muratpurc/1234383 to your computer and use it in GitHub Desktop.
JS: JSDOC plugin to use for extended documentations
/**
* Replaces occurance of userdefined docblocks within js sourcecode against HTML tags <pre><code>...</pre></code>
*
* Example:
* @xcode
* var foobar = 123456;
* /@xcode
*
* Will be replaced against:
* <pre><code>
* var foobar = 123456;
* </pre></code>
*/
IO.include("frame/Dumper.js");
JSDOC.PluginManager.registerPlugin(
"JSDOC.commentExtendedCode",
{
onDocCommentSrc: function(comment) {
if (comment.src.search('@xcode') == -1) {
return;
}
// print(Dumper.dump(comment));
var content = comment.src,
startPos = content.search('@xcode') + 7,
endPos = content.search('/@xcode'),
extractedContent = content.substr(startPos, endPos - startPos),
changedContent = extractedContent.replace(/</g, '&lt;').replace(/>/g, '&gt;');
comment.src = content.replace('/@xcode', '</pre></code>')
.replace('@xcode', '<pre><code>')
.replace(extractedContent, changedContent);
// @fixme: Each known variant of regexp didn't worked here even if
// all tests in browser were ok???
/*
var regex = /@xcode(.*)\/@xcode/gi;
// var match = regex.exec(content);
var match = content.match(regex);
// print(Dumper.dump(match));
if (match) {
var content = '<code><pre>' + match[1].replace('<', '&lt;').replace('>', '&gt;') + '</pre></code>';
comment.src = comment.src.replace(match[0], content);
}
*/
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment