How to use remark - 10 common examples

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 phenomic / phenomic / src / loader-plugin-markdown-init-head.description-property-from-content / index.js View on Github external
function description(text, opts = {}) {
  opts = { ...defaultOpts, ...opts }

  if (opts.pruneLength === 0) {
    console.warn(
      "You defined 'description.pruneLength' of phenomic loader " +
      "with an zero value. This does not make sense, " +
      `so the default value ${ defaultOpts.pruneLength } has been used.`
    )

    opts.pruneLength = defaultOpts.pruneLength
  }

  return prune(
    remark()
      .use(stripMd)
      .process(text)
      .toString()
      .replace(/\n+/g, " ") // Avoid useless new lines
      .trim()
    ,
    opts.pruneLength,
    opts.pruneString
  )
}
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 rhiokim / flybook / libs / md-loader.js View on Github external
// @flow
import fs from 'fs'
import remark from 'remark'
import html from 'remark-html'
import hljs from 'remark-highlight.js'
import slug from 'remark-slug'
import headding from 'remark-autolink-headings'

const app = remark()
app.use([slug, headding, html])

export default (file: string): string => {
  let markdown: string = fs.readFileSync(file).toString('utf8')
  const { contents } = app.processSync(markdown)

  return contents
}
github runtools / run / website / src / components / markdown.js View on Github external
render() {
    return remark()
      .use(remarkReactRenderer, {
        sanitize: sanitization,
        remarkReactComponents: {
          a: ({href, children}) => {
            if (href.match(/^https?:\/\//i) || href.startsWith('mailto:')) {
              // External Link
              return <a href="{href}">{children}</a>;
            }
            return {children};
          },
          code: ({className, children}) =&gt; {
            let language;
            if (className &amp;&amp; className.startsWith('language-')) {
              language = className.slice('language-'.length);
            }
            return <code>{children[0]}</code>;
github thangngoc89 / blog / old / web_modules / utils / statinamic-agolia-plugin.js View on Github external
const sendToAgolia = (opts) => {
  const when = opts.when
  if (typeof when === "function" && !when()) {
    return
  }
  const mdProcess = remark.use(strip)
  // Flatten head
  let data = cache.map((item) => {
    return {
      ...item,
      ...item.head,
      head: undefined,
    }
  })

  if (opts.collectionOptions) {
    data = enhanceCollection(data, opts.collectionOptions)
  }

  data = data.map((item) => {
    item.objectID = item.__filename
    item.body = mdProcess.process(item.rawBody)
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 graalvm / graaljs / tools / node-lint-md-cli-rollup / src / cli-entry.js View on Github external
'use strict';

const engine = require('unified-engine');
const options = require('unified-args/lib/options');
const extensions = require('markdown-extensions');
const processor = require('remark');
const proc = require('remark/package.json');
const cli = require('../package.json');
const { plugins } = require('remark-preset-lint-node');

const args = {
  processor: processor,
  name: proc.name,
  description: cli.description,
  version: [
    proc.name + ': ' + proc.version,
    cli.name + ': ' + cli.version,
  ].join(', '),
  ignoreName: '.' + proc.name + 'ignore',
  extensions: extensions
};
const config = options(process.argv.slice(2), args);
config.detectConfig = false;
config.plugins = plugins;

engine(config, (err, code) => {
  if (err) console.error(err);
  process.exit(code);
});

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