How to use the markdown-it 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 JoelOtter / kajero / js / parseMarkdown.js View on Github external
import MarkdownIt from 'markdown-it';
import fm from 'front-matter';
import Immutable from 'immutable';

import { codeToText } from './util';

let markedownIt = new MarkdownIt();

export default function parse(md) {
    const content = fm(md);
    const parsedMarkdown = markedownIt.parseInline(content.body);
    const blockParsedMarkdown = markedownIt.parse(content.body);

    // Extract code blocks first
    let codeBlocks = [];
    for (let block of blockParsedMarkdown) {
        if (block.type === 'fence') {
            const info = block.info.split(';').map(s => s.trim());
            const language = info[0];
            const attrs = info.splice(1);
            codeBlocks.push(Immutable.fromJS({
                type: 'code',
                content: block.content.trim(),
github NevenLeung / write-down / src / utils / external / markdown-parser.js View on Github external
import taskList from "markdown-it-task-lists";
import TOC from "markdown-it-table-of-contents";

import twemoji from 'twemoji';

const markdownOption = {
  html:         false,        // Enable HTML tags in source
  xhtmlOut:     false,        // Use '/' to close single tags (<br>)
  breaks:       false,        // Convert '\n' in paragraphs into <br>
  langPrefix:   'language-',  // CSS language prefix for fenced blocks
  linkify:      false,         // autoconvert URL-like texts to links
  typographer:  true,         // Enable smartypants and other sweet transforms
  quotes: '“”‘’',
};

const md = new MarkdownIt(markdownOption);

const anchorOption = {
  level: [1, 2, 3]
};

const imsizeOption = {
  autofill: true
};

const TOC_Option = {
  includeLevel: [1, 2, 3]
};


md.use(abbr)
  .use(anchor, anchorOption)
github gsuitedevs / md2googleslides / src / parser / parser.ts View on Github external
import customFence from 'markdown-it-fence';
function generatedImage(md): void {
    return customFence(md, 'generated_image', {
        marker: '$',
        validate: () => true,
    });
}

const mdOptions = {
    html: true,
    langPrefix: 'highlight ',
    linkify: false,
    breaks: false,
};

const parser = markdownIt(mdOptions)
    .use(attrs)
    .use(lazyHeaders)
    .use(emoji, { shortcuts: {} })
    .use(expandTabs, { tabWidth: 4 })
    .use(generatedImage)
    .use(video, { youtube: { width: 640, height: 390 } });

function parseMarkdown(markdown: string): Token[] {
    return parser.parse(markdown, {});
}

export default parseMarkdown;
github krasimir / igit / src / components / utils / marked.js View on Github external
import MarkdownIt from 'markdown-it';
import mentions from 'markdown-it-mentions';

import emojis from '../../emoji.json';

const shaRe = new RegExp(/ \b[0-9a-f]{5,40}\b/, 'gm');
const prOrIssueNumber = new RegExp(/#[0-9]+\b/gm);
const emojiRe = new RegExp(':[a-zA-Z]+:', 'gm');

const md = new MarkdownIt({
  linkify: true
});

function parseURL(username) {
  return `https://github.com/${ username }`;
}

export default function (str, repo, pr) {
  str = str
    .replace(emojiRe, function (str) {
      const s = str.substr(1, str.length - 2);

      if (emojis[s]) return emojis[s];
      return str;
    })
    .replace(shaRe, function (str) {
github bs32g1038 / node-blog / react-blog-admin / src / components / MdEdit / index.jsx View on Github external
constructor(props) {
        super(props);
        this.markdown = new MarkdownIt();
        this.state = {
            MarkdownContent: this.props.value || '',
            isPreview: false
        };
    }
    getCodeMirror() {
github pubpub / pubpub / app / components / RenderFile / ReactMarkdownMD.js View on Github external
function mdReactFactory(options={}) {
  const { onIterate, tags=DEFAULT_TAGS,
    presetName, markdownOptions,
    enableRules=[], disableRules=[], plugins=[],
    onGenerateKey=(tag, index) => `mdrct-${tag}-${index}`,
    className } = options;

  let md = markdown(markdownOptions || presetName)
    .enable(enableRules)
    .disable(disableRules);

  const convertRules = assign({}, DEFAULT_RULES, options.convertRules);

  md = reduce(plugins, (m, plugin) =>
    plugin.plugin ?
    m.use(plugin.plugin, ...plugin.args) :
    m.use(plugin),
    md
  );

  function iterateTree(tree, level=0, index=0) {
    let tag = tree.shift();
    const key = onGenerateKey(tag, index);
github WebbyLab / itsquiz-wall / shared / components / Markdown.jsx View on Github external
componentWillMount() {
        this.md = new MarkdownIt();

        const { preset } = this.props;

        switch (preset) {
            case 'activationDescription': {
                this.md.configure(activationDescriptionPreset).enable('linkify').enable(['link', 'list', 'emphasis']);

                break;
            }

            default: {
                this.md.enable('linkify');
            }
        }

        const customRenderer = (tokens, idx, options, env, self) => self.renderToken(tokens, idx, options);
github bradfrost / gatsby-style-guide-guide / src / components / Section.js View on Github external
const Section = ({ headingLevel, title, description, children }) =&gt; {

    const md = markdownIt({
	  html: true,
	  linkify: true
  });

    return (
        <section>
            <header>
                <h2>
                { description &amp;&amp;
                    <div>
                }
            </div></h2></header>
            <div>{children}</div>
        </section>
    )
};
github fjordllc / bootcamp / app / javascript / packs / markdown-it.js View on Github external
document.addEventListener('DOMContentLoaded', () => {
  const md = new MarkdownIt({
    html: true,
    breaks: true,
    linkify: true,
    langPrefix: 'language-'
  })

  md.use(MarkdownItEmoji).use(MarkdownItMention).use(MarkdownItTaskLists)

  Array.from(document.querySelectorAll('.js-markdown-view'), e => {
    e.style.display = 'block'
    e.innerHTML = md.render(e.textContent)
  })
})
github telescopejs / telescope / src / core / utils / markdown.js View on Github external
return nUrl.resolve(imgFromUrl, link)
      }
      return nUrl.resolve(fromUrl, link)
    },
    highlight,
    markdownItOptions
  })

  const mark = [taskList, emoji, preamble, replaceLink, headings]
    .concat(transformers)
    .reduce((main, plugin) => {
      if (Array.isArray(plugin)) {
        return main.use(plugin[0], plugin[1])
      }
      return main.use(plugin)
    }, new Markdown(opts))

  return mark.render(markdown)
}