How to use the commonmark.Parser function in commonmark

To help you get started, we’ve selected a few commonmark 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 accordproject / markdown-editor / src / MarkdownToSlateConverter.js View on Github external
convert(markdownText) {
    this.root = null;
    this.nodeStack = [];

    const reader = new commonmark.Parser();
    const parsed = reader.parse(markdownText);

    const walker = parsed.walker();
    let event;
    event = walker.next();

    while (event) {
      const type = event.node.type;
      // console.log(`Converting: ${type}`);

      if (this[type]) {
        // console.log(event.node);

        this[type](event.node, event.entering);
        this.dump();
      } else {
github witheve / Eve / src / editor.ts View on Github external
import {Parser} from "commonmark";
import * as CodeMirror from "codemirror";
import {sendSwap, sendSave, sendParse} from "./client";
import {setActiveIds, renderer, renderEve} from "./renderer";
let codeEditor: MarkdownEditor;
let lineMarks = {"item": true, "heading": true, "heading1": true, "heading2": true, "heading3": true, "heading4": true};
let parser = new Parser();


type Pos = CodeMirror.Position;
type Range = CodeMirror.Range;

type Elem = Element&any;

function isRange(loc:any): loc is Range {
  return loc.from !== undefined || loc.to !== undefined;
}
function isPosition(loc:any): loc is Position {
  return loc.line !== undefined || loc.ch !== undefined;
}

//---------------------------------------------------------
// Spans (TextMarkers)
github markedjs / marked / test / index.js View on Github external
bench('commonmark', files, (function() {
      var commonmark = require('commonmark'),
          parser = new commonmark.Parser(),
          writer = new commonmark.HtmlRenderer();
      return function(text) {
        return writer.render(parser.parse(text));
      };
    })());
  } catch (e) {
github jostylr / literate-programming-lib / index.js View on Github external
});

    var text = doc.text;
    var bits = text.split("\n"); 
            if (ind !== -1) {
                return el.slice(0, ind).trim() + el.slice(ind+3);
            } else {
                return el;
            }
        }).join("\n");
    } 

    var reader = new commonmark.Parser();
    var parsed = reader.parse(text); 

    var walker = parsed.walker();
    var event, node, entering, htext = false, ltext = false, lang, code;
    var ind, pipes, middle, title, href, directive; //for links

    while ((event = walker.next())) {
        node = event.node;
        entering = event.entering;

        switch (node.type) {
        case "text" : 
            if (htext) {
                htext.push(node.literal);
            }
            if (ltext) {
github mtconnect / mtconnect-agent / tools / generate-standard.js View on Github external
var commonmark = require("commonmark");

var infile = "../doc/standard/upnp.md";
var outfile = "../build/upnp.md";

var fs = require('fs');
var md = fs.readFileSync(infile, {encoding:"utf8"});

var reader = new commonmark.Parser();
var parsed = reader.parse(md);

var out = md.split("\n");

var walker = parsed.walker();
var event, node, source, i;

while ((event = walker.next())) {
    node = event.node;
    if (node.type === "code_block") {
        source = node.sourcepos;
        for (i = source[0][0]-1; i < source[1][0]; i +=1) {
            out[i] = false;
        }
    }
}
github Twipped / QueryizeJS / docs / index.js View on Github external
'use strict';

var fs = require('fs');
var dox = require('dox');
var Handlebars = require('handlebars');
var commonmark = require('commonmark');
var path = require('path');

var template = Handlebars.compile(fs.readFileSync(path.join(__dirname, '/template.hbs.html')).toString('utf8'));

/** Build Changelog
*******************************************************************************************/
var changelog = fs.readFileSync(path.join(__dirname, '/../CHANGELOG.md')).toString('utf8');
changelog = (new commonmark.Parser()).parse(changelog);
var walker = changelog.walker();
var event;
var node;
while ((event = walker.next())) {
	node = event.node;
	if (node.t === 'SetextHeader' && node.level === 1) {
		node.level = 3;
	}
}
changelog = (new commonmark.HtmlRenderer()).render(changelog);

/** Build Docs
*******************************************************************************************/

var parsed = dox.parseComments(
	fs.readFileSync(
github learnapollo / learnapollo / src / utils / content.ts View on Github external
this.isTrack = isTrack
    this.description = description
    this.subchapters = subchaptersData.map((d) => new Subchapter(d.title, d.alias, this))
  }
}

interface SubchapterData {
  title: string
  alias: string
}

interface SubchapterDataWithMeta extends SubchapterData {
  isLast: boolean
}

const parser = new Parser()

class Subchapter {
  title: string
  alias: string
  chapter: Chapter

  constructor(title: string, alias: string, chapter: Chapter) {
    this.title = title
    this.alias = alias
    this.chapter = chapter
  }

  ast(): Node {
    return parser.parse(require(`../../content/${this.chapter.alias}/${this.alias}.md`))
  }
}
github 6502ts / 6502.ts / src / web / stella / stellerator / components / general / Markdown.tsx View on Github external
.then(source => {
                const parser = new commonmark.Parser(),
                    renderer = new commonmark.HtmlRenderer();

                this.setState({
                    content: renderer.render(this._postprocessParsedMarkdown(parser.parse(source)))
                });
            })
            .then(undefined, (e: Error) => this.props.onMarkdownError(e));
github cleverbeagle / pup / modules / parse-markdown.js View on Github external
export default (markdown, options) => {
  const reader = new Parser();
  const writer = options ? new HtmlRenderer(options) : new HtmlRenderer();
  const parsed = reader.parse(markdown);
  return writer.render(parsed);
};
github sinnerschrader / schlump / src / markdown.js View on Github external
const CommonMark = require('commonmark');
const ReactRenderer = require('commonmark-react-renderer');
const React = require('react');
const {stripIndent} = require('common-tags');

const parser = new CommonMark.Parser();
const renderer = new ReactRenderer();

module.exports = {
	renderMarkdown,
	wrapMarkdown,
	Markdown
};

function renderMarkdown(text) {
	return renderer.render(parser.parse(stripIndent`${text}`));
}

function Markdown(props) {
	return React.createElement('div', undefined, renderMarkdown(props.children));
}

commonmark

a strongly specified, highly compatible variant of Markdown

BSD-2-Clause
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis