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 - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

index.html

2

package.json
{
"name": "highlight-html-syntax",
"version": "1.0.0",
"version": "1.0.1",
"description": "Syntax Highlighter for HTML code",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,1 +0,68 @@

# highlight-syntax
# highlight-html-syntax
Install the package from NPM:
```node
$ npm install --save highlight-html-syntax
```
Import the CSS for highlighting:
```css
@import 'node_modules/highlight-html-syntax/syntax.css'
```
Require the Highlight package in your project:
```javascript
var Highlight = require('highlight-html-syntax')
```
Then use it in your code!
```javascript
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> */
```
<h1> EXAMPLE </h1>
In your frontend:
```javascript
var code = document.getElementById('code').value;
var syntax = Highlight(code);
var result = document.getElementById('result');
result.innerText = syntax;
```
This HTML code
```html
<form>
<input type="text" placeholder="John Doe"/>
</form>
```
Turns into ->
```code
<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
<link rel="stylesheet" href="./syntax.css">
<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>
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