Created
September 22, 2011 09:02
-
-
Save muratpurc/1234383 to your computer and use it in GitHub Desktop.
JS: JSDOC plugin to use for extended documentations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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, '<').replace(/>/g, '>'); | |
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('<', '<').replace('>', '>') + '</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