How to use jsdoc-to-markdown - 10 common examples

To help you get started, we’ve selected a few jsdoc-to-markdown examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ff0000-ad-tech / ad-docs / lib / index.js View on Github external
async function createMarkdownFromClasses(packageName, outputDir, api, readme) {
	console.log('createMarkdownFromClasses()')

	const { outputDocsDir, templateData } = setup(outputDir, true)

	// reduce templateData to an array of class names
	const classNames = templateData.reduce((classNames, identifier) => {
		if (identifier.kind === 'class') classNames.push(identifier.name)
		return classNames
	}, [])

	// create a documentation file for each class
	for (const className of classNames) {
		const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`
		const output = jsdoc2md.renderSync({ data: templateData, template: template })
		fs.writeFileSync(path.resolve(outputDocsDir, `${className}.md`), output)
	}

	let apiOutput = await prepApi(api, templateData)

	apiOutput = mergeAndRepathHeaderLink(apiOutput, './')

	// use to convert links from page scroll to nav to other md files
	apiOutput = apiOutput.replace(/(\[)([^\]]+)(\]\(#([^\)]+)\))/g, (full, a, b, c, d) => {
		// split to see if it is a method or property
		const split = d.split('.')
		return split.length &gt; 1 ? `<a href="./docs/${split[0]}.md#${d}">${b}</a>` : b
	})

	combineAndWrite(packageName, outputDir, apiOutput, readme)
}
github ff0000-ad-tech / ad-docs / lib / doc_master_nav.js View on Github external
fs.readFile(obj.api, (err, apiData) => {
				if (err) reject(err)
				console.log(obj.name)
				// console.log(obj.files)
				const templateData = jsdoc2md.getTemplateDataSync({ files: obj.files, configure: docUtils.CONFIG_PATH })
				// console.log(templateData)

				let output = jsdoc2md.renderSync({
					data: templateData,
					template: apiData.toString(),
					helper: __dirname + '/helper.js'
				})

				// remap the links
				output = output.replace(/(\[)([^\]]+)(\]\(#([^\)]+)\))/g, (full, a, b, c, d) => {
					// split to see if it is a method or property
					const split = d.split('.')
					let subPath = ''
					if (split.length > 1) {
						subPath = `#${d}`
					} else {
						// check 'd' for 'new_[name]_new' leading word
						split[0] = split[0].replace(/(new_)(.+)(_new)/, '$2')
					}
github ff0000-ad-tech / ad-docs / lib / doc_master_nav.js View on Github external
fs.readFile(obj.api, (err, apiData) => {
				if (err) reject(err)
				console.log(obj.name)
				// console.log(obj.files)
				const templateData = jsdoc2md.getTemplateDataSync({ files: obj.files, configure: docUtils.CONFIG_PATH })
				// console.log(templateData)

				let output = jsdoc2md.renderSync({
					data: templateData,
					template: apiData.toString(),
					helper: __dirname + '/helper.js'
				})

				// remap the links
				output = output.replace(/(\[)([^\]]+)(\]\(#([^\)]+)\))/g, (full, a, b, c, d) => {
					// split to see if it is a method or property
					const split = d.split('.')
					let subPath = ''
					if (split.length > 1) {
						subPath = `#${d}`
					} else {
github pattern-lab / patternlab-node / packages / core / scripts / docs.js View on Github external
//   .then(x => {
//     console.log(x);
//   });

doc
  .render({
    'example-lang': 'javascript',
    files: path.resolve(process.cwd(), './core/index.js'),
    'name-format': 'backticks',
    template: fs.readFileSync('./scripts/api.handlebars', 'utf8'),
  })
  .then(x => {
    fs.outputFile(path.resolve(process.cwd(), './docs/README.md'), x);
  });

doc
  .render({
    'example-lang': 'javascript',
    files: path.resolve(process.cwd(), './core/lib/events.js'),
    'name-format': 'backticks',
    template: fs.readFileSync('./scripts/events.handlebars', 'utf8'),
  })
  .then(x => {
    fs.outputFile(path.resolve(process.cwd(), './docs/events.md'), x);
  });
github apifytech / apify-js / website / tools / build_docs.js View on Github external
namespaces.forEach((name) => {
        const template = `{{#namespace name="${name}"}}{{>docs}}{{/namespace}}`;
        console.log(`Rendering ${name}, template: ${template}`); // eslint-disable-line no-console
        const output = jsdoc2md.renderSync(getRenderOptions(template, templateData));
        const markdown = generateFinalMarkdown(name, output);
        fs.writeFileSync(path.resolve(sourceFilesOutputDir, `${name}.md`), markdown);
    });
github typicode / react-lodash / generate / index.js View on Github external
function getDocs() {
  // Get all lodash functions
  const functionNames = _.functions(_)
  console.log(`Found ${functionNames.length} functions`)

  // Find all files associated to lodash functions
  const files = functionNames
    .map(functionName =>
      path.join(__dirname, `../node_modules/lodash/${functionName}.js`)
    )
    .filter(fs.existsSync)
  console.log(`Found ${files.length} files`)

  // Parse JSDoc for each file
  const docs = jsdoc2md
    .getTemplateDataSync({ files })
    .filter(doc => functionNames.includes(doc.name))
  console.log(`Found ${docs.length} docs`)

  return docs
}
github discordjs / discord.js / docs / generator / index.js View on Github external
#!/usr/bin/env node
/* eslint-disable no-console */
const fs = require('fs');
const jsdoc2md = require('jsdoc-to-markdown');
const Documentation = require('./documentation');
const custom = require('../custom/index');
const config = require('./config');

process.on('unhandledRejection', console.error);

console.log(`Using format version ${config.GEN_VERSION}.`);
console.log('Parsing JSDocs in source files...');

jsdoc2md.getTemplateData({ files: [`./src/*.js`, `./src/**/*.js`] }).then(data => {
  console.log(`${data.length} items found.`);
  const documentation = new Documentation(data, custom);

  console.log('Serializing...');
  let output = JSON.stringify(documentation.serialize(), null, 0);

  if (config.compress) {
    console.log('Compressing...');
    output = require('zlib').deflateSync(output).toString('utf8');
  }

  if (!process.argv.slice(2).includes('test')) {
    console.log('Writing to docs.json...');
    fs.writeFileSync('./docs/docs.json', output);
  }
github electron-userland / electron-builder / scripts / jsdoc2md.js View on Github external
sortOptions(pages)
  // sortAutoUpdate(pages)

  for (const page of pages) {
    const finalOptions = Object.assign({
      data: page.data,
      "property-list-format": page === pages[0] || page === pages[3] || page === pages[1] ? "list" : "table",
      "param-list-format": page === pages[1] ? "list" : "table",
    }, jsdoc2MdOptions)

    if (page === pages[0]) {
      finalOptions["heading-depth"] = 1
    }

    let content = await jsdoc2md.render(finalOptions)

    if (page.mainHeader != null && content.startsWith("## Modules")) {
      content = "## API" + content.substring("## Modules".length)
    }
    if (page.mainHeader != null) {
      content = "## API" + content.substring(content.indexOf("\n", content.indexOf("##")))
    }

    await writeDocFile(path.join(__dirname, "..", "docs", page.page), content)
  }
}
github ff0000-ad-tech / ad-docs / lib / index.js View on Github external
async function prepApi(api, templateData) {
	const apiData = await fs.readFileAsync(api)

	// create the main README
	return jsdoc2md.renderSync({
		data: templateData,
		template: apiData.toString(),
		helper: __dirname + '/helper.js'
	})
}
github ff0000-ad-tech / ad-docs / lib / index.js View on Github external
function setup(outputDir, createDocsDir) {
	// input and output paths
	const inputFiles = [outputDir + 'index.js'].concat(docUtils.readDirRecursive(outputDir + 'lib'))

	// get template data
	const templateData = jsdoc2md.getTemplateDataSync({ files: inputFiles, configure: docUtils.CONFIG_PATH })

	if (createDocsDir) {
		const outputDocsDir = outputDir + 'docs'
		if (!fs.existsSync(outputDocsDir)) {
			fs.mkdirSync(outputDocsDir)
		}
		return { outputDocsDir, templateData }
	}

	return templateData
}

jsdoc-to-markdown

Generates markdown API documentation from jsdoc annotated source code

MIT
Latest version published 3 months ago

Package Health Score

67 / 100
Full package analysis