marked-extras
Extras for marked.js. Utils, language definitions, templates for custom headings and sensible defaults.
Last updated 12 years ago by jonschlinkert .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install marked-extras 
SYNC missed versions from official npm registry.

marked-extras NPM version

Extras, utils, language definitions and defaults for marked.js

If you find a bug or have a feature request, please create an issue.

Installation

Use npm to install the package

npm i marked-extras --save

Usage

var marked = require('marked');
var extras = require('marked-extras');

// Example node module
module.exports = function (str, options) {
  options = options || {};

  // Initialize marked extras
  extras.init(options);

  // Set marked.js options
  marked.setOptions(extras.markedDefaults);

  // do stuff...
  // ...

  // Convert markdown to HTML
  return marked(str);
};

Highlighting

Also be sure to add the highlight.js scripts to your HTML:

<script src="js/highlight.js"></script>
<!-- or, a customized version -->
<script src="js/highlight.pack.js"></script>

<script>hljs.initHighlightingOnLoad();</script>

Options

The following example shows the actual defaults used in this lib, and how they can be customized:

var opts = {
  renderer: renderer,
  gfm: true,
  tables: true,
  breaks: false,
  pedantic: false,
  sanitize: false,
  smartLists: true,
  smartypants: false,

  // highlight.js options
  prefix: 'lang-',
  tabReplace: ' ',
  highlight: function (code, lang) {
    console.log(languages[lang]);
    try {
      if (languages[lang]) {
        lang = languages[lang];
      } else {
        return code;
      }
      return hljs.highlight(lang, code).value;
    } catch(e) {
      return hljs.highlightAuto(code).value;
    }
  }
};

var markedOpts = _.extend(extras.markedDefaults, opts);

// Define marked.js options
marked.setOptions(markedOpts);

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.

Authors

Jon Schlinkert

Brian Woodward

License

Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors. Released under the MIT license

Current Tags

  • 0.2.4                                ...           latest (12 years ago)

9 Versions

  • 0.2.4                                ...           12 years ago
  • 0.2.3                                ...           12 years ago
  • 0.2.2                                ...           12 years ago
  • 0.2.0                                ...           12 years ago
  • 0.1.4                                ...           12 years ago
  • 0.1.3                                ...           12 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |