How to use marked-terminal - 10 common examples

To help you get started, we’ve selected a few marked-terminal 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 umijs / umi / packages / umi-core / src / error.js View on Github external
import chalk from 'chalk';
import signale from 'signale';
import marked from 'marked';
import TerminalRenderer from 'marked-terminal';
import { existsSync, writeFileSync } from 'fs';

marked.setOptions({
  renderer: new TerminalRenderer(),
});

// 支持内部框架扩展 error code map
const ERROR_CODE_MAP = require(process.env.ERROR_CODE_MAP_PATH || '@umijs/error-code-map');

export class UmiError extends Error {
  constructor(opts, ...params) {
    const { message, code, context } = opts;
    super(message, ...params);
    this.code = code;
    this.context = context || {};

    this.test();
  }

  test() {
github SnowdogApps / magento2-frontools / tasks / default.js View on Github external
export default function(callback) {
  // Display formatted readme.md
  marked.setOptions({
    renderer: new markedTerminal()
  })

  log.info(marked(fs.readFileSync('./README.md', 'UTF-8')))

  callback()
}
github crazyguitar / noslide.js / lib / slide.js View on Github external
});
    body = setLineSameWidth(body.trim());

    var quote = "";
    body.split('\n').forEach(line => {
      if (line.trim() === "") {
        quote += '\n';
        return;
      }
      quote += ('> ' + line + '\n');
    });
    return '\n' + this.o.blockquote(indentify(quote)) + '\n\n';
  });
};

TerminalRenderer.prototype.html = function(html) {
  var out = "";
  if (html instanceof Array) {
    html.forEach(block => {
      out += block;
    });
  } else {
    out = html;
  }
  out = out.replace(/<[^>\)\(]+>/g,'');
  return this.o.html(setLineSameWidth(out));
};



/**
 * Read slide content.
github crazyguitar / noslide.js / lib / slide.js View on Github external
var hasText = text && text !== href;

  var out = '';
  if (hasText) out += this.emoji(text) + ' (';
  out +=  this.o.href(href);
  if (hasText) out += ')';

  return this.o.link(out);
};

TerminalRenderer.prototype.hr = function() {
  return '\n\n' + '-'.repeat(this.o.width) + '\n';
};

TerminalRenderer.prototype.blockquote = function(quoteBlocks) {
  return Promise.all(quoteBlocks).then(quotes => {
    var body = "";
    quotes.forEach(quote => {
      body += quote;
    });
    body = setLineSameWidth(body.trim());

    var quote = "";
    body.split('\n').forEach(line => {
      if (line.trim() === "") {
        quote += '\n';
        return;
      }
      quote += ('> ' + line + '\n');
    });
    return '\n' + this.o.blockquote(indentify(quote)) + '\n\n';
github crazyguitar / noslide.js / lib / slide.js View on Github external
if (prot.indexOf('javascript:') === 0) {
      return '';
    }
  }

  var hasText = text && text !== href;

  var out = '';
  if (hasText) out += this.emoji(text) + ' (';
  out +=  this.o.href(href);
  if (hasText) out += ')';

  return this.o.link(out);
};

TerminalRenderer.prototype.hr = function() {
  return '\n\n' + '-'.repeat(this.o.width) + '\n';
};

TerminalRenderer.prototype.blockquote = function(quoteBlocks) {
  return Promise.all(quoteBlocks).then(quotes => {
    var body = "";
    quotes.forEach(quote => {
      body += quote;
    });
    body = setLineSameWidth(body.trim());

    var quote = "";
    body.split('\n').forEach(line => {
      if (line.trim() === "") {
        quote += '\n';
        return;
github crazyguitar / noslide.js / lib / slide.js View on Github external
if (Object.prototype.hasOwnProperty.call(target, key)) {
        obj[key] = target[key];
      }
    }
  }

  return obj;
}


TerminalRenderer.prototype.code = function(code, lang, escaped) {
  code = setLineSameWidth(code);
  return '\n' + indentify(highlight(code, lang, this.o, this.highlightOptions)) + '\n';
};

TerminalRenderer.prototype.list = function(body, ordered) {
  body = setLineSameWidth(body);
  body = indentLines(this.o.listitem(body));
  body = body + '\n';
  if (!ordered) return body;
  return changeToOrdered(body);
};

TerminalRenderer.prototype.image = function(href, title, text) {
  return new Promise((resolve, reject) => {
    imageToAscii(href,
      { size: { height: "60%" }
      }, (err, converted) => {
      if (err) reject(err);
      else resolve(converted + "\n");
    });
  });
github crazyguitar / noslide.js / lib / slide.js View on Github external
return changeToOrdered(body);
};

TerminalRenderer.prototype.image = function(href, title, text) {
  return new Promise((resolve, reject) => {
    imageToAscii(href,
      { size: { height: "60%" }
      }, (err, converted) => {
      if (err) reject(err);
      else resolve(converted + "\n");
    });
  });

};

TerminalRenderer.prototype.heading = function(text, level, raw) {
  text = this.transform(text.join(''));

  var prefix = this.o.showSectionPrefix ?
    (new Array(level + 1)).join('#')+' ' : '';
  text = prefix + text;
  if (this.o.reflowText) {
    text = reflowText(text, this.o.width, this.options.gfm);
  }
  if (level === 1) {
    return this.o.firstHeading(text) + '\n';
  }
  return '\n' + this.o.heading(text) + '\n';
};

TerminalRenderer.prototype.paragraph = function(texts) {
  return Promise.all(texts).then(data => {
github crazyguitar / noslide.js / lib / slide.js View on Github external
TerminalRenderer.prototype.code = function(code, lang, escaped) {
  code = setLineSameWidth(code);
  return '\n' + indentify(highlight(code, lang, this.o, this.highlightOptions)) + '\n';
};

TerminalRenderer.prototype.list = function(body, ordered) {
  body = setLineSameWidth(body);
  body = indentLines(this.o.listitem(body));
  body = body + '\n';
  if (!ordered) return body;
  return changeToOrdered(body);
};

TerminalRenderer.prototype.image = function(href, title, text) {
  return new Promise((resolve, reject) => {
    imageToAscii(href,
      { size: { height: "60%" }
      }, (err, converted) => {
      if (err) reject(err);
      else resolve(converted + "\n");
    });
  });

};

TerminalRenderer.prototype.heading = function(text, level, raw) {
  text = this.transform(text.join(''));

  var prefix = this.o.showSectionPrefix ?
    (new Array(level + 1)).join('#')+' ' : '';
github crazyguitar / noslide.js / lib / slide.js View on Github external
TerminalRenderer.prototype.heading = function(text, level, raw) {
  text = this.transform(text.join(''));

  var prefix = this.o.showSectionPrefix ?
    (new Array(level + 1)).join('#')+' ' : '';
  text = prefix + text;
  if (this.o.reflowText) {
    text = reflowText(text, this.o.width, this.options.gfm);
  }
  if (level === 1) {
    return this.o.firstHeading(text) + '\n';
  }
  return '\n' + this.o.heading(text) + '\n';
};

TerminalRenderer.prototype.paragraph = function(texts) {
  return Promise.all(texts).then(data => {
    var res = '';
    data.forEach(i => {
      res += i;
    });
    return '\n' + res + '\n';
  });
};

TerminalRenderer.prototype.link = function(href, title, text) {
  text = text.join('');
  var prot = "";
  if (this.options.sanitize) {
    try {
      prot = decodeURIComponent(unescape(href))
        .replace(/[^\w:]/g, '')
github crazyguitar / noslide.js / lib / slide.js View on Github external
return this.o.firstHeading(text) + '\n';
  }
  return '\n' + this.o.heading(text) + '\n';
};

TerminalRenderer.prototype.paragraph = function(texts) {
  return Promise.all(texts).then(data => {
    var res = '';
    data.forEach(i => {
      res += i;
    });
    return '\n' + res + '\n';
  });
};

TerminalRenderer.prototype.link = function(href, title, text) {
  text = text.join('');
  var prot = "";
  if (this.options.sanitize) {
    try {
      prot = decodeURIComponent(unescape(href))
        .replace(/[^\w:]/g, '')
        .toLowerCase();
    } catch (e) {
      return '';
    }
    if (prot.indexOf('javascript:') === 0) {
      return '';
    }
  }

  var hasText = text && text !== href;

marked-terminal

A custom render for marked to output to the Terminal

MIT
Latest version published 10 months ago

Package Health Score

85 / 100
Full package analysis

Popular marked-terminal functions