How to use the marked.Renderer function in marked

To help you get started, we’ve selected a few marked 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 apache / incubator-echarts-doc / tool / md2json.js View on Github external
function mdToJsonSchema(mdStr, maxDepth, imagePath) {

    var renderer = new marked.Renderer();
    renderer.link = function (href, title, text) {
        if (href.match(/^~/)) { // Property link
            return '<a href="#' + href.slice(1) + '">' + text + '</a>';
        }
        else {
            // All other links are opened in new page
            return '<a href="' + href + '">' + text + '</a>';
        }
    };

    renderer.image = function (href, title, text) {
        var size = (text || '').split('x');
        if (isNaN(size[0])) {
            size[0] = 'auto';
        }
        if (isNaN(size[1])) {
github DanWebb / jdown / example / index.js View on Github external
const jdown = require('../dist');
const marked = require('marked');

// See https://marked.js.org/#/USING_PRO.md#renderer
const renderer = new marked.Renderer();
renderer.heading = (text, level) =&gt;
  `${text}`;

jdown('example/content', {
  fileInfo: true,
  markdown: {renderer},
  assets: {output: 'example/public', path: '/'}
}).then(content =&gt; console.log(content));
github SmartApplicationUnipi / Smart_ELF / tools / kb-docs / src / routes.js View on Github external
const express = require('express');
const marked = require('marked');
const hljs = require('highlight.js');
const router = express.Router();

// Monkey patch the default markdown renderer to allow code highlighting
const renderer = new marked.Renderer();
renderer.code = (code, language) =&gt;
    `<pre><code class="hljs ${language}">${hljs.highlightAuto(code, language ? [language] : null).value}</code></pre>`;


// GET home page
router.get('/', async (req, res, next) =&gt; {
    try {
        const data = await req.kb.getAllTags({ includeShortDesc: true });
        res.render('index', { data });
    } catch (e) {
        next(e);
    }
});

// Get tag details
router.get('/:source/:tag', async (req, res, next) =&gt; {
github tscanlin / tocbot / script / parse.js View on Github external
var options = {
  src: '**/*.md',
  dest: 'build/data',
  includeFilename: true,
  compileMarkdown: true,
  bodyProperty: 'body',

  exportName: 'content.json',
  singleFile: false,
  writeFiles: false,
  writeStdout: true
};

marked.setOptions({
  renderer: new marked.Renderer(),
  gfm: true,
  tables: true,
  breaks: true,
  pedantic: false,
  // sanitize: true,
  smartLists: true,
  // smartypants: false,
  highlight: function(code) {
    return require('highlight.js').highlightAuto(code).value;
  }
});


function parseFile(input) {
  var output = {};
  var hasFrontmatter = input.data.slice(0, 3) === MD_SEPERATOR;
github docsifyjs / docsify / src / core / render / compiler.js View on Github external
_initRenderer() {
    const renderer = new marked.Renderer()
    const {linkTarget, linkRel, router, contentBase} = this
    const _self = this
    const origin = {}

    /**
     * Render anchor tag
     * @link https://github.com/markedjs/marked#overriding-renderer-methods
     */
    origin.heading = renderer.heading = function (text, level) {
      let {str, config} = getAndRemoveConfig(text)
      const nextToc = {level, title: str}

      if (/{docsify-ignore}/g.test(str)) {
        str = str.replace('{docsify-ignore}', '')
        nextToc.title = str
        nextToc.ignoreSubHeading = true
github mvlabs / isomorphic-mithril / app / resources.js View on Github external
.then(data => marked(data, {
            renderer: new marked.Renderer(),
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: true,
            smartLists: true,
            smartypants: false
        }))
        .catch(manageErrors),
github amazeui / amazeui-react / webpack.docs.js View on Github external
const isProduction = process.env.NODE_ENV === 'production';
const codeRenderer = function(code, lang) {
  lang = lang === 'js' ? 'javascript' : lang;
  if (lang === 'html') {
    lang = 'xml';
  }

  let hlCode = lang ?
    hl.highlight(lang, code).value : hl.highlightAuto(code).value;

  return `<div class="doc-highlight"><pre><code class="${lang || ''}">${hlCode}</code></pre></div>`;
};

let renderer = new marked.Renderer();
renderer.code = codeRenderer;

const entry = './docs/app.js';
const devEntry = [
  'webpack/hot/dev-server',
  'webpack-hot-middleware/client?reload=true',
  entry,
];
const basePlugins = [
  new webpack.DefinePlugin({
    'process.env': {
      'NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
    }
  }),
  new HTMLWebpackPlugin({
    title: 'Amaze UI React',
github iuap-design / bee.tinper.org / server / router.js View on Github external
/**
 * Created by chief on 16/11/28.
 */

var router = require("koa-router")();
var fs = require("fs");
var path = require("path");
var cate = require("../static/json/catalog-0.1.json");
var markdown = require("markdown").markdown;
var marked = require("marked");
var axios = require('axios')
var renderer = new marked.Renderer();
var components = require('../static/components/components.json');
var qs = require('querystring');

renderer.link = function (href,title,text) {
  var target = '';
  if(href){
    target="_blank";
  }else{
    href = 'javacript:void(0);'
  }
  return `<a href="${href}">${text}</a>`;
};

marked.setOptions({
  renderer: renderer,
  gfm: true,
github livingstyleguide / livingstyleguide / js / core / document.js View on Github external
renderContent () {
    const renderer = new marked.Renderer()

    renderer.heading = (text, level, raw) =&gt; {
      const id = raw.toLowerCase().replace(/[^\w]+/g, '-')
      return (
        `` +
        text +
        `\n`
      )
    }
    renderer.paragraph = (text) =&gt; {
      return `<p class="${this.config.classNames.p}">${text}</p>\n`
    }
    renderer.listitem = (text) =&gt; {
      return `<li class="${this.config.classNames.li}">${text}</li>\n`
    }
    renderer.code = (source, infoString) =&gt; {
github janrain / raml-fleece / src / to-html.js View on Github external
handlebars.registerHelper('markdown', function(md) {
  var renderer = new marked.Renderer();
  renderer.table = function(header, body) {
    return ''
    + `${header}`
    + `${body}`
    + '<table class="table"><thead></thead><tbody></tbody></table>'
  };
  renderer.code = codeBlock
  return md ? new handlebars.SafeString(marked(md, { renderer: renderer })) : '';
});
handlebars.registerHelper('upperCase', _.method('toUpperCase'));