How to use the markdown-it.use function in markdown-it

To help you get started, we’ve selected a few markdown-it 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 Mermade / shins / index.js View on Github external
'use strict';

const fs = require('fs');
const path = require('path');

const maybe = require('call-me-maybe');

var hljs = require('highlightjs/highlight.pack.js');
var hlpath = require.resolve('highlightjs/highlight.pack.js').replace('highlight.pack.js', '');

const emoji = require('markdown-it-emoji');
const attrs = require('markdown-it-attrs');
var md = require('markdown-it')({
    linkify: true, html: true,
    highlight: function (str, lang) {
        var slang = lang.split('--')[0]; // allows multiple language tabs for the same language
        if (slang && hljs.getLanguage(slang)) {
            try {
                return '<pre class="highlight tab tab-' + lang + '"><code>' +
                    hljs.highlight(slang, str, true).value +
                    '</code></pre>';
            } catch (__) { }
        }

        return '<pre class="highlight"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
    }
}).use(require('markdown-it-lazy-headers'));
md.use(emoji);
const yaml = require('yaml');
github Lucas-C / dotfiles_and_notes / bin / md2html.js View on Github external
function md2html(input) {
  var md = require('markdown-it')({html: true, linkify: true, typographer: true})
    .use(require('markdown-it-anchor'), { slugify: slugify } )
    .use(require('markdown-it-checkbox'))
    .use(require('markdown-it-header-sections'))
    .use(require('markdown-it-include'))
    .use(require('markdown-it-multimd-table'), {enableMultilineRows: true})
    .use(require('markdown-it-smartarrows'))
    .use(require('markdown-it-table-of-contents'))
    .use(require('markdown-it-container'), 'classname', {
      validate: name =&gt; name.trim().length, // allow everything not empty
      render: (tokens, idx) =&gt; {
        if (tokens[idx].nesting === 1) {
          return `<div class="${tokens[idx].info.trim()}">\n`;
        }
        return '</div>\n';
      }
    });
github NervJS / taro-ui / build / addImportLoader.js View on Github external
_options.markdownItReact ? _options.markdownItReact() : {}
  )

  const {
    body,
    attributes: { imports: importMap }
  } = frontMatter(source)

  const imports = `import * as Nerv from 'nervjs';  import copy from 'copy-to-clipboard';${importMap}`

  const moduleJS = []
  const state = ''
  // 放在这里应该没有问题, 反正是顺序执行的
  let flag = ''

  md.use(mdContainer, 'demo', {
    validate: params => params.trim().match(/^demo\s*(.*)$/),
    render: (tokens, idx) => {
      // container 从开头到结尾把之间的token跑一遍,其中idx定位到具体的位置

      // 获取描述
      const m = tokens[idx].info.trim().match(/^demo\s*(.*)$/)

      // 有此标记代表 ::: 开始
      if (tokens[idx].nesting === 1) {
        flag = idx

        let codeText = ''
        // let state = null
        // let method = ''
        let i = 1
github camelaissani / markdown-it-include / test / default.js View on Github external
it ('default.txt', function () {
      var md = require('markdown-it')()
        .use(require('../'), fixturesPath);
      generate(path.join(__dirname, 'fixtures/default.txt'), md);
    });
github gmaclennan / yo-static / scripts / watch.js View on Github external
var index = {}

  var mdWatcher = chokidar.watch('**/*.{md,mdown,markdown}', {
    cwd: config.content_dir
  })

  var staticWatcher = chokidar.watch('{*,**/*}', {
    cwd: cwd,
    ignored: ['.*', '_*', '_*/**'].concat(config.blacklist, gitignore)
  })

  staticWatcher.on('change', copyFile)
  staticWatcher.on('add', copyFile)
  staticWatcher.on('unlink', unlinkFile)

  config.renderer = require('markdown-it')(config.markdown_opts)
    .use(require('markdown-it-footnote'))

  mdWatcher.on('change', processChangedFile)
  mdWatcher.on('add', processNewFile)
  mdWatcher.on('unlink', processDeletedFile)

  function processChangedFile (filepath) {
    debug('File modified:', filepath)
    convertFile(filepath, config, function (err, fileMetadata) {
      if (err) return console.error(err)
      debug('Updated content file:', fileMetadata.filename)
      var dirty = false
      index[filepath] = fileMetadata
      metadata = metadata.map(function (m) {
        if (m.filename === fileMetadata.filename && !deepEqual(m, fileMetadata)) {
          dirty = true
github ournameismud / mud-fractal / gulp / tasks / fractal / engine.js View on Github external
const faker = require('faker')
const R = require('ramda')
const mdAbbr = require('markdown-it-abbr')
const mdFootnote = require('markdown-it-footnote')
const md = require('markdown-it')({
	html: true,
	xhtmlOut: true,
	typographer: true
})
	.use(mdAbbr)
	.use(mdFootnote)

const fs = require('fs')
const path = require('path')

const slugify = R.compose(
	R.replace(/[\s]+(.)?/g, (match, ch) => (ch ? `-${R.toLower(ch)}` : '')),
	R.toLower,
	R.trim,
	R.replace(/\s+/g, ' '),
	R.replace(/[^a-zA-Z\d\s:]/g, '')
github xcatliu / pagic / src / plugin / parseMarkdown.js View on Github external
const md = require('markdown-it')({
  html: true,
})
.use(require('markdown-it-anchor'))
.use(require('markdown-it-title'));

module.exports = function parseMarkdown(context) {
  /**
   * Use markdown-it-title to get the title of the page
   * https://github.com/valeriangalliat/markdown-it-title
   */
  const env = {};
  const htmlContent = md.render(context.content, env);

  return Object.assign({}, context, {
    title: env.title,
    content: htmlContent,
github TheFive / osmbc / util.js View on Github external
"use strict";

var debug = require("debug")("OSMBC:util");
var should = require('should');

var markdown = require("markdown-it")()
  .use(require("markdown-it-sup"))
  .use(require("markdown-it-imsize"), { autofill: true });

function isTrue(expr) {
  return (expr === true || expr === "true");
}

function shorten(string, maxlength) {
  debug("maxString");
  if (typeof (string) === "number") return string;
  if (typeof (maxlength) === "undefined") maxlength = 30;
  if (typeof (string) === "undefined") return "";
  if (typeof (string) === "number") return string;
  if (!string) return "";
  var newstring = string;
  if (typeof (string) === "object") newstring = JSON.stringify(string);
github nebulade / meemo / frontend / js / filter.js View on Github external
'use strict';

var Vue = require('vue'),
    twemoji = require('twemoji');

var md = require('markdown-it')({
    breaks: true,
    html: true,
    linkify: true
}).use(require('markdown-it-emoji'))
.use(require('markdown-it-highlightjs'))
.use(require('markdown-it-checkbox'));

md.renderer.rules.emoji = function(token, idx) {
  return twemoji.parse(token[idx].content);
};

Vue.filter('markdown', function (value) {
    if (!value) return '';

    return md.render(value);
});
github mudassir0909 / jsonresume-theme-elegant / index.js View on Github external
const fs = require('fs');

const _ = require('underscore');
const utils = require('jsonresume-themeutils');
const moment = require('moment');
const markdown = require('markdown-it')({
    breaks: true
}).use(require('markdown-it-abbr'));

const { renderResume } = require('./tpl/index');

require('./moment-precise-range.js');

utils.setConfig({ date_format: 'MMM, YYYY' });

function render(resume) {
    const addressAttrs = ['address', 'city', 'region', 'countryCode', 'postalCode'];
    const addressValues = addressAttrs.map(key => resume.basics.location[key]);
    const css = fs.readFileSync(__dirname + '/assets/css/theme.css', 'utf-8');

    resume.basics.picture = utils.getUrlForPicture(resume);
    resume.basics.summary = convertMarkdown(resume.basics.summary);