How to use the commonmark.DocParser 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 deanlandolt / markdown-string / index.js View on Github external
// stupid simple markdown template strings
// dervied from https://github.com/brianleroux/micromark

var commonmark = require('commonmark');
var deindent = require('deindent');

var reader = new commonmark.DocParser();
var writer = new commonmark.HtmlRenderer();
var LINE_BREAK = /\n/;
var P_TAG_WRAP = /^<p>(.*)&lt;\/p&gt;\r?\n?$/i;

function markdownTag(strings) {
  var input = strings[0];
  for (var i = 1, length = arguments.length; i &lt; length; ++i) {
    input += arguments[i] + strings[i];
  }
  var parsed = writer.render(reader.parse(input));

  // if string is all on one line (contains no line breaks) strip </p><p> wrapper
  if (!LINE_BREAK.test(input)) {
    var wrapped = parsed.match(P_TAG_WRAP);
    if (wrapped) {
      parsed = wrapped[1];</p>
github textlint / textlint / lib / parse / markdown / markdown-parser.js View on Github external
/*eslint-disable */

// LICENSE : MIT
// Base:
// Copyright (c) 2014, John MacFarlane
// https://github.com/jgm/CommonMark/blob/master/js/lib/html-renderer.js

"use strict";
var traverse = require('traverse');
var positionNode = require("./markdown-position-node");
var StructuredSource = require('structured-source');
var Syntax = require("./markdown-syntax");
var commonmark = require("commonmark");
var normalize = require("./markdown-normalizer");
var objectAssign = require("object-assign");
var reader = new commonmark.DocParser();

// Helper function to produce content in a pair of HTML tags.
var toPlainText = function (tag, attribs, contents, selfclosing) {
    return contents;
};

// Render an inline element as HTML.
var renderInline = function (inline, parent) {
    var attrs;
    switch (inline.t) {
        case 'Str':
            return this.escape(inline.c);
        case 'Softbreak':
            return this.softbreak;
        case 'Hardbreak':
            return toPlainText('br', [], "", true) + '\n';

commonmark

a strongly specified, highly compatible variant of Markdown

BSD-2-Clause
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis