mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
link to individual line numbers in source files (#316)
This commit is contained in:
parent
655dfa0f5f
commit
070903fb88
@ -133,12 +133,15 @@ function hasUrlPrefix(text) {
|
||||
* @param {string=} linktext - The text to display for the link, or `longname` if no text is
|
||||
* provided.
|
||||
* @param {string=} cssClass - The CSS class (or classes) to include in the link's `<a>` tag.
|
||||
* @param {string=} fragmentId - The fragment identifier (for example, `name` in `foo.html#name`) to
|
||||
* append to the link target.
|
||||
* @return {string} The HTML link, or a plain-text string if the link is not available.
|
||||
*/
|
||||
var linkto = exports.linkto = function(longname, linktext, cssClass) {
|
||||
var linkto = exports.linkto = function(longname, linktext, cssClass, fragmentId) {
|
||||
var catharsis = require('catharsis');
|
||||
|
||||
var classString = cssClass ? util.format(' class="%s"', cssClass) : '';
|
||||
var fragmentString = fragmentId ? '#' + fragmentId : '';
|
||||
var text = linktext || longname;
|
||||
var url = hasOwnProp.call(longnameToUrl, longname) && longnameToUrl[longname];
|
||||
var parsedType;
|
||||
@ -168,7 +171,7 @@ var linkto = exports.linkto = function(longname, linktext, cssClass) {
|
||||
return text;
|
||||
}
|
||||
else {
|
||||
return util.format('<a href="%s"%s>%s</a>', url, classString, text);
|
||||
return util.format('<a href="%s%s"%s>%s</a>', url, fragmentString, classString, text);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
17
templates/default/static/scripts/linenumber.js
Normal file
17
templates/default/static/scripts/linenumber.js
Normal file
@ -0,0 +1,17 @@
|
||||
(function() {
|
||||
var counter = 0;
|
||||
var numbered;
|
||||
var source = document.getElementsByClassName('prettyprint source');
|
||||
|
||||
if (source && source[0]) {
|
||||
source = source[0].getElementsByTagName('code')[0];
|
||||
|
||||
numbered = source.innerHTML.split('\n');
|
||||
numbered = numbered.map(function(item) {
|
||||
counter++;
|
||||
return '<span id="line' + counter + '"></span>' + item;
|
||||
});
|
||||
|
||||
source.innerHTML = numbered.join('\n');
|
||||
}
|
||||
})();
|
||||
@ -65,7 +65,7 @@ var self = this;
|
||||
<?js if (data.meta) {?>
|
||||
<dt class="tag-source">Source:</dt>
|
||||
<dd class="tag-source"><ul class="dummy"><li>
|
||||
<?js= self.linkto(meta.filename) ?>, line <?js= meta.lineno ?>
|
||||
<?js= self.linkto(meta.filename) ?>, <?js= self.linkto(meta.filename, 'line ' + meta.lineno, null, 'line' + meta.lineno) ?>
|
||||
</li></ul></dd>
|
||||
<?js } ?>
|
||||
|
||||
|
||||
@ -33,5 +33,6 @@
|
||||
</footer>
|
||||
|
||||
<script> prettyPrint(); </script>
|
||||
<script src="scripts/linenumber.js"> </script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -314,6 +314,11 @@ describe("jsdoc/util/templateHelper", function() {
|
||||
var link = helper.linkto('http://example.com', 'text');
|
||||
expect(link).toBe('<a href="http://example.com">text</a>');
|
||||
});
|
||||
|
||||
it('returns a link with a fragment ID if a URL and fragment ID are specified', function() {
|
||||
var link = helper.linkto('LinktoFakeClass', null, null, 'fragment');
|
||||
expect(link).toBe('<a href="fakeclass.html#fragment">LinktoFakeClass</a>');
|
||||
});
|
||||
});
|
||||
|
||||
describe("htmlsafe", function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user