partial.js 731 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Adds support for reusable partial jsdoc files.
  3. *
  4. * @module plugins/partial
  5. */
  6. const env = require('jsdoc/env');
  7. const fs = require('jsdoc/fs');
  8. const path = require('path');
  9. exports.handlers = {
  10. /**
  11. * Include a partial jsdoc
  12. *
  13. * @param e
  14. * @param e.filename
  15. * @param e.source
  16. * @example
  17. * @partial "partial_doc.jsdoc"
  18. */
  19. beforeParse(e) {
  20. e.source = e.source.replace(/(@partial ".*")+/g, $ => {
  21. const pathArg = $.match(/".*"/)[0].replace(/"/g, '');
  22. const fullPath = path.join(e.filename, '..', pathArg);
  23. const partialData = fs.readFileSync(fullPath, env.opts.encoding);
  24. return partialData;
  25. });
  26. }
  27. };