How to use markdown-magic - 10 common examples

To help you get started, we’ve selected a few markdown-magic 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 DavidWells / netlify-functions-workshop / _scripts / docs.js View on Github external
}).map((file) => {
        const filePath = path.join(lessonsPath, file)
        const examples = globby.sync([
          // `!node_modules`,
          `${filePath}/**/**.md`,
          `!${filePath}/node_modules/**/**`,
          `!${filePath}/**/node_modules/**/**`,
          // `!${filePath}/node_modules/**/**.md`,
          // `!${filePath}/**/node_modules/**/**.md`,
        ])

        // console.log('examples', examples)
        // console.log('filePath', filePath)
        // process.exit(1)
        let md = `### ${formatName(file)}

${generateTable(examples)}
`
        return md
github netlify / cli / scripts / generateCommandData.js View on Github external
module.exports = function generateCommandData() {
  const commandsPath = path.join(__dirname, '..', 'src/commands')
  const netlifyDevPath = path.join(__dirname, '..', 'node_modules/netlify-dev-plugin/src/commands')
  // console.log('commandsPath', commandsPath)
  const commands = globby.sync([`${commandsPath}/**/**.js`, `${netlifyDevPath}/**/**.js`])

  const allCommands = commands.map(file => {
    let cmd = {}
    try {
      cmd = require(file)
    } catch (e) {
      throw e
    }
    const command = commandFromPath(file)
    const parentCommand = command.split(':')[0]
    const parent = command === parentCommand ? true : false
    return {
      command: command,
      commandGroup: parentCommand,
      isParent: parent,
      path: file,
github netlify / cli / scripts / docs.js View on Github external
markdownMagic(markdownFiles, config, () => {
  /* Post process the docs */
  const processedDocs = globby.sync(['../docs/**/**.md'])
  processedDocs.map(f => {
    const filePath = path.resolve(f)
    const fileContents = fs.readFileSync(filePath, 'utf8')

    // Fix garbage chalk output
    const updatedContents = fileContents.replace(/\[92m/, '').replace(/\[39m/, '')
    fs.writeFileSync(filePath, updatedContents)
  })
  console.log('Docs updated!')
})
github DavidWells / netlify-functions-workshop / _scripts / docs.js View on Github external
GENERATE_LESSONS_STEPS(content, options, instance) {
      // console.log('instance.outputDir', instance.outputDir)

      // debug single file
      // if (instance.outputDir !== "_instructor/events/step-functions") {
      //   return content
      // }
      const lessonFiles = globby.sync(['**', '!node_modules'], {
        cwd: instance.outputDir
      })
      const jsRegex = /\/\* Step([\s\S]*?)\*\//g
      const ymlRegex = / *?# Step([\s\S]*?) #\n*?/g
      const htmlRegex = / *?\<\!-- Step([\s\S]*?) ?--\>\n*?/g
      var matches = []
      if (lessonFiles) {
        lessonFiles.map((f) => {
          const filePath = path.join(instance.outputDir, f)
          if (fs.lstatSync(filePath).isDirectory()) {
            // skip dirs
            return
          }
          const fileContents = fs.readFileSync(filePath, 'utf8')
          const fileType = path.extname(f)
github DavidWells / serverless-workshop / docs.js View on Github external
GENERATE_LESSONS_STEPS(content, options, instance) {

      //console.log('instance.outputDir', instance.outputDir)

      // debug single file
      // if (instance.outputDir !== "_instructor/events/step-functions") {
      //   return content
      // }
      const lessonFiles = globby.sync(['**', '!node_modules'], {
        cwd: instance.outputDir
      })
      const jsRegex = /\/\* Step([\s\S]*?)\*\//g
      const ymlRegex = / *?# Step([\s\S]*?) #\n*?/g
      const htmlRegex = / *?\<\!-- Step([\s\S]*?) ?--\>\n*?/g
      var matches = []
      if (lessonFiles) {
        lessonFiles.map((f) => {
          const filePath = path.join(instance.outputDir, f)
          if (fs.lstatSync(filePath).isDirectory()) {
            // skip dirs
            return;
          }
          const fileContents = fs.readFileSync(filePath, 'utf8')
          const fileType = path.extname(f)
          var regex = jsRegex
github DavidWells / serverless-workshop / postDocs.js View on Github external
const path = require('path')
const chalk = require('chalk')
const markdownMagic = require('markdown-magic')
const globby = require('markdown-magic').globby

console.log('Post process lesson files')

const removeComments = / *?\<\!-- ([\s\S]*?) ?--\>\n\n*?/g

const directories = [
  'lessons-code-complete/**/**.md',
  'lessons/**/**.md',
  '!node_modules'
]

const lessonFiles = globby.sync(directories)

if (lessonFiles) {
  console.log(chalk.yellow('Removing comments from student files'))
  lessonFiles.map((f) => {
    const filePath = path.resolve(f)
    // console.log('filePath', filePath)
    const fileContents = fs.readFileSync(filePath, 'utf8')
    //console.log(fileContents)
    const fileType = path.extname(f)

    const updatedContents = fileContents.replace(removeComments, '')
    fs.writeFileSync(filePath, updatedContents)
    //console.log('updatedContents', updatedContents)
  })
  console.log(chalk.green('All Done!'))
}
github serverless / utils / scripts / js / docs-gen.js View on Github external
const magicConfig = {
      transforms: {
        METHODS() {
          const categories = generateCategoryDocs(srcData)
          return reduceObjIndexed(
            (markdown, category) => {
              return markdown + renderCategoryMarkdown(category)
            },
            '',
            categories
          )
        }
      }
    }

    markdownMagic([API_README_PATH], magicConfig, (error) => {
      if (error) {
        // eslint-disable-next-line no-console
        console.log('Error while generating docs')
        return reject(error)
      }
      // eslint-disable-next-line no-console
      console.log('🎉 Docs updated!')
      resolve()
    })
  })
github serverless / examples / generate-readme.js View on Github external
SERVERLESS_EXAMPLE_TABLE() {
      const examples = globby.sync(['**/package.json', '!node_modules/**/package.json', '!**/node_modules/**/package.json', '!package.json']);
      // Make table header
      let md = '| Example | Runtime  |\n';
      md += '|:--------------------------- |:-----|\n';
      examples.forEach((example) => {
        const data = JSON.parse(fs.readFileSync(example, 'utf8'));
        const dirname = path.dirname(example);
        const exampleUrl = `https://github.com/serverless/examples/tree/master/${dirname}`;
        const runtime = getRuntime(dirname);
        const description = (data.description) ? `<br> ${data.description}` : '';
        // add table rows
        md += `| [${formatPluginName(data.name)}](${exampleUrl}) ${description} | ${runtime} |\n`;
      });

      return md;
    },
    /*
github serverless / blog / validate.js View on Github external
"name": "David Wells",
  "github": "davidwells",
  "avatar": "https://avatars2.githubusercontent.com/u/532272?v=3&s=60",
  "bio": {
    "short": "David Wells is a developer at Serverless, Inc.",
    "long": "David is a Full Stack JavaScript Developer, entrepreneur, past life marketer. Developer @ http://serverless.com "
  }
}

const authorArray = fs.readdirSync(authorDirectory).map((author) =>{
  return author.replace('.json', '')
})


// test author directory
globby(['*', '!node_modules'], {
  cwd: authorDirectory
}).then(paths => {
    paths.forEach((file) => {
      const fp = path.join(authorDirectory, file)
      if (file.match(/\.json/)) {
        const author = fs.readFileSync(fp, 'utf8')
        const valid = hasSameProps(authorData, JSON.parse(author))
        if (!valid) {
          const msg = `${file} has missing value in author profile.
Author data must match (if no value applies use false):
${JSON.stringify(authorData, null, 2)}`
          throw new Error(msg)
        }
      } else {
        // not json throw error
        throw new Error(`${file} file type not allowed in authors directory ${file}`);
github serverless / blog / validate.js View on Github external
paths.forEach((file) => {
      const fp = path.join(authorDirectory, file)
      if (file.match(/\.json/)) {
        const author = fs.readFileSync(fp, 'utf8')
        const valid = hasSameProps(authorData, JSON.parse(author))
        if (!valid) {
          const msg = `${file} has missing value in author profile.
Author data must match (if no value applies use false):
${JSON.stringify(authorData, null, 2)}`
          throw new Error(msg)
        }
      } else {
        // not json throw error
        throw new Error(`${file} file type not allowed in authors directory ${file}`);
      }
    })

markdown-magic

Automatically update markdown files with content from external sources

MIT
Latest version published 4 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages