How to use the remark.parse function in remark

To help you get started, we’ve selected a few remark 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 andreypopp / mocha-doctest / src / compile.js View on Github external
export function compile(source: string, options: Options = {}) {

  // Find all code blocks in markdown
  let node = Remark.parse(source);
  let testCaseList = [];
  mdastVisitNode(node, 'code', (node, index, parent) => {
    let prev = parent.children[index - 1];
    let title = null;
    if (prev && prev.type === 'paragraph') {
      title = mdastToString(prev);
    }
    if (title && title[title.length - 1] === ':') {
      title = title.slice(0, title.length - 1);
    }
    if (SUPPORTED_LANG[node.lang]) {
      testCaseList.push({
        title: title,
        lang: node.lang,
        value: node.value
      });
github bcgov / devhub-app-web / app-web / plugins / gatsby-source-github-all / utils / plugins.js View on Github external
title: () => {
        // attempt to generate a title by finding the first h1 in markdown content
        // if none title should be fileName
        const ast = remark.parse(data.content);
        // make title file name by default
        let title = file.metadata.fileName;
        // visit heading
        visit(ast, 'heading', node => {
          // is node on first line and a h1 or h2?
          if (title === file.metadata.fileName && (node.depth === 1 || node.depth === 2)) {
            // accept headers up to 3rd line of markdown file
            if (node.position.start.line < 3) {
              title = node.children[0].value;
            }
          }
        });
        return title;
      },
      ignore: () => false, // should this markdown siphon node be ignored
github bcgov / devhub-app-web / app-web / gatsby / onCreateNode.js View on Github external
node,
      name: 'resourceType',
      value: RESOURCE_TYPES.EVENTS,
    });
    createNodeField({
      node,
      name: 'standAlonePath',
      value: node.link,
    });
  }

  if (isMarkdownRemark(node)) {
    const parentNode = getNode(node.parent);

    let title = node.frontmatter.title;
    const ast = remark.parse(node.internal.content);
    //if our title is blank, visit will search through the content for a usable and reasonable title
    visit(ast, 'heading', node => {
      // is title blank and is node on first line and a h1 or h2?
      if (title === '' && (node.depth === 1 || node.depth === 2)) {
        // accept headers up to 3rd line of markdown file
        if (node.position.start.line < 3) {
          title = node.children[0].value;
        }
      }
    });

    let labels = {};
    // assert the shape of labels in frontmatter
    if (Object.prototype.hasOwnProperty.call(node.frontmatter, 'labels')) {
      if (isPlainObject(node.frontmatter.labels)) {
        labels = node.frontmatter.labels;
github cutting-room-floor / documentation-theme-default / test / index.js View on Github external
test('main', function (t) {
  var comments = [
    {
      path: [],
      context: {},
      description: remark.parse('test'),
      members: {
        static: [],
        instance: []
      },
      returns: [{
        type: {
          type: 'NameExpression',
          name: 'Foo'
        }
      }]
    }
  ];

  theme(comments, {}, function (err) {
    t.ifError(err);
    t.done();
github cutting-room-floor / documentation-theme-default / test / format_markdown.js View on Github external
test('main', function (t) {
  t.deepEqual(formatMarkdown(remark.parse('Converts from `Result` to `?Error`')),
    '<p>Converts from <code>Result&lt;T&gt;</code> to <code>?Error</code></p>\n');
  t.done();
});
github mdx-js / mdx / to-mdxast / get-imports.js View on Github external
module.exports = mdx => {
  const imports = select(parse(mdx), IMPORT_SELECTOR)
    .map(i => {
      const squeezed = i.value.replace(/\s+/g, ' ').split(' import').join('\nimport')
      const parsed = parseImports(squeezed)

      return {
        raw: i.value,
        parsed
      }
    })

  const scope = importScope(imports)

  return {
    imports,
    scope,
    blocks: blocks.concat(scope)
github transloadit / uppy / website / build-documentation.js View on Github external
documentationFormatter(comments, {}, function (err, output) {
    if (err) {
      throw new Error(err)
    }

    var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'))
    var newStuff = remark.parse(output)
    inject('Uppy Core & Plugins', inputMarkdownContent, newStuff)

    fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent))
    console.info(chalk.green('✓ documentation generated'))
  })
})
github transloadit / uppy / website / build-documentation.js View on Github external
documentationFormatter(comments, {}, function (err, output) {
    if (err) {
      throw new Error(err)
    }

    var inputMarkdownContent = remark.parse(fs.readFileSync('src/api/docs.md', 'utf-8'))
    var newStuff = remark.parse(output)
    inject('Uppy Core & Plugins', inputMarkdownContent, newStuff)

    fs.writeFileSync('src/api/docs.md', remark.stringify(inputMarkdownContent))
    console.info(chalk.green('✓ documentation generated'))
  })
})
github mdx-js / mdx / src / transclude.js View on Github external
return
    }

    const transcludedFile = path.join(file.cwd, node.value)

    let content = null
    try {
      content = fs.readFileSync(transcludedFile, 'utf8')
    } catch (e) {
      console.log(`Error transcluding ${transcludedFile}`)
    }

    if (content) {
      tree.children = [].concat(
        tree.children.slice(0, index),
        parse(content).children,
        tree.children.slice(index + 1)
      )
    }
  })
github kt3k / node-saku / src / domain / task-factory.js View on Github external
createFromMarkdown (text) {
    const ast = remark.parse(text)
    const tasks = []

    ast.children.forEach(node => {
      if (node.type === HEADING) {
        tasks.unshift([node])
      } else if (tasks.length > 0) {
        tasks[0].push(node)
      }
    })

    return new TaskCollection(
      tasks.reverse().map(obj => this.createOneFromNodes(obj))
    )
  }

remark

markdown processor powered by plugins part of the unified collective

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis