How to use the prismjs/components.languages function in prismjs

To help you get started, we’ve selected a few prismjs 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 Soreine / prismjs-components-loader / src / componentDefinitions.js View on Github external
import COMPONENTS from 'prismjs/components';

const LANGUAGES = { ...COMPONENTS.languages };
delete LANGUAGES.meta;

// Mainstream and commonly used components.
// According to some arbitrary beliefs.
const COMMON = [
    'aspnet',
    'bash',
    'c',
    'clike',
    'coffeescript',
    'cpp',
    'csharp',
    'css',
    'd',
    'dart',
    'diff',
github orgapp / orgajs / packages / oast-to-hast / src / handlers / _load-prism-language.ts View on Github external
export default function loadPrismLanguage(language) {
  const baseLanguage = getBaseLanguageName(language)

  if (!baseLanguage) {
    throw new Error(`Prism doesn't support language '${language}'.`)
  }

  if (Prism.languages[baseLanguage]) {
    // Don't load already loaded language
    return
  }

  const languageData = prismComponents.languages[baseLanguage]

  if (languageData.option === `default`) {
    // Default language has already been loaded by Prism
    return
  }

  if (languageData.require) {
    // Load the required language first
    if (Array.isArray(languageData.require)) {
      languageData.require.forEach(loadPrismLanguage)
    } else {
      loadPrismLanguage(languageData.require)
    }
  }

  require(`prismjs/components/prism-${baseLanguage}.js`)
github hexojs / hexo-util / lib / prism.js View on Github external
'use strict';

const Prism = require('prismjs');
const prismLoadLanguages = require('prismjs/components/');

// https://github.com/PrismJS/prism/issues/2145
const prismComponents = require('prismjs/components');
const prismSupportedLanguages = Object.keys(prismComponents.languages);

const escapeHTML = require('./escape_html');

/**
 * Wrapper of Prism.highlight()
 * @param {String} code
 * @param {String} language
 */
function prismHighlight(code, language) {
  // Prism has not load the language pattern
  if (!Prism.languages[language] && prismSupportedLanguages.includes(language)) prismLoadLanguages(language);

  if (Prism.languages[language]) {
    // Prism escapes output by default
    return Prism.highlight(code, Prism.languages[language], language);
  }
github inspursoft / board / src / ui / src / app / shared / cs-components-library / cs-syntax-highlighter / cs-syntax-highlighter.component.ts View on Github external
ngAfterContentInit() {
    this.eltRef.nativeElement.innerHTML = Prism.highlight(this.content, Languages.languages[this.language]);
  }
}
github Soreine / prismjs-components-loader / src / componentDefinitions.js View on Github external
const PEERS = Object.keys(LANGUAGES).reduce((acc, language) => {
    let { peerDependencies } = COMPONENTS.languages[language];
    if (peerDependencies) {
        if (!Array.isArray(peerDependencies)) {
            peerDependencies = [peerDependencies];
        }

        peerDependencies.forEach(peer => {
            if (!acc[peer]) {
                acc[peer] = [];
            }
            acc[peer].push(language);
        });
    }

    return acc;
}, {});
github howtocards / frontend / src / lib / rich-text / extensions / code-plugin / code-block.js View on Github external
import React from "react"
import PrismComponents from "prismjs/components"
import ReactSelect from "react-select"
import styled from "styled-components"
import PropTypes from "prop-types"

const MultiSelect = styled(ReactSelect)`
  color: black;
`

const exclude = {
  meta: true,
  markup: true,
}

const languages = Object.entries(PrismComponents.languages).reduce(
  (acc, [key, value]) => {
    if (exclude[key]) {
      return acc
    }
    return {
      ...acc,
      [key]: {
        label: value.title,
        isLoaded: false,
      },
    }
  },
  {},
)

const optionsForSelect = Object.entries(languages)
github rjz / code2png / src / render.js View on Github external
const fs = require('fs');
const { resolve } = require('path');
const Mustache = require('mustache');
const Prism = require('prismjs');
const PrismLanguages = require('prismjs/components').languages;

const template = `


  
    
    <title>code2png</title>
    {{#styles}}
    <style type="text/css">{{{.}}}</style>
    {{/styles}}

    {{#scripts}}
    
    {{/scripts}}