How to use the to-vfile.readSync function in to-vfile

To help you get started, we’ve selected a few to-vfile 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 Level / awesome / src / index.js View on Github external
const modules = {}

remark()
  .use(generator, { sections, modules })
  .use(toc, { maxDepth: 2, tight: true })
  .use(collapse, {
    test: 'Table of Contents',
    summary: () => 'Click to expand'
  })
  .use(github)
  .use(bookmarks, { modules })

  // Disable padding to lessen diff noise
  .use(stringify, { paddedTable: false, looseTable: true })

  .process(vfile.readSync(fp), (err, file) => {
    if (err) throw err
    console.error(report(file))
    vfile.writeSync(file)
  })
github remarkjs / remark-usage / example.js View on Github external
;(async function (){

// Say we are making a module that exports just enough Pi (3.14159).
// We’re documenting it with a readme file, [`example/readme.md`][example-md]:
console.log('markdown', exampleMd)

// …and an example script to document it [`example/example.js`][example-js-2]:
console.log('js', exampleJs)

// …If we use `remark-usage`, we can generate the `Usage` section
var path = require('path')
var vfile = require('to-vfile')
var remark = require('remark')
var usage = require('.')

var file = vfile.readSync({path: 'readme.md', cwd: 'example'})

var file = await remark()
  .use(usage)
  .process(file)

// Now, printing `file` (the newly generated readme) yields:
console.log('markdown', String(file))

// remark-usage-ignore-next
}())
github stdlib-js / stdlib / lib / node_modules / @stdlib / _tools / remark / plugins / remark-img-equations-src-urls / examples / index.js View on Github external

'use strict';

var join = require( 'path' ).join;
var toVFile = require( 'to-vfile' );
var remark = require( 'remark' );
var insertURLs = require( './../lib' );

var fpath;
var vfile;
var opts;
var out;

// Load a Markdown file...
fpath = join( __dirname, 'fixtures/simple.txt' );
vfile = toVFile.readSync( fpath );

// Specify the directory containing equation images:
opts = {
	'dir': './doc/img/', // relative to Markdown file
	'prefix': ''         // no prefix
};

// Insert src URLs:
out = remark().use( insertURLs, opts ).processSync( vfile );

// Output the results:
console.log( out.contents );
github graalvm / graaljs / tools / doc / addon-verify.js View on Github external
// that the C++ code compiles and the js code runs.
// Add .gyp files which will be used to compile the C++ code.
// Modify the require paths in the js code to pull from the build tree.
// Triggered from the build-addons target in the Makefile and vcbuild.bat.

const { mkdir, writeFile } = require('fs');
const { resolve } = require('path');
const vfile = require('to-vfile');
const unified = require('unified');
const remarkParse = require('remark-parse');

const rootDir = resolve(__dirname, '..', '..');
const doc = resolve(rootDir, 'doc', 'api', 'addons.md');
const verifyDir = resolve(rootDir, 'test', 'addons');

const file = vfile.readSync(doc, 'utf8');
const tree = unified().use(remarkParse).parse(file);
const addons = {};
let id = 0;
let currentHeader;

const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/;
tree.children.forEach((node) => {
  if (node.type === 'heading') {
    currentHeader = file.contents.slice(
      node.children[0].position.start.offset,
      node.position.end.offset);
    addons[currentHeader] = { files: {} };
  } else if (node.type === 'code') {
    const match = node.value.match(validNames);
    if (match !== null) {
      addons[currentHeader].files[match[1]] = node.value;
github rehypejs / rehype / test / parse-error.js View on Github external
t.test(fixture, function(st) {
      var file = vfile.readSync(path.join(fp, 'index.html'), 'utf8')
      var messages = JSON.parse(
        fs.readFileSync(path.join(fp, 'messages.json'), 'utf8')
      )

      file.dirname = ''

      rehype()
        .data('settings', {emitParseErrors: true})
        .parse(file)

      st.deepEqual(
        JSON.parse(JSON.stringify(file.messages)),
        messages,
        'should emit messages for `' + fixture + '`'
      )
github remarkjs / remark-frontmatter / test / index.js View on Github external
t.test(fixture, function(st) {
      var input = vfile.readSync(join(base, fixture, 'input.md'))
      var treePath = join(base, fixture, 'tree.json')
      var outputPath = join(base, fixture, 'output.md')
      var output
      var actual
      var expected
      var config
      var proc

      try {
        config = JSON.parse(read(join(base, fixture, 'config.json')))
      } catch (error) {}

      proc = remark().use(frontmatter, config)
      actual = proc.parse(input)

      try {
github orgapp / orgajs / examples / example / index.js View on Github external
var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var parse = require('orga-unified')
var mutate = require('orga-rehype')
var stringify = require('rehype-stringify')
var doc = require('rehype-document')

unified()
  .use(parse)
  .use(mutate)
  .use(doc, {title: 'Hi!'})
  .use(stringify)
  .process(vfile.readSync('./README.org'), function (err, file) {
    console.error(report(err || file))
    console.log(String(file))
  })
github department-of-veterans-affairs / veteran-facing-services-tools / packages / documentation / plugins / remark / gatsby-remark-mdx-mermaid / index.js View on Github external
visit(markdownAST, 'code', async (node) => {
    const lang = (node.lang || '').toLowerCase();
    const fileContent = vfile.readSync(markdownNode.fileAbsolutePath);

    if (lang === language) {
      await remark()
        .use(mermaid)
        .process(fileContent, (err, file) => {
          if (err) throw err;

          const mermaidSrcMatch = file.messages.filter(
            item => item.message.source === node.value
          )[0];

          node.type = 'html';
          node.value = `<img src="${mermaidSrcMatch.message.imgSrc}">`;
        });
    }
  });
github nitin42 / linkify-markdown / src / linkify.js View on Github external
const read = file => vfile.readSync(file)

to-vfile

vfile utility to read and write to the file system

MIT
Latest version published 1 year ago

Package Health Score

59 / 100
Full package analysis