How to use the prismjs.highlight 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 hiro0218 / miikun / src / lib / markdown.js View on Github external
highlight: function(str, lang) {
        const language = !lang || lang === 'html' ? 'markup' : lang;
        try {
          if (!Prism.languages[language]) {
            require(`prismjs/components/prism-${language}.min.js`);
          }
          if (Prism.languages[language]) {
            return Prism.highlight(str, Prism.languages[language]);
          }
        } catch (__) {
          // eslint-disable-next-line
        console.error(__);
        }

        return '';
      },
    });
github unstoppabledomains / browseth / gen / sample / src / components / Metamask.js View on Github external
onChange={e => {
                this.updateAmount(e);
              }}
              placeholder="AMOUNT_IN_ETH"
            />
            <br>
            <button>Send!</button>
            <br>
            {this.state.err === '' ? '' : this.state.err}
          
        
        <div>
          </div>
github hackjutsu / Lepton / app / utilities / jupyterNotebook / index.js View on Github external
const highlighter = (code, lang) => {
  if (typeof lang === 'undefined') lang = 'markup'
  if (!Prism.languages.hasOwnProperty(lang)) {
    try {
      require('prismjs/components/prism-' + lang + '.js')
    } catch (e) {
      Prism.languages[lang] = false
    }
  }
  return Prism.languages[lang] ? Prism.highlight(code, Prism.languages[lang]) : code
}
nb.highlighter = (text, pre, code, lang) => {
github alibaba / ice / packages / ice-plugin-component / lib / compile / component / markdownHelper.js View on Github external
if (options.sliceCode) {
      const JSX_REG = /(````)(?:jsx?)([^\1]*?)(\1)/g;
      const STYLE_REG = /(````)(?:css|style?)([^\1]*?)(\1)/g;

      const jsxMatched = JSX_REG.exec(result.content);
      const styleMatched = STYLE_REG.exec(result.content);

      if (jsxMatched) {
        result.code = jsxMatched[2] || '';
        result.content = result.content.replace(jsxMatched[0], '');
      }

      if (styleMatched) {
        const styleCode = styleMatched[2] || '';
        result.highlightedStyle = prismjs.highlight(styleCode.trim(), prismjs.languages.css);
      }

      result.highlightedCode = prismjs.highlight(result.code.trim(), prismjs.languages.jsx);
      result.compiledCode = bableCompile(result.code, babelConfig);
    }
    result.content = marked(result.content);

    return result;
  };
};
github qgrid / ng / filters / html.js View on Github external
return text => {
		if (text) {
			return Prism.highlight(text, Prism.languages.html);
		}
		return text;
	};
}
github ausi / respimagelint / src / reporter.js View on Github external
header.appendChild(img);

	let headline = document.createElement('h2');
	headline.textContent = 'Image #' + (index + 1);
	header.appendChild(headline);

	report.appendChild(header);

	let errors = buildErrors(image.data, image.images);

	if (errors.length) {

		errors.forEach(error =&gt; report.appendChild(error));

		let markup = document.createElement('pre');
		let html = '<code>' + prism.highlight(
			buildMarkup(image.markup),
			prism.languages.html,
			'html'
		) + '</code>';

		Object.keys(image.images).sort(
			(a, b) =&gt; b.length - a.length
		).forEach(src =&gt; {
			html = html.replace(new RegExp(
				'([&gt;,\\s])('
				+ src.replace(/&amp;/g, '&amp;').replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&amp;')
				+ ')([&lt;,\\s])'
			, 'g'), '$1<a href="' + image.images[src].url + '" class="token regex">$2</a>$3');
		});

		markup.innerHTML = html;
github TonPC64 / vue-spinkit / src / Example.vue View on Github external
showExam (name, color = '') {
      const newcolor = color !== '' ? `color="${color}"` : ''
      const code = ``
      return Prism.highlight(code, Prism.languages.markup, 'markup')
    }
  }
github surma / underdash / generate_site.js View on Github external
.then(([fCode, fLazyCode, fAsyncCode]) => ({
            name,
            fCode: prism.highlight(fCode, prism.languages.javascript),
            fLazyCode: fLazyCode && prism.highlight(fLazyCode, prism.languages.javascript),
            fAsyncCode: fAsyncCode && prism.highlight(fAsyncCode, prism.languages.javascript),
          }));
      })
github transloadit / uppy / website / scripts / highlight.js View on Github external
function highlight (lang, code) {
  const startTag = `<figure class="highlight ${lang}"><table><tbody><tr><td class="code"><pre>`
  const endTag = '</pre></td></tr></tbody></table></figure>'
  let parsedCode = ''
  if (Prism.languages[lang]) {
    parsedCode = Prism.highlight(code, Prism.languages[lang])
  } else {
    parsedCode = code
  }

  return startTag + parsedCode + endTag
}
github QiShaoXuan / animate_resume_ts / src / scripts / animateResume / index.ts View on Github external
private skipStyle(item: LoadParams, container: Element) {
    const styleStr = item.load
    const styleEl = getStyleEl()
    let originContent = ''
    const code = Prism.highlight(styleStr, Prism.languages.css)

    if (!item.rewrite) {
      originContent = container.innerHTML
    }

    styleEl.innerHTML = styleStr
    container.innerHTML = originContent + code
  }