GithubHelp home page GithubHelp logo

gerhobbelt / markdown-it-prism Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jgleitz/markdown-it-prism

0.0 2.0 0.0 7.39 MB

Highlight code blocks in markdown-it using prism

License: MIT License

JavaScript 94.53% Makefile 1.04% TypeScript 4.43%

markdown-it-prism's Introduction

markdown-it-prism Build Status npm version Bower version

markdown-it plugin to highlight code blocks using Prism

Usage

const md = require('markdown-it')();
const prism = require('markdown-it-prism');

md.use(prism, options);

The plugin will insert the necessary markup into all code blocks. Include one of Prism’s stylesheets in your HTML to get highlighted code.

Options

The options object may contain:

Name Description Default
plugins Array of Prism Plugins to load. The names to use can be found here. Please note that some prism plugins (notably line-numbers) rely on the DOM being present and can thus not be used with this package (see #1). []
init A function called after setting up prism. Will receive the prism instance as only argument. Useful for plugins needing further intialisation. () => {}
defaultLanguageForUnknown The language to use for code blocks that specify a language that Prism does not know. No default will be used if this option is undefined. undefined
defaultLanguageForUnspecified The language to use for code block that do not specify a language. No default will be used if this option is undefined. undefined
defaultLanguage Shorthand to set both defaultLanguageForUnknown and defaultLanguageForUnspecified to the same value. undefined

Usage with Webpack

If you want to use this plugin together with Webpack, you need to import all languages you intend to use:

import MarkdownIt from 'markdown-it';
import prism from 'markdown-it-prism';

import "prismjs/components/prism-clike"
import "prismjs/components/prism-java"

function component() {
  const md = new MarkdownIt();
  md.use(prism);
  const element = document.createElement('div');
  element.innerHTML = md.render(`
Here is some *code*:
\`\`\`java
public class Test {
  public void foo() {}
}
\`\`\`
`);

  return element;
}

document.body.appendChild(component());

Beware: Prisms languages have dependencies onto each other. You need to import the languages together with their dependencies in the correct order.

markdown-it-prism's People

Contributors

catnose99 avatar dependabot[bot] avatar gerhobbelt avatar iktakahiro avatar jgleitz avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar straicat avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.