How to use json2md - 9 common examples

To help you get started, we’ve selected a few json2md 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 rei / rei-cedar / build / component-docs-build.js View on Github external
const path = require('path')
const semverDiff = require('semver-diff')
const semver = require('semver')
const fs = require('fs-extra')
const json2md = require('json2md')
const vueDocgen = require('vue-docgen-api')

// Add convert for markdown anchor
json2md.converters.anchor = (anchor, json) => {
  if (!anchor.text) {
    return "";
  }

  return `[${anchor.text}](${anchor.source})`;
};

/**
 * convert .vue file into JSON object then convert to markdown file
 * @param {String} file -- file path of raw Vue component file
 * @param {Object} info -- packag.json
 */
function docsBuild(file, info) {
  console.log(`Processing file: ${file}\n`)
  const vueObj = vueDocgen.parse(file)
github rei / rei-cedar / build / vue-docs.js View on Github external
const path = require('path')
const semverDiff = require('semver-diff')
const semver = require('semver')
const fs = require('fs-extra')
const json2md = require('json2md')
const vueDocgen = require('vue-docgen-api')
const glob = require('glob')

// Add convert for markdown anchor
json2md.converters.anchor = (anchor, json) => {
  if (!anchor.text)
    return "";
  
  return `[${anchor.text}](${anchor.source})`;
};

// pull in *.vue files from directory
glob('src/+(components|compositions)/**/*.vue', {ignore: ['**/node_modules/**', '**/examples/**', '**/demos/**']}, (compErr, files) => {
  if(compErr)
    throw new Error(`Error while trying to find single file Vue components:\n${compErr}`)

  // convert *.vue files into JSON objects then convert to *.md files
  files.forEach((file) => {
    console.log(`Processing file: ${file}\n`)
    const vueObj = vueDocgen.parse(file)
github DefinitelyTyped / DefinitelyTyped / types / json2md / json2md-tests.ts View on Github external
it("Custom types", () => {
    const customConverter: json2md.ConverterCallback = (input, json2md) => {
        return `Hello ${input} world!`;
    };

    json2md.converters.customConverter = customConverter;

    json2md([
        {
            customConverter: EXAMPLE_STRING
        }
    ]);
});
github DefinitelyTyped / DefinitelyTyped / types / json2md / json2md-tests.ts View on Github external
it("Use converter", () => {
    const blockquote: string = json2md.converters.blockquote(EXAMPLE_STRING, json2md);
    const img: string = json2md.converters.img({
        title: EXAMPLE_STRING,
        source: EXAMPLE_STRING
    }, json2md);
});
github adoyle-h / Today-I-Learned / build.js View on Github external
];

    toc.push({name: '分类', level: 2});

    debug('categories=%O', categories);
    handleCategories(rootCategories, 3, structure);

    toc.push({name: '反馈问题或建议', level: 2});
    toc.push({name: '版权声明', level: 2});

    structure.push(
        {md: absPath('_docs/issue.md')},
        {md: absPath('_docs/license.md')}
    );

    const content = await json2md.async(structure);

    const file = absPath('README.md');
    await writeFile(file, content);
    console.log('writeFile: %s', file);
}
github adoyle-h / Today-I-Learned / build.js View on Github external
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);

const categories = {};
const toc = [];

json2md.converters.ul = async (array) => {
    return `- ${array.join('\n- ')}`;
};

json2md.converters.md = async (filepath) => {
    return await readFile(filepath, {encoding: 'utf8'});
};

json2md.converters.toc = (contents) => {
    const indent = 4;
    const ul = '-';
    const space = ' '.repeat(indent);
    const usedHeaders = {};
    const headers = [];

    contents.forEach((c) => {
        const {name, level} = c;
        let anchor = name.trim().toLowerCase().replace(/\s+/g, '-').replace(/\-+$/, '');
        const usedHeader = usedHeaders[anchor];
        if (usedHeader) {
            usedHeaders[anchor] = usedHeader + 1;
            anchor = `${anchor}-${usedHeader}`;
        } else {
            usedHeaders[anchor] = 1;
        }
github adoyle-h / Today-I-Learned / build.js View on Github external
.replace(/\s/g, '')
    .replace(/^(.)/, ($1) => $1.toUpperCase());

const getStat = util.promisify(FS.stat);
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);

const categories = {};
const toc = [];

json2md.converters.ul = async (array) => {
    return `- ${array.join('\n- ')}`;
};

json2md.converters.md = async (filepath) => {
    return await readFile(filepath, {encoding: 'utf8'});
};

json2md.converters.toc = (contents) => {
    const indent = 4;
    const ul = '-';
    const space = ' '.repeat(indent);
    const usedHeaders = {};
    const headers = [];

    contents.forEach((c) => {
        const {name, level} = c;
        let anchor = name.trim().toLowerCase().replace(/\s+/g, '-').replace(/\-+$/, '');
        const usedHeader = usedHeaders[anchor];
        if (usedHeader) {
            usedHeaders[anchor] = usedHeader + 1;
github adoyle-h / Today-I-Learned / build.js View on Github external
const absPath = (...paths) => Path.resolve(__dirname, ...paths);
const relativePath = (path) => Path.relative(__dirname, path);
const toCamelCase = (str) => str
    .replace(/\s(.)/g, ($1) => $1.toUpperCase())
    .replace(/\s/g, '')
    .replace(/^(.)/, ($1) => $1.toUpperCase());

const getStat = util.promisify(FS.stat);
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);

const categories = {};
const toc = [];

json2md.converters.ul = async (array) => {
    return `- ${array.join('\n- ')}`;
};

json2md.converters.md = async (filepath) => {
    return await readFile(filepath, {encoding: 'utf8'});
};

json2md.converters.toc = (contents) => {
    const indent = 4;
    const ul = '-';
    const space = ' '.repeat(indent);
    const usedHeaders = {};
    const headers = [];

    contents.forEach((c) => {
        const {name, level} = c;
github cypress-io / schema-tools / src / document / docs.ts View on Github external
}

  const headings = schemaNames(schemas)
  const toc = [
    {
      ul: headings.map(tocHeading),
    },
  ]

  let list = (title as any[]).concat(toc).concat(fragments)

  if (formats) {
    list = list.concat(documentCustomFormats(formats)).concat(titleLink)
  }

  return json2md(list)
}

json2md

A JSON to Markdown converter.

MIT
Latest version published 11 months ago

Package Health Score

69 / 100
Full package analysis

Popular json2md functions