documentation/lib/inline_tokenizer.js
Tom MacWright 3da1ff6dd0 Source-sorting by default (#410)
* Source-sorting by default

Many changes

* Uses a new version of module-deps that exposes a sort key
  we use to sort documentation.
* Adds inference for methods in objects
* Groups events into a separate comment property

* Add jsdoc property. Refs https://github.com/documentationjs/documentation/pull/388#issuecomment-215791547

* Namespaces and paths

* More powerful paths: paths now include name, kind, and scope
* comments now include a 'namespace' property with a formatted namespace

* Fix tests

* Re-ignore fonts

* Nix sourceKey from output

* Pin dependency versions

* Fix module-deps-sortable ref

* Update tests for right deps
2016-04-29 18:09:52 -04:00

58 lines
1.6 KiB
JavaScript

'use strict';
function makeTokenizer(type, regex) {
var tokenizer = function (eat, value, silent) {
var match = regex.exec(value);
if (!match) {
return;
}
if (silent) {
return true;
}
return eat(match[0])({
type: type,
url: match[1],
title: null,
jsdoc: true,
children: [{
type: 'text',
value: match[2] || match[1]
}]
});
};
tokenizer.notInLink = true;
tokenizer.locator = function (value, fromIndex) {
return value.indexOf('{@' + type, fromIndex);
};
return tokenizer;
}
var tokenizeLink = makeTokenizer('link', /^\{@link\s+(.+?)(?:[\s|](.*?))?\}/);
var tokenizeTutorial = makeTokenizer('tutorial', /^\{@tutorial\s+(.+?)(?:[\s|](.*?))?\}/);
/**
* A remark plugin that installs
* [tokenizers](https://github.com/wooorm/remark/blob/master/doc/remarkplugin.3.md#function-tokenizereat-value-silent)
* and [locators](https://github.com/wooorm/remark/blob/master/doc/remarkplugin.3.md#function-locatorvalue-fromindex)
* for JSDoc inline `{@link}` and `{@tutorial}` tags.
*
* This does not handle the `[text]({@link url})` and `[text]({@tutorial url})` forms of these tags.
* That's a JSDoc misfeature; just use regular markdown syntax instead: `[text](url)`.
*
* @param {Object} processor - remark instance
* @returns {undefined}
*/
module.exports = function (processor) {
var proto = processor.Parser.prototype;
proto.inlineTokenizers.tokenizeLink = tokenizeLink;
proto.inlineTokenizers.tokenizeTutorial = tokenizeTutorial;
var methods = proto.inlineMethods;
methods.splice(methods.indexOf('inlineText'), 0,
'tokenizeLink', 'tokenizeTutorial');
};