Socket
Socket
Sign inDemoInstall

highlight-html-syntax

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

highlight-html-syntax

Simple Syntax Highlighter for HTML code


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

highlight-html-syntax

Install the package from NPM:

$ npm install --save highlight-html-syntax

Import the CSS for highlighting:

@import 'node_modules/highlight-html-syntax/syntax.css'

Require the Highlight package in your project:

var Highlight = require('highlight-html-syntax')

Then use it in your code!

var html = '<p>hello world!</p>';
var result = Highlight(html);

console.log(result);

/* <span class="method">&lt;p</span>
<span class="method">&gt;</span>
hello world!
<span class="method">&lt;/p</span>
<span class="method">&gt;</span> */

EXAMPLE

In your frontend:

var code = document.getElementById('code').value;
var syntax = Highlight(code);
var result = document.getElementById('result');
result.innerText = syntax;

This HTML code

<form>
        <input type="text" placeholder="John Doe"/>
</form>

Turns into ->

<span class="method">&lt;form<span class="method">&gt;</span></span> <span class="global">
        <span class="method">&lt;input</span> type=<span class="string">"text"</span> placeholder</span>=<span class="string">"John Doe"</span><span class="method">/&gt;</span>
<span class="method">&lt;/form<span class="method">&gt;</span></span>

Which looks like this

image

Keywords

FAQs

Package last updated on 24 Apr 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc