GithubHelp home page GithubHelp logo

ajnauleau / highlight-syntax Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 53 KB

Simple HTML syntax highlighter!

Home Page: http://nauleau.io/simple-syntax-highlighter/index.html

HTML 74.53% JavaScript 22.32% CSS 3.15%

highlight-syntax's Introduction

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

highlight-syntax's People

Contributors

ajnauleau avatar

Stargazers

Hadj H. avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.