Socket
Socket
Sign inDemoInstall

embed-plugin-highlight

Package Overview
Dependencies
5
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    embed-plugin-highlight

An embed-js plugin to syntax highlight code.


Version published
Weekly downloads
192
increased by15.66%
Maintainers
1
Install size
193 kB
Created
Weekly downloads
 

Readme

Source

embed-plugin-highlight

A plugin that can be used to syntax highlight code.

Installation

npm i -S embed-js embed-plugin-highlight

CDN

https://unpkg.com/embed-plugin-highlight

Usage

Edit embed.js - highlight

You need Prism.js to use this plugins. So import the necessary libraries to support it.

<!-- import the theme of your choice -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/themes/prism-dark.css" />

<!-- import the umd build of prism.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.6.0/prism.min.js">  

Note : On the server, the plugin automatically imports prism.js from node_modules. But it doesn't bundle the PrismJS library with the umd build to keep the size to minimal. Technically prismjs = isServer ? require('prismjs') : window.Prism.

import EmbedJS from 'embed-js'
import highlight from 'embed-plugin-highlight'
import prismjs from 'prismjs'

const x = new EmbedJS({
  input: document.getElementById('element'),
  plugins: [
  basicAudio({
    regex: /audiRegex/gi, // in case you want to define a custom regex
    prismjs: prismjs, // By default it takes window.Prism on client side and global.Prism on server side.
    template(args) {
      // optional template
    },
    onLoad(element) {} // in case you want to do something when the component has loaded on the client.
   })
 ]
})

This will convert

\`\`\`js
 const x = "hello world"
\`\`\`

into

<pre class="language-js">
  <code class="language-js">
    const x = "hello world"
  </code>
</pre>

Example on CodePen

License

MIT @ Ritesh Kumar

FAQs

Last updated on 17 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc